xref: /llvm-project/libcxx/test/std/ranges/range.req/range.refinements/forward_range.compile.pass.cpp (revision b8cb1dc9ea87faa8e8e9ab7a31710a8c0bb8b084)
1d8fad661SChristopher Di Bella //===----------------------------------------------------------------------===//
2d8fad661SChristopher Di Bella //
3d8fad661SChristopher Di Bella // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4d8fad661SChristopher Di Bella // See https://llvm.org/LICENSE.txt for license information.
5d8fad661SChristopher Di Bella // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6d8fad661SChristopher Di Bella //
7d8fad661SChristopher Di Bella //===----------------------------------------------------------------------===//
8d8fad661SChristopher Di Bella 
9d8fad661SChristopher Di Bella // UNSUPPORTED: c++03, c++11, c++14, c++17
10d8fad661SChristopher Di Bella 
11f192616cSLouis Dionne // template<class R>
12f192616cSLouis Dionne // concept forward_range;
13d8fad661SChristopher Di Bella 
14d8fad661SChristopher Di Bella #include <ranges>
15d8fad661SChristopher Di Bella 
16d8fad661SChristopher Di Bella #include "test_iterators.h"
17d8fad661SChristopher Di Bella #include "test_range.h"
18d8fad661SChristopher Di Bella 
19d8fad661SChristopher Di Bella template <template <class...> class I>
check_forward_range()20d8fad661SChristopher Di Bella constexpr bool check_forward_range() {
219d7c420aSLouis Dionne   constexpr bool result = std::ranges::forward_range<test_range<I> >;
229d7c420aSLouis Dionne   static_assert(std::ranges::forward_range<test_range<I> const> == result);
239d7c420aSLouis Dionne   static_assert(std::ranges::forward_range<test_non_const_common_range<I> > == result);
249d7c420aSLouis Dionne   static_assert(std::ranges::forward_range<test_non_const_range<I> > == result);
259d7c420aSLouis Dionne   static_assert(std::ranges::forward_range<test_common_range<I> > == result);
269d7c420aSLouis Dionne   static_assert(std::ranges::forward_range<test_common_range<I> const> == result);
279d7c420aSLouis Dionne   static_assert(!std::ranges::forward_range<test_non_const_common_range<I> const>);
289d7c420aSLouis Dionne   static_assert(!std::ranges::forward_range<test_non_const_range<I> const>);
29d8fad661SChristopher Di Bella   return result;
30d8fad661SChristopher Di Bella }
31d8fad661SChristopher Di Bella 
32d8fad661SChristopher Di Bella static_assert(!check_forward_range<cpp17_input_iterator>());
33d8fad661SChristopher Di Bella static_assert(!check_forward_range<cpp20_input_iterator>());
34d8fad661SChristopher Di Bella static_assert(check_forward_range<forward_iterator>());
35d8fad661SChristopher Di Bella static_assert(check_forward_range<bidirectional_iterator>());
36d8fad661SChristopher Di Bella static_assert(check_forward_range<random_access_iterator>());
37d8fad661SChristopher Di Bella static_assert(check_forward_range<contiguous_iterator>());
38*bf150e8dSArthur O'Dwyer 
39*bf150e8dSArthur O'Dwyer // Test ADL-proofing.
40*bf150e8dSArthur O'Dwyer struct Incomplete;
41*bf150e8dSArthur O'Dwyer template<class T> struct Holder { T t; };
42*bf150e8dSArthur O'Dwyer 
43*bf150e8dSArthur O'Dwyer static_assert(!std::ranges::forward_range<Holder<Incomplete>*>);
44*bf150e8dSArthur O'Dwyer static_assert(!std::ranges::forward_range<Holder<Incomplete>*&>);
45*bf150e8dSArthur O'Dwyer static_assert(!std::ranges::forward_range<Holder<Incomplete>*&&>);
46*bf150e8dSArthur O'Dwyer static_assert(!std::ranges::forward_range<Holder<Incomplete>* const>);
47*bf150e8dSArthur O'Dwyer static_assert(!std::ranges::forward_range<Holder<Incomplete>* const&>);
48*bf150e8dSArthur O'Dwyer static_assert(!std::ranges::forward_range<Holder<Incomplete>* const&&>);
49*bf150e8dSArthur O'Dwyer 
50*bf150e8dSArthur O'Dwyer static_assert( std::ranges::forward_range<Holder<Incomplete>*[10]>);
51*bf150e8dSArthur O'Dwyer static_assert( std::ranges::forward_range<Holder<Incomplete>*(&)[10]>);
52*bf150e8dSArthur O'Dwyer static_assert( std::ranges::forward_range<Holder<Incomplete>*(&&)[10]>);
53*bf150e8dSArthur O'Dwyer static_assert( std::ranges::forward_range<Holder<Incomplete>* const[10]>);
54*bf150e8dSArthur O'Dwyer static_assert( std::ranges::forward_range<Holder<Incomplete>* const(&)[10]>);
55*bf150e8dSArthur O'Dwyer static_assert( std::ranges::forward_range<Holder<Incomplete>* const(&&)[10]>);
56