]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/25_algorithms/nth_element/moveable.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / nth_element / moveable.cc
CommitLineData
123c59a6 1// { dg-options "-std=gnu++11" }
5348e86a 2
f1717362 3// Copyright (C) 2005-2016 Free Software Foundation, Inc.
5348e86a 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
6bc9506f 8// Free Software Foundation; either version 3, or (at your option)
5348e86a 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
6bc9506f 17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
5348e86a 19
20// 25.3.2 [lib.alg.nth.element]
21
22#undef _GLIBCXX_CONCEPT_CHECKS
23
a8bcef69 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
5348e86a 28#include <algorithm>
29#include <testsuite_hooks.h>
30#include <testsuite_iterators.h>
31#include <testsuite_rvalref.h>
32
33using __gnu_test::test_container;
34using __gnu_test::random_access_iterator_wrapper;
35using std::nth_element;
36using __gnu_test::rvalstruct;
37
38typedef test_container<rvalstruct, random_access_iterator_wrapper> Container;
39
40void
41test1()
42{
18dddd09 43 bool test __attribute__((unused)) = true;
44
5348e86a 45 int intarray[] = {6, 5, 4, 3, 2, 1, 0};
46 rvalstruct array[7];
47 std::copy(intarray, intarray + 7, array);
48 Container con(array, array + 7);
49 nth_element(con.begin(), con.it(3), con.end());
50 for(int i = 0; i < 3; ++i)
18dddd09 51 VERIFY( array[i].val < 3 );
5348e86a 52 for(int i = 4; i < 7; ++i)
18dddd09 53 VERIFY( array[i].val > 3 );
5348e86a 54 for(int i = 0; i < 7; ++i)
18dddd09 55 VERIFY( array[i].valid );
5348e86a 56}
57
58void
59test2()
60{
18dddd09 61 bool test __attribute__((unused)) = true;
62
5348e86a 63 int intarray[] = {0, 6, 1, 5, 2, 4, 3};
64 rvalstruct array[7];
65 std::copy(intarray, intarray + 7, array);
66 Container con(array,array + 7);
67 nth_element(con.begin(), con.it(3), con.end());
68 for(int i = 0; i < 3; ++i)
18dddd09 69 VERIFY( array[i].val < 3 );
70 for(int i = 4; i < 7; ++i)
71 VERIFY( array[i].val > 3 );
72 for(int i = 0; i < 7; ++i)
73 VERIFY( array[i].valid );
74}
75
76bool
77are_less(const rvalstruct& lhs, const rvalstruct& rhs)
78{ return lhs < rhs; }
79
80void
81test3()
82{
83 bool test __attribute__((unused)) = true;
84
85 int intarray[] = {0, 6, 1, 5, 2, 4, 3};
86 rvalstruct array[7];
87 std::copy(intarray, intarray + 7, array);
88 Container con(array,array + 7);
89 nth_element(con.begin(), con.it(3), con.end(), are_less);
90 for(int i = 0; i < 3; ++i)
91 VERIFY( array[i].val < 3 );
5348e86a 92 for(int i = 4; i < 7; ++i)
18dddd09 93 VERIFY( array[i].val > 3 );
5348e86a 94 for(int i = 0; i < 7; ++i)
18dddd09 95 VERIFY( array[i].valid );
5348e86a 96}
97
98int
99main()
100{
101 test1();
102 test2();
18dddd09 103 test3();
5348e86a 104 return 0;
105}