1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // template<RandomAccessIterator Iter, StrictWeakOrder<auto, Iter::value_type> Compare>
13 // requires ShuffleIterator<Iter>
14 // && CopyConstructible<Compare>
16 // nth_element(Iter first, Iter nth, Iter last, Compare comp);
22 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
28 bool operator()(const P& x, const P& y)
32 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
35 test_one(unsigned N, unsigned M)
39 int* array = new int[N];
40 for (int i = 0; i < N; ++i)
42 std::random_shuffle(array, array+N);
43 std::nth_element(array, array+M, array+N, std::greater<int>());
44 assert(array[M] == N-M-1);
66 std::nth_element(&d, &d, &d);
76 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
78 std::vector<std::unique_ptr<int> > v(1000);
79 for (int i = 0; i < v.size(); ++i)
80 v[i].reset(new int(i));
81 std::nth_element(v.begin(), v.begin() + v.size()/2, v.end(), indirect_less());
82 assert(*v[v.size()/2] == v.size()/2);
84 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES