1 // { dg-do run { target c++11 } }
3 // Copyright (C) 2005-2023 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 25.2.12 [lib.alg.partitions] Partitions.
22 #undef _GLIBCXX_CONCEPT_CHECKS
26 #include <testsuite_hooks.h>
27 #include <testsuite_rvalref.h>
28 #include <testsuite_iterators.h>
30 using __gnu_test::test_container
;
31 using __gnu_test::forward_iterator_wrapper
;
32 using __gnu_test::bidirectional_iterator_wrapper
;
33 using __gnu_test::rvalstruct
;
35 typedef test_container
<rvalstruct
, forward_iterator_wrapper
> Fcontainer
;
36 typedef test_container
<rvalstruct
, bidirectional_iterator_wrapper
> Bcontainer
;
38 const int A
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
39 const int B
[] = {2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17};
40 const int N
= sizeof(A
) / sizeof(int);
45 operator()(const rvalstruct
& x
) const
46 { return (x
.val
% 2) == 0; }
49 // 25.2.12 partition()
58 std::copy(A
, A
+ N
, farray
);
59 std::copy(A
, A
+ N
, barray
);
61 Fcontainer
fcon(farray
, farray
+ N
);
62 Bcontainer
bcon(barray
, barray
+ N
);
66 VERIFY(partition(fcon
.begin(), fcon
.end(), pred
).ptr
- farray
== N
/2);
67 for (const rvalstruct
* i
= farray
; i
< farray
+N
/2; ++i
)
70 for (const rvalstruct
* i
= farray
+N
/2; i
< farray
+ N
; ++i
)
73 VERIFY(partition(bcon
.begin(), bcon
.end(), pred
).ptr
- barray
== N
/2);
75 for (const rvalstruct
* i
= barray
; i
< barray
+N
/2; ++i
)
77 for (const rvalstruct
* i
= barray
+N
/2; i
< barray
+ N
; ++i
)