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-no-concepts
11 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
12 
13 // class std::ranges::subrange;
14 
15 #include <ranges>
16 
17 #include "types.h"
18 #include <cassert>
19 #include "test_macros.h"
20 #include "test_iterators.h"
21 
22 // convertible-to-non-slicing cases:
23 //   1. Not convertible (fail)
24 //   2. Only one is a pointer (succeed)
25 //   3. Both are not pointers (succeed)
26 //   4. Pointer elements are different types (fail)
27 //   5. Pointer elements are same type (succeed)
28 
29 // !StoreSize ctor.
30 static_assert( std::is_constructible_v<ForwardSubrange, ForwardIter, ForwardIter>); // Default case.
31 static_assert(!std::is_constructible_v<ForwardSubrange, Empty, ForwardIter>); // 1.
32 static_assert( std::is_constructible_v<ConvertibleForwardSubrange, ConvertibleForwardIter, int*>); // 2.
33 static_assert( std::is_constructible_v<ForwardSubrange, ForwardIter, ForwardIter>); // 3. (Same as default case.)
34 // 4. and 5. must be sized.
35 
36 constexpr bool test() {
37   ForwardSubrange a(ForwardIter(globalBuff), ForwardIter(globalBuff + 8));
38   assert(a.begin().base() == globalBuff);
39   assert(a.end().base() == globalBuff + 8);
40 
41   ConvertibleForwardSubrange b(ConvertibleForwardIter(globalBuff), globalBuff + 8);
42   assert(b.begin() == globalBuff);
43   assert(b.end() == globalBuff + 8);
44 
45   return true;
46 }
47 
48 int main(int, char**) {
49   test();
50   static_assert(test());
51 
52   return 0;
53 }
54