]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/containers/sequences/forwardlist/forwardlist.ops/sort_pred.pass.cpp
Vendor import of libc++ trunk r300422:
[FreeBSD/FreeBSD.git] / test / std / containers / sequences / forwardlist / forwardlist.ops / sort_pred.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <forward_list>
11
12 // template <class Compare> void sort(Compare comp);
13
14 #include <forward_list>
15 #include <iterator>
16 #include <algorithm>
17 #include <vector>
18 #include <functional>
19 #include <random>
20 #include <cassert>
21
22 #include "min_allocator.h"
23
24 std::mt19937 randomness;
25
26 template <class C>
27 void test(int N)
28 {
29     typedef typename C::value_type T;
30     typedef std::vector<T> V;
31     V v;
32     for (int i = 0; i < N; ++i)
33         v.push_back(i);
34     std::shuffle(v.begin(), v.end(), randomness);
35     C c(v.begin(), v.end());
36     c.sort(std::greater<T>());
37     assert(distance(c.begin(), c.end()) == N);
38     typename C::const_iterator j = c.begin();
39     for (int i = 0; i < N; ++i, ++j)
40         assert(*j == N-1-i);
41 }
42
43 int main()
44 {
45     for (int i = 0; i < 40; ++i)
46         test<std::forward_list<int> >(i);
47 #if TEST_STD_VER >= 11
48     for (int i = 0; i < 40; ++i)
49         test<std::forward_list<int, min_allocator<int>> >(i);
50 #endif
51 }