diff --git a/libcxx/include/iterator b/libcxx/include/iterator --- a/libcxx/include/iterator +++ b/libcxx/include/iterator @@ -519,6 +519,22 @@ : __cond_value_type {}; // TODO(cjdb): add iter_value_t once iterator_traits is cleaned up. + +template +using __with_reference = _Tp&; + +template +concept __can_reference = requires { + typename __with_reference<_Tp>; +}; + +template +concept __dereferenceable = requires(_Tp& __t) { + { *__t } -> __can_reference; // not required to be equality-preserving +}; + +template<__dereferenceable _Tp> +using iter_reference_t = decltype(*declval<_Tp&>()); #endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS) template @@ -629,6 +645,71 @@ typedef typename _Iter::iterator_category iterator_category; }; +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS) + +// The `cpp17.*-iterator` concepts have been dubbed `__legacy.*_iterator` because the name is both +// clearer (C++98 iterators are still valid `cpp17-iterators`, for example), and because it's the +// term that C++ Reference uses (which is what most users will look to when issued diagnostics). + +template +concept __legacy_iterator = + copyable<_Ip> && + requires(_Ip __i) { + { *__i } -> __can_reference; + { ++__i } -> same_as<_Ip&>; + { *__i++ } -> __can_reference; + }; + +template +concept __legacy_input_iterator = + __legacy_iterator<_Ip> && + equality_comparable<_Ip> && + requires(_Ip __i) { + typename incrementable_traits<_Ip>::difference_type; + typename indirectly_readable_traits<_Ip>::value_type; + typename common_reference_t&&, + typename indirectly_readable_traits<_Ip>::value_type&>; + typename common_reference_t::value_type&>; + requires signed_integral::difference_type>; + }; + +template +concept __legacy_forward_iterator = + __legacy_input_iterator<_Ip> && + constructible_from<_Ip> && + is_lvalue_reference_v> && + same_as>, + typename indirectly_readable_traits<_Ip>::value_type> && + requires(_Ip __i) { + { __i++ } -> convertible_to<_Ip const&>; + { *__i++ } -> same_as>; + }; + +template +concept __legacy_bidirectional_iterator = + __legacy_forward_iterator<_Ip> && + requires(_Ip __i) { + { --__i } -> same_as<_Ip&>; + { __i-- } -> convertible_to<_Ip const&>; + { *__i-- } -> same_as>; + }; + +template +concept __legacy_random_access_iterator = + __legacy_bidirectional_iterator<_Ip> and + totally_ordered<_Ip> and + requires(_Ip __i, _Ip __j, typename incrementable_traits<_Ip>::difference_type __n) { + { __i += __n } -> same_as<_Ip&>; + { __i -= __n } -> same_as<_Ip&>; + { __i + __n } -> same_as<_Ip>; + { __n + __i } -> same_as<_Ip>; + { __i - __n } -> same_as<_Ip>; + { __i - __j } -> same_as; + { __i[__n] } -> convertible_to>; + }; +#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS) + template struct __iterator_traits {}; template diff --git a/libcxx/test/libcxx/iterators/iterator.requirements/iterator.assoc.types/iterator.traits/legacy_bidirectional_iterator.pass.cpp b/libcxx/test/libcxx/iterators/iterator.requirements/iterator.assoc.types/iterator.traits/legacy_bidirectional_iterator.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/iterators/iterator.requirements/iterator.assoc.types/iterator.traits/legacy_bidirectional_iterator.pass.cpp @@ -0,0 +1,205 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// UNSUPPORTED: libcpp-no-concepts +// UNSUPPORTED: gcc-10 + +// template +// concept __legacy_bidirectional_iterator; + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static_assert(std::__legacy_bidirectional_iterator); +static_assert(std::__legacy_bidirectional_iterator); +static_assert(std::__legacy_bidirectional_iterator); +static_assert(std::__legacy_bidirectional_iterator); + +// +static_assert( + std::__legacy_bidirectional_iterator::iterator>); +static_assert( + std::__legacy_bidirectional_iterator::const_iterator>); +static_assert(std::__legacy_bidirectional_iterator< + std::array::reverse_iterator>); +static_assert(std::__legacy_bidirectional_iterator< + std::array::const_reverse_iterator>); + +// +static_assert(std::__legacy_bidirectional_iterator::iterator>); +static_assert( + std::__legacy_bidirectional_iterator::const_iterator>); +static_assert( + std::__legacy_bidirectional_iterator::reverse_iterator>); +static_assert(std::__legacy_bidirectional_iterator< + std::deque::const_reverse_iterator>); + +// +static_assert( + !std::__legacy_bidirectional_iterator); +static_assert(!std::__legacy_bidirectional_iterator< + std::filesystem::recursive_directory_iterator>); + +// +static_assert( + !std::__legacy_bidirectional_iterator::iterator>); +static_assert(!std::__legacy_bidirectional_iterator< + std::forward_list::const_iterator>); + +// +static_assert(!std::__legacy_bidirectional_iterator< + std::back_insert_iterator > >); +static_assert(!std::__legacy_bidirectional_iterator< + std::front_insert_iterator > >); +static_assert(!std::__legacy_bidirectional_iterator< + std::insert_iterator > >); +static_assert(!std::__legacy_bidirectional_iterator< + std::istream_iterator >); +static_assert(!std::__legacy_bidirectional_iterator< + std::istreambuf_iterator >); +static_assert(!std::__legacy_bidirectional_iterator< + std::move_iterator::iterator> >); +static_assert(!std::__legacy_bidirectional_iterator< + std::ostream_iterator >); +static_assert(!std::__legacy_bidirectional_iterator< + std::ostreambuf_iterator >); + +// +static_assert(std::__legacy_bidirectional_iterator::iterator>); +static_assert( + std::__legacy_bidirectional_iterator::const_iterator>); +static_assert( + std::__legacy_bidirectional_iterator::reverse_iterator>); +static_assert(std::__legacy_bidirectional_iterator< + std::list::const_reverse_iterator>); + +// +static_assert( + std::__legacy_bidirectional_iterator::iterator>); +static_assert( + std::__legacy_bidirectional_iterator::const_iterator>); +static_assert( + std::__legacy_bidirectional_iterator::reverse_iterator>); +static_assert(std::__legacy_bidirectional_iterator< + std::map::const_reverse_iterator>); + +static_assert( + std::__legacy_bidirectional_iterator::iterator>); +static_assert(std::__legacy_bidirectional_iterator< + std::multimap::const_iterator>); +static_assert(std::__legacy_bidirectional_iterator< + std::multimap::reverse_iterator>); +static_assert(std::__legacy_bidirectional_iterator< + std::multimap::const_reverse_iterator>); + +// +static_assert( + std::__legacy_bidirectional_iterator::iterator>); +static_assert( + std::__legacy_bidirectional_iterator::const_iterator>); +static_assert( + std::__legacy_bidirectional_iterator::reverse_iterator>); +static_assert(std::__legacy_bidirectional_iterator< + std::set::const_reverse_iterator>); + +static_assert( + std::__legacy_bidirectional_iterator::iterator>); +static_assert(std::__legacy_bidirectional_iterator< + std::multiset::const_iterator>); +static_assert(std::__legacy_bidirectional_iterator< + std::multiset::reverse_iterator>); +static_assert(std::__legacy_bidirectional_iterator< + std::multiset::const_reverse_iterator>); + +// +static_assert(std::__legacy_bidirectional_iterator); +static_assert( + std::__legacy_bidirectional_iterator); +static_assert( + std::__legacy_bidirectional_iterator); +static_assert( + std::__legacy_bidirectional_iterator); + +// +static_assert(std::__legacy_bidirectional_iterator); +static_assert( + std::__legacy_bidirectional_iterator); +static_assert( + std::__legacy_bidirectional_iterator); +static_assert(std::__legacy_bidirectional_iterator< + std::string_view::const_reverse_iterator>); + +// +static_assert(!std::__legacy_bidirectional_iterator< + std::unordered_map::iterator>); +static_assert(!std::__legacy_bidirectional_iterator< + std::unordered_map::const_iterator>); + +static_assert(!std::__legacy_bidirectional_iterator< + std::unordered_multimap::iterator>); +static_assert(!std::__legacy_bidirectional_iterator< + std::unordered_multimap::const_iterator>); + +// +static_assert(!std::__legacy_bidirectional_iterator< + std::unordered_set::iterator>); +static_assert(!std::__legacy_bidirectional_iterator< + std::unordered_set::const_iterator>); + +static_assert(!std::__legacy_bidirectional_iterator< + std::unordered_multiset::iterator>); +static_assert(!std::__legacy_bidirectional_iterator< + std::unordered_multiset::const_iterator>); + +// +static_assert(std::__legacy_bidirectional_iterator::iterator>); +static_assert( + std::__legacy_bidirectional_iterator::const_iterator>); +static_assert( + std::__legacy_bidirectional_iterator::reverse_iterator>); +static_assert(std::__legacy_bidirectional_iterator< + std::vector::const_reverse_iterator>); + +// Not iterators +static_assert(!std::__legacy_bidirectional_iterator); +static_assert(!std::__legacy_bidirectional_iterator); +static_assert(!std::__legacy_bidirectional_iterator); +static_assert( + !std::__legacy_bidirectional_iterator::iterator volatile>); +static_assert( + !std::__legacy_bidirectional_iterator::iterator&>); +static_assert( + !std::__legacy_bidirectional_iterator::iterator&&>); +static_assert(!std::__legacy_bidirectional_iterator); +static_assert(!std::__legacy_bidirectional_iterator); +static_assert(!std::__legacy_bidirectional_iterator); +static_assert(!std::__legacy_bidirectional_iterator); +static_assert(!std::__legacy_bidirectional_iterator); +static_assert(!std::__legacy_bidirectional_iterator); + +struct S {}; +static_assert(!std::__legacy_bidirectional_iterator); +static_assert(!std::__legacy_bidirectional_iterator); +static_assert(!std::__legacy_bidirectional_iterator); + +int main(int, char**) { return 0; } diff --git a/libcxx/test/libcxx/iterators/iterator.requirements/iterator.assoc.types/iterator.traits/legacy_forward_iterator.pass.cpp b/libcxx/test/libcxx/iterators/iterator.requirements/iterator.assoc.types/iterator.traits/legacy_forward_iterator.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/iterators/iterator.requirements/iterator.assoc.types/iterator.traits/legacy_forward_iterator.pass.cpp @@ -0,0 +1,195 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// UNSUPPORTED: libcpp-no-concepts +// UNSUPPORTED: gcc-10 + +// template +// concept __legacy_forward_iterator; + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static_assert(std::__legacy_forward_iterator); +static_assert(std::__legacy_forward_iterator); +static_assert(std::__legacy_forward_iterator); +static_assert(std::__legacy_forward_iterator); + +// +static_assert(std::__legacy_forward_iterator::iterator>); +static_assert( + std::__legacy_forward_iterator::const_iterator>); +static_assert( + std::__legacy_forward_iterator::reverse_iterator>); +static_assert(std::__legacy_forward_iterator< + std::array::const_reverse_iterator>); + +// +static_assert(std::__legacy_forward_iterator::iterator>); +static_assert(std::__legacy_forward_iterator::const_iterator>); +static_assert( + std::__legacy_forward_iterator::reverse_iterator>); +static_assert( + std::__legacy_forward_iterator::const_reverse_iterator>); + +// +static_assert( + !std::__legacy_forward_iterator); +static_assert(!std::__legacy_forward_iterator< + std::filesystem::recursive_directory_iterator>); + +// +static_assert(std::__legacy_forward_iterator::iterator>); +static_assert( + std::__legacy_forward_iterator::const_iterator>); + +// +static_assert(!std::__legacy_forward_iterator< + std::back_insert_iterator > >); +static_assert(!std::__legacy_forward_iterator< + std::front_insert_iterator > >); +static_assert( + !std::__legacy_forward_iterator > >); + +// This is because the legacy iterator concepts don't care about iterator_category +static_assert( + std::__legacy_forward_iterator >); + +static_assert(!std::__legacy_forward_iterator< + std::istreambuf_iterator >); +static_assert(!std::__legacy_forward_iterator< + std::move_iterator::iterator> >); +static_assert( + !std::__legacy_forward_iterator >); +static_assert(!std::__legacy_forward_iterator< + std::ostreambuf_iterator >); + +// +static_assert(std::__legacy_forward_iterator::iterator>); +static_assert(std::__legacy_forward_iterator::const_iterator>); +static_assert(std::__legacy_forward_iterator::reverse_iterator>); +static_assert( + std::__legacy_forward_iterator::const_reverse_iterator>); + +// +static_assert(std::__legacy_forward_iterator::iterator>); +static_assert( + std::__legacy_forward_iterator::const_iterator>); +static_assert( + std::__legacy_forward_iterator::reverse_iterator>); +static_assert( + std::__legacy_forward_iterator::const_reverse_iterator>); + +static_assert( + std::__legacy_forward_iterator::iterator>); +static_assert( + std::__legacy_forward_iterator::const_iterator>); +static_assert( + std::__legacy_forward_iterator::reverse_iterator>); +static_assert(std::__legacy_forward_iterator< + std::multimap::const_reverse_iterator>); + +// +static_assert(std::__legacy_forward_iterator::iterator>); +static_assert( + std::__legacy_forward_iterator::const_iterator>); +static_assert( + std::__legacy_forward_iterator::reverse_iterator>); +static_assert( + std::__legacy_forward_iterator::const_reverse_iterator>); + +static_assert( + std::__legacy_forward_iterator::iterator>); +static_assert( + std::__legacy_forward_iterator::const_iterator>); +static_assert( + std::__legacy_forward_iterator::reverse_iterator>); +static_assert(std::__legacy_forward_iterator< + std::multiset::const_reverse_iterator>); + +// +static_assert(std::__legacy_forward_iterator); +static_assert(std::__legacy_forward_iterator); +static_assert(std::__legacy_forward_iterator); +static_assert( + std::__legacy_forward_iterator); + +// +static_assert(std::__legacy_forward_iterator); +static_assert(std::__legacy_forward_iterator); +static_assert( + std::__legacy_forward_iterator); +static_assert( + std::__legacy_forward_iterator); + +// +static_assert( + std::__legacy_forward_iterator::iterator>); +static_assert(std::__legacy_forward_iterator< + std::unordered_map::const_iterator>); + +static_assert(std::__legacy_forward_iterator< + std::unordered_multimap::iterator>); +static_assert(std::__legacy_forward_iterator< + std::unordered_multimap::const_iterator>); + +// +static_assert( + std::__legacy_forward_iterator::iterator>); +static_assert(std::__legacy_forward_iterator< + std::unordered_set::const_iterator>); + +static_assert(std::__legacy_forward_iterator< + std::unordered_multiset::iterator>); +static_assert(std::__legacy_forward_iterator< + std::unordered_multiset::const_iterator>); + +// +static_assert(std::__legacy_forward_iterator::iterator>); +static_assert(std::__legacy_forward_iterator::const_iterator>); +static_assert( + std::__legacy_forward_iterator::reverse_iterator>); +static_assert( + std::__legacy_forward_iterator::const_reverse_iterator>); + +// Not iterators +static_assert(!std::__legacy_forward_iterator); +static_assert(!std::__legacy_forward_iterator); +static_assert(!std::__legacy_forward_iterator); +static_assert( + !std::__legacy_forward_iterator::iterator volatile>); +static_assert(!std::__legacy_forward_iterator::iterator&>); +static_assert(!std::__legacy_forward_iterator::iterator&&>); +static_assert(!std::__legacy_forward_iterator); +static_assert(!std::__legacy_forward_iterator); +static_assert(!std::__legacy_forward_iterator); +static_assert(!std::__legacy_forward_iterator); +static_assert(!std::__legacy_forward_iterator); +static_assert(!std::__legacy_forward_iterator); + +struct S {}; +static_assert(!std::__legacy_forward_iterator); +static_assert(!std::__legacy_forward_iterator); +static_assert(!std::__legacy_forward_iterator); + +int main(int, char**) { return 0; } diff --git a/libcxx/test/libcxx/iterators/iterator.requirements/iterator.assoc.types/iterator.traits/legacy_input_iterator.pass.cpp b/libcxx/test/libcxx/iterators/iterator.requirements/iterator.assoc.types/iterator.traits/legacy_input_iterator.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/iterators/iterator.requirements/iterator.assoc.types/iterator.traits/legacy_input_iterator.pass.cpp @@ -0,0 +1,185 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// UNSUPPORTED: libcpp-no-concepts +// UNSUPPORTED: gcc-10 + +// template +// concept __legacy_input_iterator; + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static_assert(std::__legacy_input_iterator); +static_assert(std::__legacy_input_iterator); +static_assert(std::__legacy_input_iterator); +static_assert(std::__legacy_input_iterator); + +// +static_assert(std::__legacy_input_iterator::iterator>); +static_assert( + std::__legacy_input_iterator::const_iterator>); +static_assert( + std::__legacy_input_iterator::reverse_iterator>); +static_assert( + std::__legacy_input_iterator::const_reverse_iterator>); + +// +static_assert(std::__legacy_input_iterator::iterator>); +static_assert(std::__legacy_input_iterator::const_iterator>); +static_assert(std::__legacy_input_iterator::reverse_iterator>); +static_assert( + std::__legacy_input_iterator::const_reverse_iterator>); + +// +static_assert( + std::__legacy_input_iterator); +static_assert(std::__legacy_input_iterator< + std::filesystem::recursive_directory_iterator>); + +// +static_assert(std::__legacy_input_iterator::iterator>); +static_assert( + std::__legacy_input_iterator::const_iterator>); + +// +static_assert(!std::__legacy_input_iterator< + std::back_insert_iterator > >); +static_assert(!std::__legacy_input_iterator< + std::front_insert_iterator > >); +static_assert( + !std::__legacy_input_iterator > >); +static_assert( + std::__legacy_input_iterator >); +static_assert( + std::__legacy_input_iterator >); +static_assert(std::__legacy_input_iterator< + std::move_iterator::iterator> >); +static_assert( + !std::__legacy_input_iterator >); +static_assert(!std::__legacy_input_iterator< + std::ostreambuf_iterator >); + +// +static_assert(std::__legacy_input_iterator::iterator>); +static_assert(std::__legacy_input_iterator::const_iterator>); +static_assert(std::__legacy_input_iterator::reverse_iterator>); +static_assert( + std::__legacy_input_iterator::const_reverse_iterator>); + +// +static_assert(std::__legacy_input_iterator::iterator>); +static_assert(std::__legacy_input_iterator::const_iterator>); +static_assert( + std::__legacy_input_iterator::reverse_iterator>); +static_assert( + std::__legacy_input_iterator::const_reverse_iterator>); + +static_assert(std::__legacy_input_iterator::iterator>); +static_assert( + std::__legacy_input_iterator::const_iterator>); +static_assert( + std::__legacy_input_iterator::reverse_iterator>); +static_assert(std::__legacy_input_iterator< + std::multimap::const_reverse_iterator>); + +// +static_assert(std::__legacy_input_iterator::iterator>); +static_assert(std::__legacy_input_iterator::const_iterator>); +static_assert( + std::__legacy_input_iterator::reverse_iterator>); +static_assert( + std::__legacy_input_iterator::const_reverse_iterator>); + +static_assert(std::__legacy_input_iterator::iterator>); +static_assert( + std::__legacy_input_iterator::const_iterator>); +static_assert( + std::__legacy_input_iterator::reverse_iterator>); +static_assert(std::__legacy_input_iterator< + std::multiset::const_reverse_iterator>); + +// +static_assert(std::__legacy_input_iterator); +static_assert(std::__legacy_input_iterator); +static_assert(std::__legacy_input_iterator); +static_assert( + std::__legacy_input_iterator); + +// +static_assert(std::__legacy_input_iterator); +static_assert(std::__legacy_input_iterator); +static_assert(std::__legacy_input_iterator); +static_assert( + std::__legacy_input_iterator); + +// +static_assert( + std::__legacy_input_iterator::iterator>); +static_assert( + std::__legacy_input_iterator::const_iterator>); + +static_assert( + std::__legacy_input_iterator::iterator>); +static_assert(std::__legacy_input_iterator< + std::unordered_multimap::const_iterator>); + +// +static_assert( + std::__legacy_input_iterator::iterator>); +static_assert( + std::__legacy_input_iterator::const_iterator>); + +static_assert( + std::__legacy_input_iterator::iterator>); +static_assert(std::__legacy_input_iterator< + std::unordered_multiset::const_iterator>); + +// +static_assert(std::__legacy_input_iterator::iterator>); +static_assert(std::__legacy_input_iterator::const_iterator>); +static_assert(std::__legacy_input_iterator::reverse_iterator>); +static_assert( + std::__legacy_input_iterator::const_reverse_iterator>); + +// Not iterators +static_assert(!std::__legacy_input_iterator); +static_assert(!std::__legacy_input_iterator); +static_assert(!std::__legacy_input_iterator); +static_assert( + !std::__legacy_input_iterator::iterator volatile>); +static_assert(!std::__legacy_input_iterator::iterator&>); +static_assert(!std::__legacy_input_iterator::iterator&&>); +static_assert(!std::__legacy_input_iterator); +static_assert(!std::__legacy_input_iterator); +static_assert(!std::__legacy_input_iterator); +static_assert(!std::__legacy_input_iterator); +static_assert(!std::__legacy_input_iterator); +static_assert(!std::__legacy_input_iterator); + +struct S {}; +static_assert(!std::__legacy_input_iterator); +static_assert(!std::__legacy_input_iterator); +static_assert(!std::__legacy_input_iterator); + +int main(int, char**) { return 0; } diff --git a/libcxx/test/libcxx/iterators/iterator.requirements/iterator.assoc.types/iterator.traits/legacy_iterator.pass.cpp b/libcxx/test/libcxx/iterators/iterator.requirements/iterator.assoc.types/iterator.traits/legacy_iterator.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/iterators/iterator.requirements/iterator.assoc.types/iterator.traits/legacy_iterator.pass.cpp @@ -0,0 +1,168 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// UNSUPPORTED: libcpp-no-concepts +// UNSUPPORTED: gcc-10 + +// template +// concept __legacy_iterator; + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static_assert(std::__legacy_iterator); +static_assert(std::__legacy_iterator); +static_assert(std::__legacy_iterator); +static_assert(std::__legacy_iterator); + +// +static_assert(std::__legacy_iterator::iterator>); +static_assert(std::__legacy_iterator::const_iterator>); +static_assert(std::__legacy_iterator::reverse_iterator>); +static_assert( + std::__legacy_iterator::const_reverse_iterator>); + +// +static_assert(std::__legacy_iterator::iterator>); +static_assert(std::__legacy_iterator::const_iterator>); +static_assert(std::__legacy_iterator::reverse_iterator>); +static_assert(std::__legacy_iterator::const_reverse_iterator>); + +// +static_assert(std::__legacy_iterator); +static_assert( + std::__legacy_iterator); + +// +static_assert(std::__legacy_iterator::iterator>); +static_assert(std::__legacy_iterator::const_iterator>); + +// +static_assert( + std::__legacy_iterator > >); +static_assert( + std::__legacy_iterator > >); +static_assert(std::__legacy_iterator > >); +static_assert( + std::__legacy_iterator >); +static_assert( + std::__legacy_iterator >); +static_assert( + std::__legacy_iterator::iterator> >); +static_assert( + std::__legacy_iterator >); +static_assert( + std::__legacy_iterator >); + +// +static_assert(std::__legacy_iterator::iterator>); +static_assert(std::__legacy_iterator::const_iterator>); +static_assert(std::__legacy_iterator::reverse_iterator>); +static_assert(std::__legacy_iterator::const_reverse_iterator>); + +// +static_assert(std::__legacy_iterator::iterator>); +static_assert(std::__legacy_iterator::const_iterator>); +static_assert(std::__legacy_iterator::reverse_iterator>); +static_assert( + std::__legacy_iterator::const_reverse_iterator>); + +static_assert(std::__legacy_iterator::iterator>); +static_assert(std::__legacy_iterator::const_iterator>); +static_assert( + std::__legacy_iterator::reverse_iterator>); +static_assert( + std::__legacy_iterator::const_reverse_iterator>); + +// +static_assert(std::__legacy_iterator::iterator>); +static_assert(std::__legacy_iterator::const_iterator>); +static_assert(std::__legacy_iterator::reverse_iterator>); +static_assert( + std::__legacy_iterator::const_reverse_iterator>); + +static_assert(std::__legacy_iterator::iterator>); +static_assert(std::__legacy_iterator::const_iterator>); +static_assert( + std::__legacy_iterator::reverse_iterator>); +static_assert( + std::__legacy_iterator::const_reverse_iterator>); + +// +static_assert(std::__legacy_iterator); +static_assert(std::__legacy_iterator); +static_assert(std::__legacy_iterator); +static_assert(std::__legacy_iterator); + +// +static_assert(std::__legacy_iterator); +static_assert(std::__legacy_iterator); +static_assert(std::__legacy_iterator); +static_assert(std::__legacy_iterator); + +// +static_assert(std::__legacy_iterator::iterator>); +static_assert( + std::__legacy_iterator::const_iterator>); + +static_assert( + std::__legacy_iterator::iterator>); +static_assert( + std::__legacy_iterator::const_iterator>); + +// +static_assert(std::__legacy_iterator::iterator>); +static_assert( + std::__legacy_iterator::const_iterator>); + +static_assert( + std::__legacy_iterator::iterator>); +static_assert( + std::__legacy_iterator::const_iterator>); + +// +static_assert(std::__legacy_iterator::iterator>); +static_assert(std::__legacy_iterator::const_iterator>); +static_assert(std::__legacy_iterator::reverse_iterator>); +static_assert(std::__legacy_iterator::const_reverse_iterator>); + +// Not iterators +static_assert(!std::__legacy_iterator); +static_assert(!std::__legacy_iterator); +static_assert(!std::__legacy_iterator); +static_assert(!std::__legacy_iterator::iterator volatile>); +static_assert(!std::__legacy_iterator::iterator&>); +static_assert(!std::__legacy_iterator::iterator&&>); +static_assert(!std::__legacy_iterator); +static_assert(!std::__legacy_iterator); +static_assert(!std::__legacy_iterator); +static_assert(!std::__legacy_iterator); +static_assert(!std::__legacy_iterator); +static_assert(!std::__legacy_iterator); + +struct S {}; +static_assert(!std::__legacy_iterator); +static_assert(!std::__legacy_iterator); +static_assert(!std::__legacy_iterator); + +int main(int, char**) { return 0; } diff --git a/libcxx/test/libcxx/iterators/iterator.requirements/iterator.assoc.types/iterator.traits/legacy_random_access_iterator.pass.cpp b/libcxx/test/libcxx/iterators/iterator.requirements/iterator.assoc.types/iterator.traits/legacy_random_access_iterator.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/iterators/iterator.requirements/iterator.assoc.types/iterator.traits/legacy_random_access_iterator.pass.cpp @@ -0,0 +1,205 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// UNSUPPORTED: libcpp-no-concepts +// UNSUPPORTED: gcc-10 + +// template +// concept __legacy_random_access_iterator; + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static_assert(std::__legacy_random_access_iterator); +static_assert(std::__legacy_random_access_iterator); +static_assert(std::__legacy_random_access_iterator); +static_assert(std::__legacy_random_access_iterator); + +// +static_assert( + std::__legacy_random_access_iterator::iterator>); +static_assert( + std::__legacy_random_access_iterator::const_iterator>); +static_assert(std::__legacy_random_access_iterator< + std::array::reverse_iterator>); +static_assert(std::__legacy_random_access_iterator< + std::array::const_reverse_iterator>); + +// +static_assert(std::__legacy_random_access_iterator::iterator>); +static_assert( + std::__legacy_random_access_iterator::const_iterator>); +static_assert( + std::__legacy_random_access_iterator::reverse_iterator>); +static_assert(std::__legacy_random_access_iterator< + std::deque::const_reverse_iterator>); + +// +static_assert( + !std::__legacy_random_access_iterator); +static_assert(!std::__legacy_random_access_iterator< + std::filesystem::recursive_directory_iterator>); + +// +static_assert( + !std::__legacy_random_access_iterator::iterator>); +static_assert(!std::__legacy_random_access_iterator< + std::forward_list::const_iterator>); + +// +static_assert(!std::__legacy_random_access_iterator< + std::back_insert_iterator > >); +static_assert(!std::__legacy_random_access_iterator< + std::front_insert_iterator > >); +static_assert(!std::__legacy_random_access_iterator< + std::insert_iterator > >); +static_assert(!std::__legacy_random_access_iterator< + std::istream_iterator >); +static_assert(!std::__legacy_random_access_iterator< + std::istreambuf_iterator >); +static_assert(!std::__legacy_random_access_iterator< + std::move_iterator::iterator> >); +static_assert(!std::__legacy_random_access_iterator< + std::ostream_iterator >); +static_assert(!std::__legacy_random_access_iterator< + std::ostreambuf_iterator >); + +// +static_assert(!std::__legacy_random_access_iterator::iterator>); +static_assert( + !std::__legacy_random_access_iterator::const_iterator>); +static_assert( + !std::__legacy_random_access_iterator::reverse_iterator>); +static_assert(!std::__legacy_random_access_iterator< + std::list::const_reverse_iterator>); + +// +static_assert( + !std::__legacy_random_access_iterator::iterator>); +static_assert( + !std::__legacy_random_access_iterator::const_iterator>); +static_assert(!std::__legacy_random_access_iterator< + std::map::reverse_iterator>); +static_assert(!std::__legacy_random_access_iterator< + std::map::const_reverse_iterator>); + +static_assert( + !std::__legacy_random_access_iterator::iterator>); +static_assert(!std::__legacy_random_access_iterator< + std::multimap::const_iterator>); +static_assert(!std::__legacy_random_access_iterator< + std::multimap::reverse_iterator>); +static_assert(!std::__legacy_random_access_iterator< + std::multimap::const_reverse_iterator>); + +// +static_assert( + !std::__legacy_random_access_iterator::iterator>); +static_assert( + !std::__legacy_random_access_iterator::const_iterator>); +static_assert(!std::__legacy_random_access_iterator< + std::set::reverse_iterator>); +static_assert(!std::__legacy_random_access_iterator< + std::set::const_reverse_iterator>); + +static_assert( + !std::__legacy_random_access_iterator::iterator>); +static_assert(!std::__legacy_random_access_iterator< + std::multiset::const_iterator>); +static_assert(!std::__legacy_random_access_iterator< + std::multiset::reverse_iterator>); +static_assert(!std::__legacy_random_access_iterator< + std::multiset::const_reverse_iterator>); + +// +static_assert(std::__legacy_random_access_iterator); +static_assert( + std::__legacy_random_access_iterator); +static_assert( + std::__legacy_random_access_iterator); +static_assert( + std::__legacy_random_access_iterator); + +// +static_assert(std::__legacy_random_access_iterator); +static_assert( + std::__legacy_random_access_iterator); +static_assert( + std::__legacy_random_access_iterator); +static_assert(std::__legacy_random_access_iterator< + std::string_view::const_reverse_iterator>); + +// +static_assert(!std::__legacy_random_access_iterator< + std::unordered_map::iterator>); +static_assert(!std::__legacy_random_access_iterator< + std::unordered_map::const_iterator>); + +static_assert(!std::__legacy_random_access_iterator< + std::unordered_multimap::iterator>); +static_assert(!std::__legacy_random_access_iterator< + std::unordered_multimap::const_iterator>); + +// +static_assert(!std::__legacy_random_access_iterator< + std::unordered_set::iterator>); +static_assert(!std::__legacy_random_access_iterator< + std::unordered_set::const_iterator>); + +static_assert(!std::__legacy_random_access_iterator< + std::unordered_multiset::iterator>); +static_assert(!std::__legacy_random_access_iterator< + std::unordered_multiset::const_iterator>); + +// +static_assert(std::__legacy_random_access_iterator::iterator>); +static_assert( + std::__legacy_random_access_iterator::const_iterator>); +static_assert( + std::__legacy_random_access_iterator::reverse_iterator>); +static_assert(std::__legacy_random_access_iterator< + std::vector::const_reverse_iterator>); + +// Not iterators +static_assert(!std::__legacy_random_access_iterator); +static_assert(!std::__legacy_random_access_iterator); +static_assert(!std::__legacy_random_access_iterator); +static_assert( + !std::__legacy_random_access_iterator::iterator volatile>); +static_assert( + !std::__legacy_random_access_iterator::iterator&>); +static_assert( + !std::__legacy_random_access_iterator::iterator&&>); +static_assert(!std::__legacy_random_access_iterator); +static_assert(!std::__legacy_random_access_iterator); +static_assert(!std::__legacy_random_access_iterator); +static_assert(!std::__legacy_random_access_iterator); +static_assert(!std::__legacy_random_access_iterator); +static_assert(!std::__legacy_random_access_iterator); + +struct S {}; +static_assert(!std::__legacy_random_access_iterator); +static_assert(!std::__legacy_random_access_iterator); +static_assert(!std::__legacy_random_access_iterator); + +int main(int, char**) { return 0; }