]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/sort/moveable.cc
testsuite_rvalref.h: Remove obsolete macro using _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALI...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / sort / moveable.cc
1 // { dg-options "-std=gnu++0x" }
2
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
10
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.
15
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/>.
19
20 // 25.3.1 algorithms, sort()
21
22 #undef _GLIBCXX_CONCEPT_CHECKS
23
24 #include <algorithm>
25 #include <testsuite_hooks.h>
26 #include <testsuite_iterators.h>
27 #include <testsuite_rvalref.h>
28
29 using __gnu_test::test_container;
30 using __gnu_test::random_access_iterator_wrapper;
31 using __gnu_test::rvalstruct;
32 using std::partial_sort;
33
34 typedef test_container<rvalstruct, random_access_iterator_wrapper> Container;
35
36 const int A[] = {10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7,
37 17, 8, 18, 9, 19};
38 const int N = sizeof(A) / sizeof(int);
39
40 // 25.3.1.1 sort()
41 void
42 test01()
43 {
44 bool test __attribute__((unused)) = true;
45
46 rvalstruct s1[N];
47 std::copy(A, A + N, s1);
48 Container con(s1, s1 + N);
49 std::sort(con.begin(), con.end());
50 VERIFY( s1[0].valid );
51 for(int i = 1; i < N; ++i)
52 VERIFY( s1[i].val>s1[i-1].val && s1[i].valid );
53 }
54
55 bool order(const rvalstruct& lhs, const rvalstruct& rhs)
56 { return lhs < rhs; }
57
58 // 25.3.1.1 sort()
59 void
60 test02()
61 {
62 bool test __attribute__((unused)) = true;
63
64 rvalstruct s1[N];
65 std::copy(A, A + N, s1);
66 Container con(s1, s1 + N);
67 std::sort(con.begin(), con.end(), order);
68 VERIFY( s1[0].valid );
69 for(int i = 1; i < N; ++i)
70 VERIFY( s1[i].val>s1[i-1].val && s1[i].valid );
71 }
72
73 int
74 main()
75 {
76 test01();
77 test02();
78 return 0;
79 }