Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / ranges / range.factories / range.iota.view / ctor.first.last.pass.cpp
blob67b7dc428a14f002e16d56f3447b59deadce59fc
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 iota_view(iterator first, see below last); // explicit since C++23
13 #include <ranges>
14 #include <cassert>
16 #include "test_convertible.h"
17 #include "test_macros.h"
18 #include "types.h"
20 // SFINAE tests.
22 #if TEST_STD_VER >= 23
24 std::ranges::iota_view<SomeInt, SomeInt> view;
26 static_assert(!test_convertible<std::ranges::iota_view<SomeInt, SomeInt>,
27 decltype(std::ranges::iota_view<SomeInt, SomeInt>{}.begin()),
28 decltype(std::ranges::iota_view<SomeInt, SomeInt>{}.end())>(),
29 "This constructor must be explicit");
31 static_assert(!test_convertible<std::ranges::iota_view<SomeInt>,
32 decltype(std::ranges::iota_view{SomeInt{0}}.begin()),
33 decltype(std::unreachable_sentinel)>(),
34 "This constructor must be explicit");
36 static_assert(!test_convertible<std::ranges::iota_view<SomeInt, IntComparableWith<SomeInt>>,
37 decltype(std::ranges::iota_view{SomeInt(0), IntComparableWith(SomeInt(10))}.begin()),
38 decltype(std::ranges::iota_view{SomeInt(0), IntComparableWith(SomeInt(10))}.end())>(),
39 "This constructor must be explicit");
41 #else
43 static_assert(test_convertible<std::ranges::iota_view<SomeInt, SomeInt>,
44 decltype(std::ranges::iota_view<SomeInt, SomeInt>{}.begin()),
45 decltype(std::ranges::iota_view<SomeInt, SomeInt>{}.end())>(),
46 "This constructor must not be explicit");
48 static_assert(test_convertible<std::ranges::iota_view<SomeInt>,
49 decltype(std::ranges::iota_view{SomeInt{0}}.begin()),
50 decltype(std::unreachable_sentinel)>(),
51 "This constructor must not be explicit");
53 static_assert(test_convertible<std::ranges::iota_view<SomeInt, IntComparableWith<SomeInt>>,
54 decltype(std::ranges::iota_view{SomeInt(0), IntComparableWith(SomeInt(10))}.begin()),
55 decltype(std::ranges::iota_view{SomeInt(0), IntComparableWith(SomeInt(10))}.end())>(),
56 "This constructor must not be explicit");
58 #endif // TEST_STD_VER >= 23
60 constexpr bool test() {
62 std::ranges::iota_view commonView(SomeInt(0), SomeInt(10));
63 std::ranges::iota_view<SomeInt, SomeInt> io(commonView.begin(), commonView.end());
64 assert(std::ranges::next(io.begin(), 10) == io.end());
68 std::ranges::iota_view unreachableSent(SomeInt(0));
69 std::ranges::iota_view<SomeInt> io(unreachableSent.begin(), std::unreachable_sentinel);
70 assert(std::ranges::next(io.begin(), 10) != io.end());
74 std::ranges::iota_view differentTypes(SomeInt(0), IntComparableWith(SomeInt(10)));
75 std::ranges::iota_view<SomeInt, IntComparableWith<SomeInt>> io(differentTypes.begin(), differentTypes.end());
76 assert(std::ranges::next(io.begin(), 10) == io.end());
80 std::ranges::iota_view<int, std::unreachable_sentinel_t> iv1;
81 // There should be only one overload available and {} resolves to unreachable_sentinel_t
82 [[maybe_unused]] std::ranges::iota_view<int, std::unreachable_sentinel_t> iv2(iv1.begin(), {});
85 return true;
88 int main(int, char**) {
89 test();
90 static_assert(test());
92 return 0;