xref: /llvm-project/libcxx/test/std/ranges/range.req/range.refinements/forward_range.compile.pass.cpp (revision b8cb1dc9ea87faa8e8e9ab7a31710a8c0bb8b084)
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 forward_range;
13 
14 #include <ranges>
15 
16 #include "test_iterators.h"
17 #include "test_range.h"
18 
19 template <template <class...> class I>
check_forward_range()20 constexpr bool check_forward_range() {
21   constexpr bool result = std::ranges::forward_range<test_range<I> >;
22   static_assert(std::ranges::forward_range<test_range<I> const> == result);
23   static_assert(std::ranges::forward_range<test_non_const_common_range<I> > == result);
24   static_assert(std::ranges::forward_range<test_non_const_range<I> > == result);
25   static_assert(std::ranges::forward_range<test_common_range<I> > == result);
26   static_assert(std::ranges::forward_range<test_common_range<I> const> == result);
27   static_assert(!std::ranges::forward_range<test_non_const_common_range<I> const>);
28   static_assert(!std::ranges::forward_range<test_non_const_range<I> const>);
29   return result;
30 }
31 
32 static_assert(!check_forward_range<cpp17_input_iterator>());
33 static_assert(!check_forward_range<cpp20_input_iterator>());
34 static_assert(check_forward_range<forward_iterator>());
35 static_assert(check_forward_range<bidirectional_iterator>());
36 static_assert(check_forward_range<random_access_iterator>());
37 static_assert(check_forward_range<contiguous_iterator>());
38 
39 // Test ADL-proofing.
40 struct Incomplete;
41 template<class T> struct Holder { T t; };
42 
43 static_assert(!std::ranges::forward_range<Holder<Incomplete>*>);
44 static_assert(!std::ranges::forward_range<Holder<Incomplete>*&>);
45 static_assert(!std::ranges::forward_range<Holder<Incomplete>*&&>);
46 static_assert(!std::ranges::forward_range<Holder<Incomplete>* const>);
47 static_assert(!std::ranges::forward_range<Holder<Incomplete>* const&>);
48 static_assert(!std::ranges::forward_range<Holder<Incomplete>* const&&>);
49 
50 static_assert( std::ranges::forward_range<Holder<Incomplete>*[10]>);
51 static_assert( std::ranges::forward_range<Holder<Incomplete>*(&)[10]>);
52 static_assert( std::ranges::forward_range<Holder<Incomplete>*(&&)[10]>);
53 static_assert( std::ranges::forward_range<Holder<Incomplete>* const[10]>);
54 static_assert( std::ranges::forward_range<Holder<Incomplete>* const(&)[10]>);
55 static_assert( std::ranges::forward_range<Holder<Incomplete>* const(&&)[10]>);
56