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-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10
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
21 struct Empty {};
22
23 // Test explicit
24 static_assert(std::is_constructible_v<std::ranges::repeat_view<Empty>, const Empty&>);
25 static_assert(std::is_constructible_v<std::ranges::repeat_view<Empty>, Empty&&>);
26 static_assert(std::is_constructible_v<std::ranges::repeat_view<Empty, int>, const Empty&>);
27 static_assert(std::is_constructible_v<std::ranges::repeat_view<Empty, int>, Empty&&>);
28
29 static_assert(!std::is_convertible_v<const Empty&, std::ranges::repeat_view<Empty>>);
30 static_assert(!std::is_convertible_v<Empty&&, std::ranges::repeat_view<Empty>>);
31 static_assert(!std::is_convertible_v<const Empty&, std::ranges::repeat_view<Empty, int>>);
32 static_assert(!std::is_convertible_v<Empty&&, std::ranges::repeat_view<Empty, int>>);
33
34 static_assert(!std::is_constructible_v<std::ranges::repeat_view<MoveOnly>, const MoveOnly&>);
35 static_assert(std::is_constructible_v<std::ranges::repeat_view<MoveOnly>, MoveOnly&&>);
36
test()37 constexpr bool test() {
38 // Move && unbound && default argument
39 {
40 std::ranges::repeat_view<Empty> rv(Empty{});
41 assert(rv.begin() + 10 != rv.end());
42 }
43
44 // Move && unbound && user-provided argument
45 {
46 std::ranges::repeat_view<Empty> rv(Empty{}, std::unreachable_sentinel);
47 assert(rv.begin() + 10 != rv.end());
48 }
49
50 // Move && bound && default argument
51 {
52 std::ranges::repeat_view<Empty, int> rv(Empty{});
53 assert(rv.begin() == rv.end());
54 }
55
56 // Move && bound && user-provided argument
57 {
58 std::ranges::repeat_view<Empty, int> rv(Empty{}, 10);
59 assert(rv.begin() + 10 == rv.end());
60 }
61
62 // Copy && unbound && default argument
63 {
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 argument
70 {
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 argument
77 {
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 argument
84 {
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
main(int,char **)93 int main(int, char**) {
94 test();
95 static_assert(test());
96
97 return 0;
98 }
99