1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // class std::ranges::subrange;
17 #include "test_macros.h"
18 #include "test_iterators.h"
20 // convertible-to-non-slicing cases:
21 // 1. Not convertible (fail)
22 // 2. Only one is a pointer (succeed)
23 // 3. Both are not pointers (succeed)
24 // 4. Pointer elements are different types (fail)
25 // 5. Pointer elements are same type (succeed)
28 static_assert( std::is_constructible_v
<ForwardSubrange
, ForwardIter
, ForwardIter
>); // Default case.
29 static_assert(!std::is_constructible_v
<ForwardSubrange
, Empty
, ForwardIter
>); // 1.
30 static_assert( std::is_constructible_v
<ConvertibleForwardSubrange
, ConvertibleForwardIter
, int*>); // 2.
31 static_assert( std::is_constructible_v
<ForwardSubrange
, ForwardIter
, ForwardIter
>); // 3. (Same as default case.)
32 // 4. and 5. must be sized.
34 constexpr bool test() {
35 ForwardSubrange
a(ForwardIter(globalBuff
), ForwardIter(globalBuff
+ 8));
36 assert(base(a
.begin()) == globalBuff
);
37 assert(base(a
.end()) == globalBuff
+ 8);
39 ConvertibleForwardSubrange
b(ConvertibleForwardIter(globalBuff
), globalBuff
+ 8);
40 assert(b
.begin() == globalBuff
);
41 assert(b
.end() == globalBuff
+ 8);
46 int main(int, char**) {
48 static_assert(test());