i386: Allow all register_operand SUBREGs in x86_ternlog_idx.
[official-gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / nth_element / 2.cc
blobba7db905842b9754276f2083409bf759aa8383d6
1 // Copyright (C) 2006-2024 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // 25.3.2 [lib.alg.nth.element]
20 // { dg-options "-DMAX_SIZE=256" { target simulator } }
22 #ifndef MAX_SIZE
23 #define MAX_SIZE (1 << 10)
24 #endif
26 #include <vector>
27 #include <algorithm>
28 #include <testsuite_hooks.h>
30 void
31 test_set(std::vector<unsigned>& v, unsigned size)
33 v.clear();
35 for (unsigned i = 0; i < size; i += 4)
37 v.push_back(i / 2);
38 v.push_back((size - 2) - (i / 2));
40 for (unsigned i = 1; i < size; i += 2)
41 v.push_back(i);
44 void
45 do_test01(unsigned size)
47 std::vector<unsigned> v, s;
49 for (unsigned j = 0; j < size; ++j)
51 test_set(v, size);
52 s = v;
53 std::sort(s.begin(), s.end());
55 std::nth_element(v.begin(), v.begin() + j, v.end());
57 VERIFY( v[j] == s[j] );
59 for (unsigned i = 0; i < j; ++i)
60 VERIFY( !(v[j] < v[i]) );
62 for (unsigned i = j; i < v.size(); ++i)
63 VERIFY( !(v[i] < v[j]) );
67 void
68 test01()
70 for (unsigned size = 4; size <= MAX_SIZE; size <<= 1)
71 do_test01(size);
74 int main()
76 test01();
77 return 0;