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_container
;
25 using __gnu_test::test_range
;
26 using __gnu_test::input_iterator_wrapper
;
27 using __gnu_test::forward_iterator_wrapper
;
29 namespace ranges
= std::ranges
;
36 operator==(const X
& a
, const X
& b
)
46 X x
[6] = { {2}, {2}, {6}, {8}, {10}, {11} };
47 X y
[6] = { {2}, {2}, {6}, {9}, {10}, {11} };
48 auto res
= ranges::replace(x
, x
+5, 8, X
{9}, &X::i
);
50 VERIFY( ranges::equal(x
, y
) );
54 X x
[6] = { {2}, {2}, {6}, {8}, {10}, {11} };
55 X y
[6] = { {2}, {2}, {6}, {8}, {10}, {11} };
56 auto res
= ranges::replace(x
, x
+5, 7, X
{9}, &X::i
);
58 VERIFY( ranges::equal(x
, y
) );
62 X x
[6] = { {2}, {2}, {6}, {8}, {10}, {11} };
63 X y
[6] = { {7}, {7}, {6}, {8}, {10}, {11} };
64 test_container
<X
, forward_iterator_wrapper
> cx(x
), cy(y
);
65 auto res
= ranges::replace(cx
, 2, X
{7}, &X::i
);
66 VERIFY( res
== cx
.end() );
67 VERIFY( ranges::equal(cx
, cy
) );
71 int x
[6] = { {2}, {2}, {6}, {8}, {10}, {2} };
72 int y
[6] = { {7}, {7}, {6}, {8}, {10}, {7} };
73 test_range
<int, input_iterator_wrapper
> rx(x
), ry(y
);
74 auto res
= ranges::replace(rx
, 2, 7);
75 VERIFY( res
== rx
.end() );
79 VERIFY( ranges::equal(rx
, ry
) );
83 struct Y
{ int i
; int j
; };
89 Y x
[] = { {3,2}, {2,4}, {3,6} };
90 Y y
[] = { {4,5}, {2,4}, {4,5} };
91 auto res
= ranges::replace(x
, 3, Y
{4,5}, &Y::i
);
93 ok
&= ranges::equal(x
, y
, {}, &Y::i
, &Y::i
);
94 ok
&= ranges::equal(x
, y
, {}, &Y::j
, &Y::j
);
102 static_assert(test02());