1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // constexpr bool empty() const;
22 concept HasEmpty
= requires(const R r
) {
23 std::ranges::empty(r
);
24 { r
.empty() } -> std::same_as
<bool>;
27 constexpr void test_empty_iota_sfinae() {
30 auto iv
= std::views::iota(std::ranges::begin(ev
), std::ranges::end(ev
));
32 static_assert(HasEmpty
<decltype(iv
)>);
33 static_assert(HasEmpty
<decltype(std::as_const(iv
))>);
36 constexpr void test_nonempty_iota_sfinae() {
39 std::ranges::iota_view
<Int42
<DefaultTo42
>> iv
;
41 static_assert(HasEmpty
<decltype(iv
)>);
45 std::ranges::iota_view
<SomeInt
> iv(SomeInt(94));
47 static_assert(HasEmpty
<decltype(iv
)>);
52 auto it
= std::back_inserter(v
);
53 auto iv
= std::views::iota(it
);
55 static_assert(HasEmpty
<decltype(iv
)>);
58 std::vector
<char> v
{'b', 'a', 'b', 'a', 'z', 'm', 't'};
59 auto it
= std::back_inserter(v
);
60 auto iv
= std::views::iota(it
);
62 static_assert(HasEmpty
<decltype(iv
)>);
66 constexpr void test_empty_iota() {
69 auto iv
= std::views::iota(std::ranges::begin(ev
), std::ranges::end(ev
));
72 assert(std::as_const(iv
).empty());
75 constexpr void test_nonempty_iota() {
78 std::ranges::iota_view
<Int42
<DefaultTo42
>> iv
;
84 std::ranges::iota_view
<SomeInt
> iv(SomeInt(94));
91 auto it
= std::back_inserter(v
);
92 auto iv
= std::views::iota(it
);
97 std::vector
<char> v
{'b', 'a', 'b', 'a', 'z', 'm', 't'};
98 auto it
= std::back_inserter(v
);
99 auto iv
= std::views::iota(it
);
105 constexpr bool test() {
107 test_nonempty_iota();
112 int main(int, char**) {
114 static_assert(test());