]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/25_algorithms/sort/moveable.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / sort / moveable.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
f5783e34 2
7adcbafe 3// Copyright (C) 2005-2022 Free Software Foundation, Inc.
f5783e34
CJ
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
f5783e34
CJ
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
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
f5783e34
CJ
19
20// 25.3.1 algorithms, sort()
21
22#undef _GLIBCXX_CONCEPT_CHECKS
f5783e34 23
932f6f4a
PC
24// XXX FIXME: parallel-mode should deal correctly with moveable-only types
25// per C++0x, at minimum smoothly fall back to serial.
26#undef _GLIBCXX_PARALLEL
27
f5783e34
CJ
28#include <algorithm>
29#include <testsuite_hooks.h>
30#include <testsuite_iterators.h>
31#include <testsuite_rvalref.h>
32
f5783e34
CJ
33using __gnu_test::test_container;
34using __gnu_test::random_access_iterator_wrapper;
35using __gnu_test::rvalstruct;
36using std::partial_sort;
37
38typedef test_container<rvalstruct, random_access_iterator_wrapper> Container;
39
f5783e34 40const int A[] = {10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7,
01bbe151 41 17, 8, 18, 9, 19};
f5783e34
CJ
42const int N = sizeof(A) / sizeof(int);
43
44// 25.3.1.1 sort()
45void
46test01()
47{
01bbe151
CJ
48 rvalstruct s1[N];
49 std::copy(A, A + N, s1);
50 Container con(s1, s1 + N);
51 std::sort(con.begin(), con.end());
52 VERIFY( s1[0].valid );
53 for(int i = 1; i < N; ++i)
54 VERIFY( s1[i].val>s1[i-1].val && s1[i].valid );
55}
56
57bool order(const rvalstruct& lhs, const rvalstruct& rhs)
58{ return lhs < rhs; }
59
60// 25.3.1.1 sort()
61void
62test02()
63{
01bbe151
CJ
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 );
f5783e34
CJ
71}
72
73int
74main()
75{
76 test01();
01bbe151 77 test02();
f5783e34
CJ
78 return 0;
79}