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