diff options
author | Patrick Palka <ppalka@redhat.com> | 2022-11-07 13:29:42 -0500 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2022-11-07 13:29:42 -0500 |
commit | 2ee0165f72be96083deaa8fd315bcfed011acd52 (patch) | |
tree | 645f25b7ba7193d94eac43ce3c58c4a85528b1c0 /libstdc++-v3/testsuite/std | |
parent | f471cb71c86c1e7a3dead324142bdf880f00a3da (diff) | |
download | gcc-2ee0165f72be96083deaa8fd315bcfed011acd52.tar.gz |
libstdc++: Implement ranges::as_rvalue_view from P2446R2
libstdc++-v3/ChangeLog:
* include/std/ranges (as_rvalue_view): Define.
(enable_borrowed_range<as_rvalue_view>): Define.
(views::__detail::__can_as_rvalue_view): Define.
(views::_AsRvalue, views::as_rvalue): Define.
* testsuite/std/ranges/adaptors/as_rvalue/1.cc: New test.
Diffstat (limited to 'libstdc++-v3/testsuite/std')
-rw-r--r-- | libstdc++-v3/testsuite/std/ranges/adaptors/as_rvalue/1.cc | 47 |
1 files changed, 47 insertions, 0 deletions
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 <ranges> +#include <algorithm> +#include <memory> +#include <testsuite_hooks.h> +#include <testsuite_iterators.h> + +namespace ranges = std::ranges; +namespace views = std::views; + +constexpr bool +test01() +{ + + std::unique_ptr<int> a[3] = { std::make_unique<int>(1), + std::make_unique<int>(2), + std::make_unique<int>(3) }; + std::unique_ptr<int> 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<int> x = std::make_unique<int>(42); + std::unique_ptr<int> y; + __gnu_test::test_input_range rx(&x, &x+1); + auto v = rx | views::as_rvalue; + static_assert(!ranges::common_range<decltype(v)>); + ranges::copy(v, &y); + VERIFY( x.get() == nullptr ); + VERIFY( *y == 42 ); +} + +int +main() +{ + static_assert(test01()); + test02(); +} |