reverse.pass.cpp revision 06086258d3d8c48a916ec51c33e1ad8f46821b81
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 reverse();
13
14#include <forward_list>
15#include <iterator>
16#include <algorithm>
17#include <cassert>
18
19#include "min_allocator.h"
20
21template <class C>
22void test(int N)
23{
24    C c;
25    for (int i = 0; i < N; ++i)
26        c.push_front(i);
27    c.reverse();
28    assert(distance(c.begin(), c.end()) == N);
29    typename C::const_iterator j = c.begin();
30    for (int i = 0; i < N; ++i, ++j)
31        assert(*j == i);
32}
33
34int main()
35{
36    for (int i = 0; i < 10; ++i)
37        test<std::forward_list<int> >(i);
38#if __cplusplus >= 201103L
39    for (int i = 0; i < 10; ++i)
40        test<std::forward_list<int, min_allocator<int>> >(i);
41#endif
42}
43