//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 // std::views::as_rvalue #include #include #include #include #include "test_iterators.h" struct DefaultConstructibleView : std::ranges::view_base { int i_; int* begin(); int* end(); }; struct RValueView : std::ranges::view_base {}; template concept HasPipe = requires(View&& view, T&& t) { { std::forward(view) | std::forward(t) }; }; struct NoView {}; static_assert(std::is_invocable_v); static_assert(!std::is_invocable_v); static_assert(!std::is_invocable_v); static_assert(HasPipe); static_assert(HasPipe); static_assert(!HasPipe); static_assert(!HasPipe); static_assert(std::is_same_v); struct move_iterator_range { constexpr std::move_iterator begin() const { return {}; } constexpr std::move_iterator end() const { return {}; } }; static_assert(!std::ranges::view); static_assert(std::ranges::range); constexpr bool test() { { // view | views::as_rvalue DefaultConstructibleView v{{}, 3}; std::same_as> decltype(auto) view = v | std::views::as_rvalue; assert(view.base().i_ == 3); } { // adaptor | views::as_rvalue DefaultConstructibleView v{{}, 3}; const auto partial = std::views::transform(std::identity{}) | std::views::as_rvalue; std::same_as>> decltype(auto) view = partial(v); assert(view.base().base().i_ == 3); } { // views::as_rvalue | adaptor DefaultConstructibleView v{{}, 3}; const auto partial = std::views::as_rvalue | std::views::transform(std::identity{}); std::same_as, std::identity>> decltype(auto) view = partial(v); assert(view.base().base().i_ == 3); } { // rvalue-view | views::as_rvalue int a[4] = {1, 2, 3, 4}; std::ranges::subrange range(rvalue_iterator{a}, rvalue_iterator{a + 4}); [[maybe_unused]] std::same_as>> decltype(auto) rval_range = range | std::views::as_rvalue; } { // range | views::as_rvalue [[maybe_unused]] std::same_as>>> decltype(auto) view = std::vector{} | std::views::as_rvalue; } { // rvalue-range | views::as_rvalue [[maybe_unused]] std::same_as> decltype(auto) view = move_iterator_range{} | std::views::as_rvalue; } return true; } int main(int, char**) { test(); static_assert(test()); return 0; }