c++: Fix ICE with #embed/RAW_DATA_CST after list conversion [PR118671]
[gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / replace / constrained.cc
blob85c969a82217df5488a038fa6c9aa3043b6d8cf5
1 // Copyright (C) 2020-2025 Free Software Foundation, Inc.
2 //
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)
7 // any later version.
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 } }
20 #include <algorithm>
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;
31 struct X
33 int i;
35 friend constexpr bool
36 operator==(const X& a, const X& b)
38 return a.i == b.i;
42 void
43 test01()
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);
49 VERIFY( res == x+5 );
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);
57 VERIFY( res == x+5 );
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() );
77 rx.bounds.first = x;
78 ry.bounds.first = y;
79 VERIFY( ranges::equal(rx, ry) );
83 struct Y { int i; int j; };
85 constexpr bool
86 test02()
88 bool ok = true;
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);
92 ok &= res == x+3;
93 ok &= ranges::equal(x, y, {}, &Y::i, &Y::i);
94 ok &= ranges::equal(x, y, {}, &Y::j, &Y::j);
95 return ok;
98 int
99 main()
101 test01();
102 static_assert(test02());