//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14, c++17 // views::iota #include #include #include #include #include "test_macros.h" #include "types.h" template constexpr void testType(U u) { // Test that this generally does the right thing. // Test with only one argument. { assert(*std::views::iota(T(0)).begin() == T(0)); } { const auto io = std::views::iota(T(10)); assert(*io.begin() == T(10)); } // Test with two arguments. { assert(*std::views::iota(T(0), u).begin() == T(0)); } { const auto io = std::views::iota(T(10), u); assert(*io.begin() == T(10)); } // Test that we return the correct type. { ASSERT_SAME_TYPE(decltype(std::views::iota(T(10))), std::ranges::iota_view); ASSERT_SAME_TYPE(decltype(std::views::iota(T(10), u)), std::ranges::iota_view); } } struct X {}; template concept CanDoubleWrap = requires(IntT i) { std::views::iota(std::views::iota(i)); }; constexpr bool test() { testType(SomeInt(10)); testType(IntComparableWith(SomeInt(10))); testType(IntComparableWith(10)); testType(IntComparableWith(10)); testType(IntComparableWith(10)); testType(int(10)); testType(unsigned(10)); testType(IntComparableWith(10)); testType(short(10)); testType(IntComparableWith(10)); testType(IntComparableWith(10)); { static_assert( std::is_invocable_v); static_assert(!std::is_invocable_v); static_assert( std::is_invocable_v); static_assert(!std::is_invocable_v); } { static_assert(std::same_as); } { // LWG4096: views::iota(views::iota(0)) should be rejected static_assert(!CanDoubleWrap); static_assert(!CanDoubleWrap); static_assert(!std::is_invocable_v); static_assert(!std::is_invocable_v); static_assert(!std::is_invocable_v); static_assert(!std::is_invocable_v); } return true; } int main(int, char**) { test(); static_assert(test()); return 0; }