diff --git a/libcxx/test/std/iterators/predef.iterators/iterators.common/ctor.pass.cpp b/libcxx/test/std/iterators/predef.iterators/iterators.common/ctor.pass.cpp --- a/libcxx/test/std/iterators/predef.iterators/iterators.common/ctor.pass.cpp +++ b/libcxx/test/std/iterators/predef.iterators/iterators.common/ctor.pass.cpp @@ -27,59 +27,60 @@ typename std::common_iterator; }; -template -concept ConvCtorEnabled = requires(std::common_iterator> ci) { - std::common_iterator>(ci); -}; - void test() { int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8}; - static_assert( std::is_default_constructible_v>>); - static_assert(!std::is_default_constructible_v, sentinel_type>>); + static_assert( std::is_default_constructible_v>>); + static_assert(!std::is_default_constructible_v, sentinel_wrapper>>>); // Not copyable: - static_assert(!ValidCommonIterator, sentinel_type>); + static_assert(!ValidCommonIterator, sentinel_wrapper>); // Same iter and sent: static_assert(!ValidCommonIterator, cpp17_input_iterator>); { - auto iter1 = cpp17_input_iterator(buffer); - auto commonIter1 = std::common_iterator>(iter1); - auto commonSent1 = std::common_iterator>(sentinel_type{buffer + 8}); - - assert(*iter1 == 1); + using It = cpp17_input_iterator; + using Sent = sentinel_wrapper; + auto commonIter1 = std::common_iterator(It(buffer)); + auto commonSent1 = std::common_iterator(Sent(It(buffer + 8))); assert(*commonIter1 == 1); assert(commonIter1 != commonSent1); + assert(std::next(commonIter1, 8) == commonSent1); } { - auto iter1 = forward_iterator(buffer); - auto commonIter1 = std::common_iterator>(iter1); - auto commonSent1 = std::common_iterator>(sentinel_type{buffer + 8}); - - assert(*iter1 == 1); + using It = forward_iterator; + using Sent = sentinel_wrapper; + auto commonIter1 = std::common_iterator(It(buffer)); + auto commonSent1 = std::common_iterator(Sent(It(buffer + 8))); assert(*commonIter1 == 1); assert(commonIter1 != commonSent1); + assert(std::next(commonIter1, 8) == commonSent1); } { - auto iter1 = random_access_iterator(buffer); - auto commonIter1 = std::common_iterator>(iter1); - auto commonSent1 = std::common_iterator>(sentinel_type{buffer + 8}); - - assert(*iter1 == 1); + using It = random_access_iterator; + using Sent = sentinel_wrapper; + auto commonIter1 = std::common_iterator(It(buffer)); + auto commonSent1 = std::common_iterator(Sent(It(buffer + 8))); assert(*commonIter1 == 1); assert(commonIter1 != commonSent1); + assert(std::next(commonIter1, 8) == commonSent1); } - - // Conversion constructor: { - convertible_iterator conv{buffer}; - auto commonIter1 = std::common_iterator, sentinel_type>(conv); - auto commonIter2 = std::common_iterator, sentinel_type>(commonIter1); - assert(*commonIter2 == 1); - - static_assert( ConvCtorEnabled, convertible_iterator>); - static_assert(!ConvCtorEnabled, random_access_iterator>); + // Test the converting constructor + struct Base {}; + struct Derived : Base {}; + + using BaseIt = std::common_iterator; + using DerivedIt = std::common_iterator; + static_assert(std::is_convertible_v); // Derived* to Base* + static_assert(!std::is_constructible_v); // Base* to Derived* + Derived a[10]; + auto it = DerivedIt(a); // the iterator type + auto jt = BaseIt(it); + assert(jt == BaseIt(a)); + it = DerivedIt((const Derived*)a); // the sentinel type + jt = it; + assert(jt == BaseIt(a)); } } diff --git a/libcxx/test/std/iterators/predef.iterators/iterators.common/types.h b/libcxx/test/std/iterators/predef.iterators/iterators.common/types.h --- a/libcxx/test/std/iterators/predef.iterators/iterators.common/types.h +++ b/libcxx/test/std/iterators/predef.iterators/iterators.common/types.h @@ -157,32 +157,6 @@ } }; -template -class convertible_iterator -{ - It it_; - -public: - typedef std::input_iterator_tag iterator_category; - typedef typename std::iterator_traits::value_type value_type; - typedef typename std::iterator_traits::difference_type difference_type; - typedef It pointer; - typedef typename std::iterator_traits::reference reference; - - constexpr It base() const {return it_;} - - convertible_iterator() = default; - explicit constexpr convertible_iterator(It it) : it_(it) {} - - constexpr reference operator*() const {return *it_;} - - constexpr convertible_iterator& operator++() {++it_; return *this;} - constexpr convertible_iterator operator++(int) - {convertible_iterator tmp(*this); ++(*this); return tmp;} - - operator forward_iterator() const { return forward_iterator(it_); } -}; - template class non_const_deref_iterator { diff --git a/libcxx/test/support/test_iterators.h b/libcxx/test/support/test_iterators.h --- a/libcxx/test/support/test_iterators.h +++ b/libcxx/test/support/test_iterators.h @@ -116,38 +116,6 @@ void operator,(T const &) = delete; }; -template -class non_default_constructible_iterator -{ - It it_; - - template friend class non_default_constructible_iterator; -public: - typedef std::input_iterator_tag iterator_category; - typedef typename std::iterator_traits::value_type value_type; - typedef typename std::iterator_traits::difference_type difference_type; - typedef It pointer; - typedef typename std::iterator_traits::reference reference; - - non_default_constructible_iterator() = delete; - - TEST_CONSTEXPR explicit non_default_constructible_iterator(It it) : it_(it) {} - template - TEST_CONSTEXPR non_default_constructible_iterator(const non_default_constructible_iterator& u) : it_(u.it_) {} - - TEST_CONSTEXPR reference operator*() const {return *it_;} - TEST_CONSTEXPR pointer operator->() const {return it_;} - - TEST_CONSTEXPR_CXX14 non_default_constructible_iterator& operator++() {++it_; return *this;} - TEST_CONSTEXPR_CXX14 non_default_constructible_iterator operator++(int) {return non_default_constructible_iterator(it_++);} - - friend TEST_CONSTEXPR bool operator==(const non_default_constructible_iterator& x, const non_default_constructible_iterator& y) {return x.it_ == y.it_;} - friend TEST_CONSTEXPR bool operator!=(const non_default_constructible_iterator& x, const non_default_constructible_iterator& y) {return x.it_ != y.it_;} - - template - void operator,(T const &) = delete; -}; - template class bidirectional_iterator {