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 <cassert>
19 
20 #include "min_allocator.h"
21 
22 template <class C>
test(int N)23 void test(int N)
24 {
25     typedef typename C::value_type T;
26     typedef std::vector<T> V;
27     V v;
28     for (int i = 0; i < N; ++i)
29         v.push_back(i);
30     std::random_shuffle(v.begin(), v.end());
31     C c(v.begin(), v.end());
32     c.sort();
33     assert(distance(c.begin(), c.end()) == N);
34     typename C::const_iterator j = c.begin();
35     for (int i = 0; i < N; ++i, ++j)
36         assert(*j == i);
37 }
38 
main()39 int main()
40 {
41     for (int i = 0; i < 40; ++i)
42         test<std::forward_list<int> >(i);
43 #if __cplusplus >= 201103L
44     for (int i = 0; i < 40; ++i)
45         test<std::forward_list<int, min_allocator<int>> >(i);
46 #endif
47 }
48