]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/containers/sequences/forwardlist/forwardlist.ops/sort.pass.cpp
Vendor import of libc++ trunk r300422:
[FreeBSD/FreeBSD.git] / test / std / containers / sequences / forwardlist / forwardlist.ops / sort.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 // void sort();
13
14 #include <forward_list>
15 #include <iterator>
16 #include <algorithm>
17 #include <vector>
18 #include <random>
19 #include <cassert>
20
21 #include "min_allocator.h"
22
23 std::mt19937 randomness;
24
25 template <class C>
26 void test(int N)
27 {
28     typedef typename C::value_type T;
29     typedef std::vector<T> V;
30     V v;
31     for (int i = 0; i < N; ++i)
32         v.push_back(i);
33     std::shuffle(v.begin(), v.end(), randomness);
34     C c(v.begin(), v.end());
35     c.sort();
36     assert(distance(c.begin(), c.end()) == N);
37     typename C::const_iterator j = c.begin();
38     for (int i = 0; i < N; ++i, ++j)
39         assert(*j == i);
40 }
41
42 int main()
43 {
44     for (int i = 0; i < 40; ++i)
45         test<std::forward_list<int> >(i);
46 #if TEST_STD_VER >= 11
47     for (int i = 0; i < 40; ++i)
48         test<std::forward_list<int, min_allocator<int>> >(i);
49 #endif
50 }