brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.7 KiB · 67b7dc4 Raw
95 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// constexpr iota_view(iterator first, see below last); // explicit since C++2312 13#include <ranges>14#include <cassert>15 16#include "test_convertible.h"17#include "test_macros.h"18#include "types.h"19 20// SFINAE tests.21 22#if TEST_STD_VER >= 2323 24std::ranges::iota_view<SomeInt, SomeInt> view;25 26static_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");30 31static_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");35 36static_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");40 41#else42 43static_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");47 48static_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");52 53static_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");57 58#endif // TEST_STD_VER >= 2359 60constexpr bool test() {61  {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());65  }66 67  {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());71  }72 73  {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());77  }78 79  {80    std::ranges::iota_view<int, std::unreachable_sentinel_t> iv1;81    // There should be only one overload available and {} resolves to unreachable_sentinel_t82    [[maybe_unused]] std::ranges::iota_view<int, std::unreachable_sentinel_t> iv2(iv1.begin(), {});83  }84 85  return true;86}87 88int main(int, char**) {89  test();90  static_assert(test());91 92  return 0;93}94 95