]>
gcc.gnu.org Git - gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/replace_if/constrained.cc
1 // Copyright (C) 2020 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_container
;
26 using __gnu_test::test_range
;
27 using __gnu_test::input_iterator_wrapper
;
28 using __gnu_test::forward_iterator_wrapper
;
30 namespace ranges
= std::ranges
;
37 operator==(const X
& a
, const X
& b
)
46 auto is_even_p
= [] (int a
) { return a
%2 == 0; };
47 auto is_negative_p
= [] (int a
) { return a
< 0; };
48 auto is_two_p
= [] (int a
) { return a
== 2; };
50 X x
[6] = { {1}, {2}, {6}, {8}, {10}, {11} };
51 X y
[6] = { {1}, {9}, {9}, {9}, {9}, {11} };
52 auto res
= ranges::replace_if(x
, x
+5, is_even_p
, X
{9}, &X::i
);
54 VERIFY( ranges::equal(x
, y
) );
58 X x
[6] = { {2}, {2}, {6}, {8}, {10}, {11} };
59 X y
[6] = { {2}, {2}, {6}, {8}, {10}, {11} };
60 auto res
= ranges::replace_if(x
, x
+5, is_negative_p
, X
{9}, &X::i
);
62 VERIFY( ranges::equal(x
, y
) );
66 X x
[6] = { {2}, {2}, {6}, {8}, {10}, {11} };
67 X y
[6] = { {7}, {7}, {6}, {8}, {10}, {11} };
68 test_container
<X
, forward_iterator_wrapper
> cx(x
), cy(y
);
69 auto res
= ranges::replace_if(cx
, is_two_p
, X
{7}, &X::i
);
70 VERIFY( res
== cx
.end() );
71 VERIFY( ranges::equal(cx
, cy
) );
75 int x
[6] = { {2}, {2}, {6}, {8}, {10}, {2} };
76 int y
[6] = { {7}, {7}, {6}, {8}, {10}, {7} };
77 test_range
<int, input_iterator_wrapper
> rx(x
), ry(y
);
78 auto res
= ranges::replace_if(rx
, is_two_p
, 7);
79 VERIFY( res
== rx
.end() );
83 VERIFY( ranges::equal(rx
, ry
) );
87 struct Y
{ int i
; int j
; };
93 Y x
[] = { {3,2}, {2,4}, {3,6} };
94 Y y
[] = { {4,5}, {2,4}, {4,5} };
95 auto res
= ranges::replace_if(x
, [] (int a
) { return a
%2 == 1; },
98 ok
&= ranges::equal(x
, y
, {}, &Y::i
, &Y::i
);
99 ok
&= ranges::equal(x
, y
, {}, &Y::j
, &Y::j
);
107 static_assert(test02());
This page took 0.041676 seconds and 5 git commands to generate.