Revert "[libc] Breakup freelist_malloc into separate files" (#119749)
[llvm-project.git] / libcxx / test / std / ranges / range.factories / range.single.view / cpo.pass.cpp
blobd818a749c68cb557fdc7230f13c332b8a1169f0f
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 // std::views::single
13 #include <ranges>
15 #include <cassert>
16 #include <concepts>
17 #include <utility>
18 #include "MoveOnly.h"
20 // Can't invoke without arguments.
21 static_assert(!std::is_invocable_v<decltype((std::views::single))>);
22 #if _LIBCPP_STD_VER >= 23
23 // Can invoke with a move-only type.
24 static_assert(std::is_invocable_v<decltype((std::views::single)), MoveOnly>);
25 #endif
26 constexpr bool test() {
27 // Lvalue.
29 int x = 42;
30 std::same_as<std::ranges::single_view<int>> decltype(auto) v = std::views::single(x);
31 assert(v.size() == 1);
32 assert(v.front() == x);
35 // Prvalue.
37 std::same_as<std::ranges::single_view<int>> decltype(auto) v = std::views::single(42);
38 assert(v.size() == 1);
39 assert(v.front() == 42);
42 // Const lvalue.
44 const int x = 42;
45 std::same_as<std::ranges::single_view<int>> decltype(auto) v = std::views::single(x);
46 assert(v.size() == 1);
47 assert(v.front() == x);
50 // Xvalue.
52 int x = 42;
53 std::same_as<std::ranges::single_view<int>> decltype(auto) v = std::views::single(std::move(x));
54 assert(v.size() == 1);
55 assert(v.front() == x);
58 return true;
61 int main(int, char**) {
62 test();
63 static_assert(test());
65 return 0;