//===----------------------------------------------------------------------===// // // 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 // constexpr V base() const & requires copy_constructible { return base_; } // constexpr V base() && { return std::move(base_); } #include #include #include #include "MoveOnly.h" struct SimpleView : std::ranges::view_base { int i; int* begin() const; int* end() const; }; struct MoveOnlyView : SimpleView { MoveOnly m; }; template concept HasBase = requires(T&& t) { std::forward(t).base(); }; static_assert(HasBase const&>); static_assert(HasBase&&>); static_assert(!HasBase const&>); static_assert(HasBase&&>); constexpr bool test() { { // const & const std::ranges::as_rvalue_view view(SimpleView{{}, 5}); std::same_as decltype(auto) v = view.base(); assert(v.i == 5); } { // & std::ranges::as_rvalue_view view(SimpleView{{}, 5}); std::same_as decltype(auto) v = view.base(); assert(v.i == 5); } { // && std::ranges::as_rvalue_view view(SimpleView{{}, 5}); std::same_as decltype(auto) v = std::move(view).base(); assert(v.i == 5); } { // const && const std::ranges::as_rvalue_view view(SimpleView{{}, 5}); std::same_as decltype(auto) v = std::move(view).base(); assert(v.i == 5); } { // move only std::ranges::as_rvalue_view view(MoveOnlyView{{}, 5}); std::same_as decltype(auto) v = std::move(view).base(); assert(v.m.get() == 5); } return true; } int main(int, char**) { test(); static_assert(test()); return 0; }