brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · 733729f Raw
99 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++17, c++2010 11// constexpr explicit repeat_view(const T& value, Bound bound = Bound()) requires copy_constructible<T>;12// constexpr explicit repeat_view(T&& value, Bound bound = Bound());13 14#include <ranges>15#include <cassert>16#include <iterator>17#include <type_traits>18 19#include "MoveOnly.h"20 21struct Empty {};22 23// Test explicit24static_assert(std::is_constructible_v<std::ranges::repeat_view<Empty>, const Empty&>);25static_assert(std::is_constructible_v<std::ranges::repeat_view<Empty>, Empty&&>);26static_assert(std::is_constructible_v<std::ranges::repeat_view<Empty, int>, const Empty&>);27static_assert(std::is_constructible_v<std::ranges::repeat_view<Empty, int>, Empty&&>);28 29static_assert(!std::is_convertible_v<const Empty&, std::ranges::repeat_view<Empty>>);30static_assert(!std::is_convertible_v<Empty&&, std::ranges::repeat_view<Empty>>);31static_assert(!std::is_convertible_v<const Empty&, std::ranges::repeat_view<Empty, int>>);32static_assert(!std::is_convertible_v<Empty&&, std::ranges::repeat_view<Empty, int>>);33 34static_assert(!std::is_constructible_v<std::ranges::repeat_view<MoveOnly>, const MoveOnly&>);35static_assert(std::is_constructible_v<std::ranges::repeat_view<MoveOnly>, MoveOnly&&>);36 37constexpr bool test() {38  // Move && unbound && default argument39  {40    std::ranges::repeat_view<Empty> rv(Empty{});41    assert(rv.begin() + 10 != rv.end());42  }43 44  // Move && unbound && user-provided argument45  {46    std::ranges::repeat_view<Empty> rv(Empty{}, std::unreachable_sentinel);47    assert(rv.begin() + 10 != rv.end());48  }49 50  // Move && bound && default argument51  {52    std::ranges::repeat_view<Empty, int> rv(Empty{});53    assert(rv.begin() == rv.end());54  }55 56  // Move && bound && user-provided argument57  {58    std::ranges::repeat_view<Empty, int> rv(Empty{}, 10);59    assert(rv.begin() + 10 == rv.end());60  }61 62  // Copy && unbound && default argument63  {64    Empty e;65    std::ranges::repeat_view<Empty> rv(e);66    assert(rv.begin() + 10 != rv.end());67  }68 69  // Copy && unbound && user-provided argument70  {71    Empty e;72    std::ranges::repeat_view<Empty> rv(e, std::unreachable_sentinel);73    assert(rv.begin() + 10 != rv.end());74  }75 76  // Copy && bound && default argument77  {78    Empty e;79    std::ranges::repeat_view<Empty, int> rv(e);80    assert(rv.begin() == rv.end());81  }82 83  // Copy && bound && user-provided argument84  {85    Empty e;86    std::ranges::repeat_view<Empty, int> rv(e, 10);87    assert(rv.begin() + 10 == rv.end());88  }89 90  return true;91}92 93int main(int, char**) {94  test();95  static_assert(test());96 97  return 0;98}99