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 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
11 
12 // class std::ranges::subrange;
13 
14 #include <ranges>
15 
16 #include <cassert>
17 #include "test_macros.h"
18 #include "test_iterators.h"
19 
20 template<std::ranges::subrange_kind K, class... Args>
21 concept ValidSubrangeKind = requires { typename std::ranges::subrange<Args..., K>; };
22 
23 template<class... Args>
24 concept ValidSubrange = requires { typename std::ranges::subrange<Args...>; };
25 
26 static_assert( ValidSubrange<forward_iterator<int*>>);
27 static_assert( ValidSubrange<forward_iterator<int*>, forward_iterator<int*>>);
28 static_assert( ValidSubrangeKind<std::ranges::subrange_kind::unsized, forward_iterator<int*>, forward_iterator<int*>>);
29 static_assert( ValidSubrangeKind<std::ranges::subrange_kind::sized, forward_iterator<int*>, forward_iterator<int*>>);
30 // Wrong sentinel type.
31 static_assert(!ValidSubrange<forward_iterator<int*>, int*>);
32 static_assert( ValidSubrange<int*>);
33 static_assert( ValidSubrange<int*, int*>);
34 // Must be sized.
35 static_assert(!ValidSubrangeKind<std::ranges::subrange_kind::unsized, int*, int*>);
36 static_assert( ValidSubrangeKind<std::ranges::subrange_kind::sized, int*, int*>);
37 // Wrong sentinel type.
38 static_assert(!ValidSubrange<int*, forward_iterator<int*>>);
39 // Not an iterator.
40 static_assert(!ValidSubrange<int>);
41