Merge -r 127928:132243 from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / nth_element / moveable.cc
blobc521d382b2f603e6765dbc30276854021c7f281d
1 // { dg-require-rvalref "" }
2 // { dg-options "-std=gnu++0x" }
4 // Copyright (C) 2005, 2007 Free Software Foundation, Inc.
5 //
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)
10 // any later version.
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,
20 // USA.
22 // 25.3.2 [lib.alg.nth.element]
24 #undef _GLIBCXX_CONCEPT_CHECKS
26 #include <algorithm>
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;
38 void
39 test1()
41 int intarray[] = {6, 5, 4, 3, 2, 1, 0};
42 rvalstruct array[7];
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);
54 void
55 test2()
57 int intarray[] = {0, 6, 1, 5, 2, 4, 3};
58 rvalstruct array[7];
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);
70 int
71 main()
73 test1();
74 test2();
75 return 0;