brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · 4f06b26 Raw
93 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 11// views::iota12 13#include <cassert>14#include <concepts>15#include <ranges>16#include <type_traits>17 18#include "test_macros.h"19#include "types.h"20 21template<class T, class U>22constexpr void testType(U u) {23  // Test that this generally does the right thing.24  // Test with only one argument.25  {26    assert(*std::views::iota(T(0)).begin() == T(0));27  }28  {29    const auto io = std::views::iota(T(10));30    assert(*io.begin() == T(10));31  }32  // Test with two arguments.33  {34    assert(*std::views::iota(T(0), u).begin() == T(0));35  }36  {37    const auto io = std::views::iota(T(10), u);38    assert(*io.begin() == T(10));39  }40  // Test that we return the correct type.41  {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>);44  }45}46 47struct X {};48 49template <typename IntT>50concept CanDoubleWrap = requires(IntT i) { std::views::iota(std::views::iota(i)); };51 52constexpr bool test() {53  testType<SomeInt>(SomeInt(10));54  testType<SomeInt>(IntComparableWith(SomeInt(10)));55  testType<signed long>(IntComparableWith<signed long>(10));56  testType<unsigned long>(IntComparableWith<unsigned long>(10));57  testType<int>(IntComparableWith<int>(10));58  testType<int>(int(10));59  testType<unsigned>(unsigned(10));60  testType<unsigned>(IntComparableWith<unsigned>(10));61  testType<short>(short(10));62  testType<short>(IntComparableWith<short>(10));63  testType<unsigned short>(IntComparableWith<unsigned short>(10));64 65  {66    static_assert( std::is_invocable_v<decltype(std::views::iota), int>);67    static_assert(!std::is_invocable_v<decltype(std::views::iota), X>);68    static_assert( std::is_invocable_v<decltype(std::views::iota), int, int>);69    static_assert(!std::is_invocable_v<decltype(std::views::iota), int, X>);70  }71  {72    static_assert(std::same_as<decltype(std::views::iota), decltype(std::ranges::views::iota)>);73  }74  { // LWG4096: views::iota(views::iota(0)) should be rejected75    static_assert(!CanDoubleWrap<int>);76    static_assert(!CanDoubleWrap<SomeInt>);77 78    static_assert(!std::is_invocable_v<decltype(std::views::iota), decltype(std::views::iota(0))>);79    static_assert(!std::is_invocable_v<decltype(std::views::iota), decltype(std::views::iota(82))>);80    static_assert(!std::is_invocable_v<decltype(std::views::iota), decltype(std::views::iota(SomeInt(0)))>);81    static_assert(!std::is_invocable_v<decltype(std::views::iota), decltype(std::views::iota(SomeInt(94)))>);82  }83 84  return true;85}86 87int main(int, char**) {88  test();89  static_assert(test());90 91  return 0;92}93