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 | // template<class... TArgs, class... BoundArgs> |
12 | // requires constructible_from<T, TArgs...> && |
13 | // constructible_from<Bound, BoundArgs...> |
14 | // constexpr explicit repeat_view(piecewise_construct_t, |
15 | // tuple<TArgs...> value_args, tuple<BoundArgs...> bound_args = tuple<>{}); |
16 | |
17 | #include <ranges> |
18 | #include <cassert> |
19 | #include <concepts> |
20 | #include <tuple> |
21 | #include <utility> |
22 | |
23 | struct C {}; |
24 | |
25 | struct B { |
26 | int v; |
27 | }; |
28 | |
29 | struct A { |
30 | int x = 111; |
31 | int y = 222; |
32 | |
33 | constexpr A() = default; |
34 | constexpr A(B b) : x(b.v), y(b.v + 1) {} |
35 | constexpr A(int _x, int _y) : x(_x), y(_y) {} |
36 | }; |
37 | |
38 | static_assert(std::constructible_from<std::ranges::repeat_view<A, int>, |
39 | std::piecewise_construct_t, |
40 | std::tuple<int, int>, |
41 | std::tuple<int>>); |
42 | static_assert(std::constructible_from<std::ranges::repeat_view<A, int>, |
43 | std::piecewise_construct_t, |
44 | std::tuple<B>, |
45 | std::tuple<int>>); |
46 | static_assert(std::constructible_from<std::ranges::repeat_view<A, int>, |
47 | std::piecewise_construct_t, |
48 | std::tuple<>, |
49 | std::tuple<int>>); |
50 | static_assert(std::constructible_from<std::ranges::repeat_view<A>, |
51 | std::piecewise_construct_t, |
52 | std::tuple<int, int>, |
53 | std::tuple<std::unreachable_sentinel_t>>); |
54 | static_assert(std::constructible_from<std::ranges::repeat_view<A>, |
55 | std::piecewise_construct_t, |
56 | std::tuple<B>, |
57 | std::tuple<std::unreachable_sentinel_t>>); |
58 | static_assert(std::constructible_from<std::ranges::repeat_view<A>, |
59 | std::piecewise_construct_t, |
60 | std::tuple<>, |
61 | std::tuple<std::unreachable_sentinel_t>>); |
62 | static_assert(!std::constructible_from<std::ranges::repeat_view<A, int>, |
63 | std::piecewise_construct_t, |
64 | std::tuple<C>, |
65 | std::tuple<int>>); |
66 | static_assert(!std::constructible_from<std::ranges::repeat_view<A>, |
67 | std::piecewise_construct_t, |
68 | std::tuple<C>, |
69 | std::tuple<std::unreachable_sentinel_t>>); |
70 | static_assert(!std::constructible_from<std::ranges::repeat_view<A, int>, |
71 | std::piecewise_construct_t, |
72 | std::tuple<int, int, int>, |
73 | std::tuple<int>>); |
74 | static_assert(!std::constructible_from<std::ranges::repeat_view<A>, |
75 | std::piecewise_construct_t, |
76 | std::tuple<int, int, int>, |
77 | std::tuple<std::unreachable_sentinel_t>>); |
78 | static_assert( |
79 | !std::constructible_from<std::ranges::repeat_view<A>, std::piecewise_construct_t, std::tuple<B>, std::tuple<int>>); |
80 | |
81 | constexpr bool test() { |
82 | { |
83 | std::ranges::repeat_view<A, int> rv(std::piecewise_construct, std::tuple{}, std::tuple{3}); |
84 | assert(rv.size() == 3); |
85 | assert(rv[0].x == 111); |
86 | assert(rv[0].y == 222); |
87 | assert(rv.begin() + 3 == rv.end()); |
88 | } |
89 | { |
90 | std::ranges::repeat_view<A> rv(std::piecewise_construct, std::tuple{}, std::tuple{std::unreachable_sentinel}); |
91 | assert(rv[0].x == 111); |
92 | assert(rv[0].y == 222); |
93 | assert(rv.begin() + 300 != rv.end()); |
94 | } |
95 | { |
96 | std::ranges::repeat_view<A, int> rv(std::piecewise_construct, std::tuple{1, 2}, std::tuple{3}); |
97 | assert(rv.size() == 3); |
98 | assert(rv[0].x == 1); |
99 | assert(rv[0].y == 2); |
100 | assert(rv.begin() + 3 == rv.end()); |
101 | } |
102 | { |
103 | std::ranges::repeat_view<A> rv(std::piecewise_construct, std::tuple{1, 2}, std::tuple{std::unreachable_sentinel}); |
104 | assert(rv[0].x == 1); |
105 | assert(rv[0].y == 2); |
106 | assert(rv.begin() + 300 != rv.end()); |
107 | } |
108 | { |
109 | std::ranges::repeat_view<A, int> rv(std::piecewise_construct, std::tuple{B{11}}, std::tuple{3}); |
110 | assert(rv.size() == 3); |
111 | assert(rv[0].x == 11); |
112 | assert(rv[0].y == 12); |
113 | assert(rv.begin() + 3 == rv.end()); |
114 | } |
115 | { |
116 | std::ranges::repeat_view<A> rv(std::piecewise_construct, std::tuple{B{10}}, std::tuple{std::unreachable_sentinel}); |
117 | assert(rv[0].x == 10); |
118 | assert(rv[0].y == 11); |
119 | assert(rv.begin() + 300 != rv.end()); |
120 | } |
121 | |
122 | return true; |
123 | } |
124 | |
125 | int main(int, char**) { |
126 | test(); |
127 | static_assert(test()); |
128 | |
129 | return 0; |
130 | } |
131 | |