67 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 11// std::views::single12 13#include <ranges>14 15#include <cassert>16#include <concepts>17#include <utility>18#include "MoveOnly.h"19 20// Can't invoke without arguments.21static_assert(!std::is_invocable_v<decltype((std::views::single))>);22#if _LIBCPP_STD_VER >= 2323// Can invoke with a move-only type.24static_assert(std::is_invocable_v<decltype((std::views::single)), MoveOnly>);25#endif26constexpr bool test() {27 // Lvalue.28 {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);33 }34 35 // Prvalue.36 {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);40 }41 42 // Const lvalue.43 {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);48 }49 50 // Xvalue.51 {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);56 }57 58 return true;59}60 61int main(int, char**) {62 test();63 static_assert(test());64 65 return 0;66}67