1 // { dg-require-rvalref "" }
2 // { dg-options "-std=gnu++0x" }
4 // Copyright (C) 2005, 2007 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 // 25.3.2 [lib.alg.nth.element]
24 #undef _GLIBCXX_CONCEPT_CHECKS
27 #include <testsuite_hooks.h>
28 #include <testsuite_iterators.h>
29 #include <testsuite_rvalref.h>
31 using __gnu_test::test_container
;
32 using __gnu_test::random_access_iterator_wrapper
;
33 using std::nth_element
;
34 using __gnu_test::rvalstruct
;
36 typedef test_container
<rvalstruct
, random_access_iterator_wrapper
> Container
;
41 int intarray
[] = {6, 5, 4, 3, 2, 1, 0};
43 std::copy(intarray
, intarray
+ 7, array
);
44 Container
con(array
, array
+ 7);
45 nth_element(con
.begin(), con
.it(3), con
.end());
46 for(int i
= 0; i
< 3; ++i
)
47 VERIFY(array
[i
].val
< 3);
48 for(int i
= 4; i
< 7; ++i
)
49 VERIFY(array
[i
].val
> 3);
50 for(int i
= 0; i
< 7; ++i
)
51 VERIFY(array
[i
].valid
);
57 int intarray
[] = {0, 6, 1, 5, 2, 4, 3};
59 std::copy(intarray
, intarray
+ 7, array
);
60 Container
con(array
,array
+ 7);
61 nth_element(con
.begin(), con
.it(3), con
.end());
62 for(int i
= 0; i
< 3; ++i
)
63 VERIFY(array
[i
].val
< 3);
64 for(int i
= 4; i
< 7; ++i
)
65 VERIFY(array
[i
].val
> 3);
66 for(int i
= 0; i
< 7; ++i
)
67 VERIFY(array
[i
].valid
);