Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / ranges / range.factories / range.iota.view / views_iota.pass.cpp
bloba6b268fd6a8d8e0f6ad07cfaae0f6e7f1cf6117e
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 // views::iota
13 #include <cassert>
14 #include <concepts>
15 #include <ranges>
16 #include <type_traits>
18 #include "test_macros.h"
19 #include "types.h"
21 template<class T, class U>
22 constexpr void testType(U u) {
23 // Test that this generally does the right thing.
24 // Test with only one argument.
26 assert(*std::views::iota(T(0)).begin() == T(0));
29 const auto io = std::views::iota(T(10));
30 assert(*io.begin() == T(10));
32 // Test with two arguments.
34 assert(*std::views::iota(T(0), u).begin() == T(0));
37 const auto io = std::views::iota(T(10), u);
38 assert(*io.begin() == T(10));
40 // Test that we return the correct type.
42 ASSERT_SAME_TYPE(decltype(std::views::iota(T(10))), std::ranges::iota_view<T>);
43 ASSERT_SAME_TYPE(decltype(std::views::iota(T(10), u)), std::ranges::iota_view<T, U>);
47 struct X {};
49 constexpr bool test() {
50 testType<SomeInt>(SomeInt(10));
51 testType<SomeInt>(IntComparableWith(SomeInt(10)));
52 testType<signed long>(IntComparableWith<signed long>(10));
53 testType<unsigned long>(IntComparableWith<unsigned long>(10));
54 testType<int>(IntComparableWith<int>(10));
55 testType<int>(int(10));
56 testType<unsigned>(unsigned(10));
57 testType<unsigned>(IntComparableWith<unsigned>(10));
58 testType<short>(short(10));
59 testType<short>(IntComparableWith<short>(10));
60 testType<unsigned short>(IntComparableWith<unsigned short>(10));
63 static_assert( std::is_invocable_v<decltype(std::views::iota), int>);
64 static_assert(!std::is_invocable_v<decltype(std::views::iota), X>);
65 static_assert( std::is_invocable_v<decltype(std::views::iota), int, int>);
66 static_assert(!std::is_invocable_v<decltype(std::views::iota), int, X>);
69 static_assert(std::same_as<decltype(std::views::iota), decltype(std::ranges::views::iota)>);
72 return true;
75 int main(int, char**) {
76 test();
77 static_assert(test());
79 return 0;