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//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10
11// std::ranges::as_rvalue_view::as_rvalue_view(...)
12
13#include <cassert>
14#include <ranges>
15#include <type_traits>
16#include <utility>
17#include <vector>
18
19struct DefaultConstructibleView : std::ranges::view_base {
20 int* begin() const;
21 int* end() const;
22
23 int i_ = 23;
24};
25
26struct NonDefaultConstructibleView : std::ranges::view_base {
27 NonDefaultConstructibleView(int i) : i_(i) {}
28
29 int* begin() const;
30 int* end() const;
31
32 int i_ = 23;
33};
34
35static_assert(!std::is_constructible_v<std::ranges::as_rvalue_view<NonDefaultConstructibleView>>);
36static_assert(std::is_constructible_v<std::ranges::as_rvalue_view<NonDefaultConstructibleView>, int>);
37static_assert(std::is_nothrow_constructible_v<std::ranges::as_rvalue_view<DefaultConstructibleView>>);
38
39template <class T, class... Args>
40concept IsImplicitlyConstructible = requires(T val, Args... args) { val = {std::forward<Args>(args)...}; };
41
42static_assert(IsImplicitlyConstructible<std::ranges::as_rvalue_view<DefaultConstructibleView>>);
43static_assert(!IsImplicitlyConstructible<std::ranges::as_rvalue_view<NonDefaultConstructibleView>, int>);
44
45constexpr bool test() {
46 std::ranges::as_rvalue_view<DefaultConstructibleView> view = {};
47 assert(view.base().i_ == 23);
48
49 return true;
50}
51
52int main(int, char**) {
53 static_assert(test());
54 test();
55
56 return 0;
57}
58

source code of libcxx/test/std/ranges/range.adaptors/range.as.rvalue/ctor.pass.cpp