blob: e8a6c18fd49ac79a565f34ccfced94122f5b4117 [file] [log] [blame]
Marshall Clow1e548c72013-08-30 01:17:07 +00001//===----------------------------------------------------------------------===//
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// <iterator>
11// template <class C> auto begin(C& c) -> decltype(c.begin());
12// template <class C> auto begin(const C& c) -> decltype(c.begin());
13// template <class C> auto end(C& c) -> decltype(c.end());
14// template <class C> auto end(const C& c) -> decltype(c.end());
15// template <class E> reverse_iterator<const E*> rbegin(initializer_list<E> il);
16// template <class E> reverse_iterator<const E*> rend(initializer_list<E> il);
17
18#include <__config>
19
20#if __cplusplus >= 201103L
21#include <iterator>
22#include <cassert>
23#include <vector>
24#include <array>
25#include <list>
26#include <initializer_list>
27
28template<typename C>
29void test_const_container( const C & c, typename C::value_type val ) {
30 assert ( std::begin(c) == c.begin());
31 assert (*std::begin(c) == val );
32 assert ( std::begin(c) != c.end());
33 assert ( std::end(c) == c.end());
34#if _LIBCPP_STD_VER > 11
35 assert ( std::cbegin(c) == c.cbegin());
36 assert ( std::cbegin(c) != c.cend());
37 assert ( std::cend(c) == c.cend());
38 assert ( std::rbegin(c) == c.rbegin());
39 assert ( std::rbegin(c) != c.rend());
40 assert ( std::rend(c) == c.rend());
41 assert ( std::crbegin(c) == c.crbegin());
42 assert ( std::crbegin(c) != c.crend());
43 assert ( std::crend(c) == c.crend());
44#endif
45 }
46
47template<typename T>
48void test_const_container( const std::initializer_list<T> & c, T val ) {
49 assert ( std::begin(c) == c.begin());
50 assert (*std::begin(c) == val );
51 assert ( std::begin(c) != c.end());
52 assert ( std::end(c) == c.end());
53#if _LIBCPP_STD_VER > 11
54// initializer_list doesn't have cbegin/cend/rbegin/rend
55// assert ( std::cbegin(c) == c.cbegin());
56// assert ( std::cbegin(c) != c.cend());
57// assert ( std::cend(c) == c.cend());
58// assert ( std::rbegin(c) == c.rbegin());
59// assert ( std::rbegin(c) != c.rend());
60// assert ( std::rend(c) == c.rend());
61// assert ( std::crbegin(c) == c.crbegin());
62// assert ( std::crbegin(c) != c.crend());
63// assert ( std::crend(c) == c.crend());
64#endif
65 }
66
67template<typename C>
68void test_container( C & c, typename C::value_type val ) {
69 assert ( std::begin(c) == c.begin());
70 assert (*std::begin(c) == val );
71 assert ( std::begin(c) != c.end());
72 assert ( std::end(c) == c.end());
73#if _LIBCPP_STD_VER > 11
74 assert ( std::cbegin(c) == c.cbegin());
75 assert ( std::cbegin(c) != c.cend());
76 assert ( std::cend(c) == c.cend());
77 assert ( std::rbegin(c) == c.rbegin());
78 assert ( std::rbegin(c) != c.rend());
79 assert ( std::rend(c) == c.rend());
80 assert ( std::crbegin(c) == c.crbegin());
81 assert ( std::crbegin(c) != c.crend());
82 assert ( std::crend(c) == c.crend());
83#endif
84 }
85
86template<typename T>
87void test_container( std::initializer_list<T> & c, T val ) {
88 assert ( std::begin(c) == c.begin());
89 assert (*std::begin(c) == val );
90 assert ( std::begin(c) != c.end());
91 assert ( std::end(c) == c.end());
92#if _LIBCPP_STD_VER > 11
93// initializer_list doesn't have cbegin/cend/rbegin/rend
94// assert ( std::cbegin(c) == c.cbegin());
95// assert ( std::cbegin(c) != c.cend());
96// assert ( std::cend(c) == c.cend());
97// assert ( std::rbegin(c) == c.rbegin());
98// assert ( std::rbegin(c) != c.rend());
99// assert ( std::rend(c) == c.rend());
100// assert ( std::crbegin(c) == c.crbegin());
101// assert ( std::crbegin(c) != c.crend());
102// assert ( std::crend(c) == c.crend());
103#endif
104 }
105
106int main(){
107 std::vector<int> v; v.push_back(1);
108 std::list<int> l; l.push_back(2);
109 std::array<int, 1> a; a[0] = 3;
110 std::initializer_list<int> il = { 4 };
111
112 test_container ( v, 1 );
113 test_container ( l, 2 );
114 test_container ( a, 3 );
115 test_container ( il, 4 );
116
117 test_const_container ( v, 1 );
118 test_const_container ( l, 2 );
119 test_const_container ( a, 3 );
120 test_const_container ( il, 4 );
121}
122
123#else
124int main(){}
125#endif