| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 10 | |
| 11 | // template<class R> |
| 12 | // concept bidirectional_range; |
| 13 | |
| 14 | #include <ranges> |
| 15 | |
| 16 | #include "test_range.h" |
| 17 | |
| 18 | template <template <class...> class I> |
| 19 | constexpr bool check_bidirectional_range() { |
| 20 | constexpr bool result = std::ranges::bidirectional_range<test_range<I> >; |
| 21 | static_assert(std::ranges::bidirectional_range<test_range<I> const> == result); |
| 22 | static_assert(std::ranges::bidirectional_range<test_non_const_common_range<I> > == result); |
| 23 | static_assert(std::ranges::bidirectional_range<test_non_const_range<I> > == result); |
| 24 | static_assert(std::ranges::bidirectional_range<test_common_range<I> > == result); |
| 25 | static_assert(std::ranges::bidirectional_range<test_common_range<I> const> == result); |
| 26 | static_assert(!std::ranges::bidirectional_range<test_non_const_common_range<I> const>); |
| 27 | static_assert(!std::ranges::bidirectional_range<test_non_const_range<I> const>); |
| 28 | return result; |
| 29 | } |
| 30 | |
| 31 | static_assert(!check_bidirectional_range<cpp17_input_iterator>()); |
| 32 | static_assert(!check_bidirectional_range<cpp20_input_iterator>()); |
| 33 | static_assert(!check_bidirectional_range<forward_iterator>()); |
| 34 | static_assert(check_bidirectional_range<bidirectional_iterator>()); |
| 35 | static_assert(check_bidirectional_range<random_access_iterator>()); |
| 36 | static_assert(check_bidirectional_range<contiguous_iterator>()); |
| 37 | |
| 38 | // Test ADL-proofing. |
| 39 | struct Incomplete; |
| 40 | template<class T> struct Holder { T t; }; |
| 41 | |
| 42 | static_assert(!std::ranges::bidirectional_range<Holder<Incomplete>*>); |
| 43 | static_assert(!std::ranges::bidirectional_range<Holder<Incomplete>*&>); |
| 44 | static_assert(!std::ranges::bidirectional_range<Holder<Incomplete>*&&>); |
| 45 | static_assert(!std::ranges::bidirectional_range<Holder<Incomplete>* const>); |
| 46 | static_assert(!std::ranges::bidirectional_range<Holder<Incomplete>* const&>); |
| 47 | static_assert(!std::ranges::bidirectional_range<Holder<Incomplete>* const&&>); |
| 48 | |
| 49 | static_assert( std::ranges::bidirectional_range<Holder<Incomplete>*[10]>); |
| 50 | static_assert( std::ranges::bidirectional_range<Holder<Incomplete>*(&)[10]>); |
| 51 | static_assert( std::ranges::bidirectional_range<Holder<Incomplete>*(&&)[10]>); |
| 52 | static_assert( std::ranges::bidirectional_range<Holder<Incomplete>* const[10]>); |
| 53 | static_assert( std::ranges::bidirectional_range<Holder<Incomplete>* const(&)[10]>); |
| 54 | static_assert( std::ranges::bidirectional_range<Holder<Incomplete>* const(&&)[10]>); |
| 55 | |