1 // Copyright (C) 2020-2021 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
22 #include <testsuite_hooks.h>
23 #include <testsuite_iterators.h>
25 using __gnu_test::test_range
;
26 using __gnu_test::input_iterator_wrapper
;
27 using __gnu_test::output_iterator_wrapper
;
28 using __gnu_test::forward_iterator_wrapper
;
30 namespace ranges
= std::ranges
;
32 template<template<typename
> typename source_wrapper
,
33 template<typename
> typename dest_wrapper
>
37 int x
[6] = {0, 0, 0, 1, 1, 1};
39 const int z
[2] = {0, 1};
41 test_range
<int, source_wrapper
> rx(x
);
42 test_range
<int, dest_wrapper
> ry(y
);
43 auto [in
,out
] = ranges::unique_copy(rx
, ry
.begin());
44 VERIFY( in
== ranges::end(rx
) && out
== ranges::end(ry
) );
45 VERIFY( ranges::equal(y
, z
) );
48 template<template<typename
> typename source_wrapper
,
49 template<typename
> typename dest_wrapper
>
53 int x
[6] = {0, 0, 0, 1, 1, 1};
55 const int z
[2] = {0, 0};
57 test_range
<int, source_wrapper
> rx(x
, x
);
58 test_range
<int, dest_wrapper
> ry(y
, y
);
59 auto [in
, out
] = ranges::unique_copy(rx
.begin(), rx
.end(), ry
.begin());
60 VERIFY( in
.ptr
== x
&& out
.ptr
== y
);
61 VERIFY( ranges::equal(y
, z
) );
64 template<template<typename
> typename source_wrapper
,
65 template<typename
> typename dest_wrapper
>
70 X x
[6] = { {1}, {2}, {2}, {4}, {4}, {6} };
71 X y
[4] = { {1}, {2}, {4}, {6} };
72 const X z
[4] = { {1}, {2}, {4}, {6} };
74 test_range
<X
, source_wrapper
> rx(x
);
75 test_range
<X
, dest_wrapper
> ry(y
);
77 = ranges::unique_copy(rx
, ry
.begin(), ranges::equal_to
{}, &X::i
);
78 VERIFY( in
== ranges::end(rx
) && out
== ranges::end(ry
) );
79 VERIFY( ranges::equal(y
, z
, {}, &X::i
, &X::i
) );
86 X x
[7] = { {1}, {2}, {2}, {2}, {4}, {4}, {6} };
87 X y
[4] = { {1}, {2}, {4}, {6} };
88 const X z
[4] = { {1}, {2}, {4}, {6} };
91 = ranges::unique_copy(x
, x
+7, y
, ranges::equal_to
{}, &X::i
);
92 return (in
== ranges::end(x
)
93 && out
== ranges::end(y
)
94 && ranges::equal(y
, z
, {}, &X::i
, &X::i
));
100 test01
<input_iterator_wrapper
, output_iterator_wrapper
>();
101 test01
<input_iterator_wrapper
, forward_iterator_wrapper
>();
102 test01
<forward_iterator_wrapper
, output_iterator_wrapper
>();
104 test02
<input_iterator_wrapper
, output_iterator_wrapper
>();
105 test02
<input_iterator_wrapper
, forward_iterator_wrapper
>();
106 test02
<forward_iterator_wrapper
, output_iterator_wrapper
>();
108 test03
<input_iterator_wrapper
, output_iterator_wrapper
>();
109 test03
<input_iterator_wrapper
, forward_iterator_wrapper
>();
110 test03
<forward_iterator_wrapper
, output_iterator_wrapper
>();
112 static_assert(test04());