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 // !StoreSize ctor.
29 static_assert( std::is_constructible_v<ForwardSubrange, ForwardIter, ForwardIter>); // Default case.
30 static_assert(!std::is_constructible_v<ForwardSubrange, Empty, ForwardIter>); // 1.
31 static_assert( std::is_constructible_v<ConvertibleForwardSubrange, ConvertibleForwardIter, int*>); // 2.
32 static_assert( std::is_constructible_v<ForwardSubrange, ForwardIter, ForwardIter>); // 3. (Same as default case.)
33 // 4. and 5. must be sized.
34
test()35 constexpr bool test() {
36 ForwardSubrange a(ForwardIter(globalBuff), ForwardIter(globalBuff + 8));
37 assert(base(a.begin()) == globalBuff);
38 assert(base(a.end()) == globalBuff + 8);
39
40 ConvertibleForwardSubrange b(ConvertibleForwardIter(globalBuff), globalBuff + 8);
41 assert(b.begin() == globalBuff);
42 assert(b.end() == globalBuff + 8);
43
44 return true;
45 }
46
main(int,char **)47 int main(int, char**) {
48 test();
49 static_assert(test());
50
51 return 0;
52 }
53