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 "types.h"
17 #include <cassert>
18 #include "test_macros.h"
19 #include "test_iterators.h"
20
21 // convertible-to-non-slicing cases:
22 // 1. Not convertible (fail)
23 // 2. Only one is a pointer (succeed)
24 // 3. Both are not pointers (succeed)
25 // 4. Pointer elements are different types (fail)
26 // 5. Pointer elements are same type (succeed)
27
28 static_assert( std::is_constructible_v<SizedSentinelForwardSubrange, ConditionallyConvertibleIter, ConditionallyConvertibleIter, ConditionallyConvertibleIter::udifference_type>); // Default case.
29 static_assert(!std::is_constructible_v<SizedSentinelForwardSubrange, Empty, ConditionallyConvertibleIter, ConditionallyConvertibleIter::udifference_type>); // 1.
30 static_assert( std::is_constructible_v<ConvertibleSizedSentinelForwardSubrange, ConvertibleSizedSentinelForwardIter, int*, ConvertibleSizedSentinelForwardIter::udifference_type>); // 2.
31 static_assert( std::is_constructible_v<SizedSentinelForwardSubrange, ConditionallyConvertibleIter, ConditionallyConvertibleIter, ConditionallyConvertibleIter::udifference_type>); // 3. (Same as default case.)
32 static_assert(!std::is_constructible_v<SizedIntPtrSubrange, long*, int*, size_t>); // 4.
33 static_assert( std::is_constructible_v<SizedIntPtrSubrange, int*, int*, size_t>); // 5.
34
test()35 constexpr bool test() {
36 SizedSentinelForwardSubrange a(ConditionallyConvertibleIter(globalBuff), ConditionallyConvertibleIter(globalBuff + 8), 8);
37 assert(a.begin().base() == globalBuff);
38 assert(a.end().base() == globalBuff + 8);
39 assert(a.size() == 8);
40
41 ConvertibleSizedSentinelForwardSubrange b(ConvertibleSizedSentinelForwardIter(globalBuff), ConvertibleSizedSentinelForwardIter(globalBuff + 8), 8);
42 assert(b.begin() == globalBuff);
43 assert(b.end() == globalBuff + 8);
44 assert(b.size() == 8);
45
46 SizedIntPtrSubrange c(globalBuff, globalBuff + 8, 8);
47 assert(c.begin() == globalBuff);
48 assert(c.end() == globalBuff + 8);
49 assert(c.size() == 8);
50
51 return true;
52 }
53
main(int,char **)54 int main(int, char**) {
55 test();
56 static_assert(test());
57
58 return 0;
59 }
60