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
16 #include <type_traits>
18 #include "test_macros.h"
21 template<class T
, class U
>
22 constexpr void testType(U u
) {
23 // Test that this generally does the right thing.
24 // Test with only one argument.
26 assert(*std::views::iota(T(0)).begin() == T(0));
29 const auto io
= std::views::iota(T(10));
30 assert(*io
.begin() == T(10));
32 // Test with two arguments.
34 assert(*std::views::iota(T(0), u
).begin() == T(0));
37 const auto io
= std::views::iota(T(10), u
);
38 assert(*io
.begin() == T(10));
40 // Test that we return the correct type.
42 ASSERT_SAME_TYPE(decltype(std::views::iota(T(10))), std::ranges::iota_view
<T
>);
43 ASSERT_SAME_TYPE(decltype(std::views::iota(T(10), u
)), std::ranges::iota_view
<T
, U
>);
49 constexpr bool test() {
50 testType
<SomeInt
>(SomeInt(10));
51 testType
<SomeInt
>(IntComparableWith(SomeInt(10)));
52 testType
<signed long>(IntComparableWith
<signed long>(10));
53 testType
<unsigned long>(IntComparableWith
<unsigned long>(10));
54 testType
<int>(IntComparableWith
<int>(10));
55 testType
<int>(int(10));
56 testType
<unsigned>(unsigned(10));
57 testType
<unsigned>(IntComparableWith
<unsigned>(10));
58 testType
<short>(short(10));
59 testType
<short>(IntComparableWith
<short>(10));
60 testType
<unsigned short>(IntComparableWith
<unsigned short>(10));
63 static_assert( std::is_invocable_v
<decltype(std::views::iota
), int>);
64 static_assert(!std::is_invocable_v
<decltype(std::views::iota
), X
>);
65 static_assert( std::is_invocable_v
<decltype(std::views::iota
), int, int>);
66 static_assert(!std::is_invocable_v
<decltype(std::views::iota
), int, X
>);
69 static_assert(std::same_as
<decltype(std::views::iota
), decltype(std::ranges::views::iota
)>);
75 int main(int, char**) {
77 static_assert(test());