From 2ee0165f72be96083deaa8fd315bcfed011acd52 Mon Sep 17 00:00:00 2001 From: Patrick Palka Date: Mon, 7 Nov 2022 13:29:42 -0500 Subject: libstdc++: Implement ranges::as_rvalue_view from P2446R2 libstdc++-v3/ChangeLog: * include/std/ranges (as_rvalue_view): Define. (enable_borrowed_range): Define. (views::__detail::__can_as_rvalue_view): Define. (views::_AsRvalue, views::as_rvalue): Define. * testsuite/std/ranges/adaptors/as_rvalue/1.cc: New test. --- .../testsuite/std/ranges/adaptors/as_rvalue/1.cc | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 libstdc++-v3/testsuite/std/ranges/adaptors/as_rvalue/1.cc (limited to 'libstdc++-v3/testsuite/std') diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/as_rvalue/1.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/as_rvalue/1.cc new file mode 100644 index 00000000000..8ca4f50e9d2 --- /dev/null +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/as_rvalue/1.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++23" } +// { dg-do run { target c++23 } } + +#include +#include +#include +#include +#include + +namespace ranges = std::ranges; +namespace views = std::views; + +constexpr bool +test01() +{ + + std::unique_ptr a[3] = { std::make_unique(1), + std::make_unique(2), + std::make_unique(3) }; + std::unique_ptr b[3]; + auto v = a | views::as_rvalue; + ranges::copy(v, b); + VERIFY( ranges::all_of(a, [](auto& p) { return p.get() == nullptr; }) ); + VERIFY( ranges::equal(b | views::transform([](auto& p) { return *p; }), (int[]){1, 2, 3}) ); + + return true; +} + +void +test02() +{ + std::unique_ptr x = std::make_unique(42); + std::unique_ptr y; + __gnu_test::test_input_range rx(&x, &x+1); + auto v = rx | views::as_rvalue; + static_assert(!ranges::common_range); + ranges::copy(v, &y); + VERIFY( x.get() == nullptr ); + VERIFY( *y == 42 ); +} + +int +main() +{ + static_assert(test01()); + test02(); +} -- cgit v1.2.1