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 // constexpr iota_view(iterator first, see below last); // explicit since C++23
16 #include "test_convertible.h"
17 #include "test_macros.h"
22 #if TEST_STD_VER >= 23
24 std::ranges::iota_view
<SomeInt
, SomeInt
> view
;
26 static_assert(!test_convertible
<std::ranges::iota_view
<SomeInt
, SomeInt
>,
27 decltype(std::ranges::iota_view
<SomeInt
, SomeInt
>{}.begin()),
28 decltype(std::ranges::iota_view
<SomeInt
, SomeInt
>{}.end())>(),
29 "This constructor must be explicit");
31 static_assert(!test_convertible
<std::ranges::iota_view
<SomeInt
>,
32 decltype(std::ranges::iota_view
{SomeInt
{0}}.begin()),
33 decltype(std::unreachable_sentinel
)>(),
34 "This constructor must be explicit");
36 static_assert(!test_convertible
<std::ranges::iota_view
<SomeInt
, IntComparableWith
<SomeInt
>>,
37 decltype(std::ranges::iota_view
{SomeInt(0), IntComparableWith(SomeInt(10))}.begin()),
38 decltype(std::ranges::iota_view
{SomeInt(0), IntComparableWith(SomeInt(10))}.end())>(),
39 "This constructor must be explicit");
43 static_assert(test_convertible
<std::ranges::iota_view
<SomeInt
, SomeInt
>,
44 decltype(std::ranges::iota_view
<SomeInt
, SomeInt
>{}.begin()),
45 decltype(std::ranges::iota_view
<SomeInt
, SomeInt
>{}.end())>(),
46 "This constructor must not be explicit");
48 static_assert(test_convertible
<std::ranges::iota_view
<SomeInt
>,
49 decltype(std::ranges::iota_view
{SomeInt
{0}}.begin()),
50 decltype(std::unreachable_sentinel
)>(),
51 "This constructor must not be explicit");
53 static_assert(test_convertible
<std::ranges::iota_view
<SomeInt
, IntComparableWith
<SomeInt
>>,
54 decltype(std::ranges::iota_view
{SomeInt(0), IntComparableWith(SomeInt(10))}.begin()),
55 decltype(std::ranges::iota_view
{SomeInt(0), IntComparableWith(SomeInt(10))}.end())>(),
56 "This constructor must not be explicit");
58 #endif // TEST_STD_VER >= 23
60 constexpr bool test() {
62 std::ranges::iota_view
commonView(SomeInt(0), SomeInt(10));
63 std::ranges::iota_view
<SomeInt
, SomeInt
> io(commonView
.begin(), commonView
.end());
64 assert(std::ranges::next(io
.begin(), 10) == io
.end());
68 std::ranges::iota_view
unreachableSent(SomeInt(0));
69 std::ranges::iota_view
<SomeInt
> io(unreachableSent
.begin(), std::unreachable_sentinel
);
70 assert(std::ranges::next(io
.begin(), 10) != io
.end());
74 std::ranges::iota_view
differentTypes(SomeInt(0), IntComparableWith(SomeInt(10)));
75 std::ranges::iota_view
<SomeInt
, IntComparableWith
<SomeInt
>> io(differentTypes
.begin(), differentTypes
.end());
76 assert(std::ranges::next(io
.begin(), 10) == io
.end());
80 std::ranges::iota_view
<int, std::unreachable_sentinel_t
> iv1
;
81 // There should be only one overload available and {} resolves to unreachable_sentinel_t
82 [[maybe_unused
]] std::ranges::iota_view
<int, std::unreachable_sentinel_t
> iv2(iv1
.begin(), {});
88 int main(int, char**) {
90 static_assert(test());