summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/std/ranges/adaptors/as_rvalue/1.cc
blob: 8ca4f50e9d25c69194fec5af1c781da248b3e629 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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();
}