Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / ranges / range.factories / range.iota.view / empty.pass.cpp
bloba8a34e152643a12a9abe70fb97ed534d1100d61d
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // constexpr bool empty() const;
13 #include <cassert>
14 #include <concepts>
15 #include <ranges>
16 #include <utility>
17 #include <vector>
19 #include "types.h"
21 template <typename R>
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() {
28 std::vector<int> ev;
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() {
37 // Default ctr
39 std::ranges::iota_view<Int42<DefaultTo42>> iv;
41 static_assert(HasEmpty<decltype(iv)>);
43 // Value pass
45 std::ranges::iota_view<SomeInt> iv(SomeInt(94));
47 static_assert(HasEmpty<decltype(iv)>);
51 std::vector<char> v;
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() {
67 std::vector<int> ev;
69 auto iv = std::views::iota(std::ranges::begin(ev), std::ranges::end(ev));
71 assert(iv.empty());
72 assert(std::as_const(iv).empty());
75 constexpr void test_nonempty_iota() {
76 // Default ctr
78 std::ranges::iota_view<Int42<DefaultTo42>> iv;
80 assert(!iv.empty());
82 // Value pass
84 std::ranges::iota_view<SomeInt> iv(SomeInt(94));
86 assert(!iv.empty());
90 std::vector<char> v;
91 auto it = std::back_inserter(v);
92 auto iv = std::views::iota(it);
94 assert(!iv.empty());
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);
101 assert(!iv.empty());
105 constexpr bool test() {
106 test_empty_iota();
107 test_nonempty_iota();
109 return true;
112 int main(int, char**) {
113 test();
114 static_assert(test());
116 return 0;