1 // Copyright (C) 2020-2025 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-do run { target c++20 } }
21 #include <testsuite_hooks.h>
22 #include <testsuite_iterators.h>
24 using __gnu_test::test_range
;
25 using __gnu_test::input_iterator_wrapper
;
26 using __gnu_test::output_iterator_wrapper
;
27 using __gnu_test::forward_iterator_wrapper
;
29 namespace ranges
= std::ranges
;
31 template<template<typename
> typename source_wrapper
,
32 template<typename
> typename dest_wrapper
>
36 int x
[6] = {0, 0, 0, 1, 1, 1};
38 const int z
[2] = {0, 1};
40 test_range
<int, source_wrapper
> rx(x
);
41 test_range
<int, dest_wrapper
> ry(y
);
42 auto [in
,out
] = ranges::unique_copy(rx
, ry
.begin());
43 VERIFY( in
== ranges::end(rx
) && out
== ranges::end(ry
) );
44 VERIFY( ranges::equal(y
, z
) );
47 template<template<typename
> typename source_wrapper
,
48 template<typename
> typename dest_wrapper
>
52 int x
[6] = {0, 0, 0, 1, 1, 1};
54 const int z
[2] = {0, 0};
56 test_range
<int, source_wrapper
> rx(x
, x
);
57 test_range
<int, dest_wrapper
> ry(y
, y
);
58 auto [in
, out
] = ranges::unique_copy(rx
.begin(), rx
.end(), ry
.begin());
59 VERIFY( in
.ptr
== x
&& out
.ptr
== y
);
60 VERIFY( ranges::equal(y
, z
) );
63 template<template<typename
> typename source_wrapper
,
64 template<typename
> typename dest_wrapper
>
69 X x
[6] = { {1}, {2}, {2}, {4}, {4}, {6} };
70 X y
[4] = { {1}, {2}, {4}, {6} };
71 const X z
[4] = { {1}, {2}, {4}, {6} };
73 test_range
<X
, source_wrapper
> rx(x
);
74 test_range
<X
, dest_wrapper
> ry(y
);
76 = ranges::unique_copy(rx
, ry
.begin(), ranges::equal_to
{}, &X::i
);
77 VERIFY( in
== ranges::end(rx
) && out
== ranges::end(ry
) );
78 VERIFY( ranges::equal(y
, z
, {}, &X::i
, &X::i
) );
85 X x
[7] = { {1}, {2}, {2}, {2}, {4}, {4}, {6} };
86 X y
[4] = { {1}, {2}, {4}, {6} };
87 const X z
[4] = { {1}, {2}, {4}, {6} };
90 = ranges::unique_copy(x
, x
+7, y
, ranges::equal_to
{}, &X::i
);
91 return (in
== ranges::end(x
)
92 && out
== ranges::end(y
)
93 && ranges::equal(y
, z
, {}, &X::i
, &X::i
));
99 test01
<input_iterator_wrapper
, output_iterator_wrapper
>();
100 test01
<input_iterator_wrapper
, forward_iterator_wrapper
>();
101 test01
<forward_iterator_wrapper
, output_iterator_wrapper
>();
103 test02
<input_iterator_wrapper
, output_iterator_wrapper
>();
104 test02
<input_iterator_wrapper
, forward_iterator_wrapper
>();
105 test02
<forward_iterator_wrapper
, output_iterator_wrapper
>();
107 test03
<input_iterator_wrapper
, output_iterator_wrapper
>();
108 test03
<input_iterator_wrapper
, forward_iterator_wrapper
>();
109 test03
<forward_iterator_wrapper
, output_iterator_wrapper
>();
111 static_assert(test04());