1 | // (C) Copyright John Maddock 2005. |
---|
2 | // Use, modification and distribution are subject to the |
---|
3 | // Boost Software License, Version 1.0. (See accompanying file |
---|
4 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
5 | |
---|
6 | #ifdef TEST_STD_HEADERS |
---|
7 | #include <array> |
---|
8 | #else |
---|
9 | #include <boost/tr1/array.hpp> |
---|
10 | #endif |
---|
11 | |
---|
12 | #include <string> |
---|
13 | #include <boost/static_assert.hpp> |
---|
14 | #include <boost/type_traits/is_same.hpp> |
---|
15 | |
---|
16 | #include "verify_return.hpp" |
---|
17 | |
---|
18 | template <class T, class U> |
---|
19 | void check_tuple_access(T& a, const U&) |
---|
20 | { |
---|
21 | typedef typename T::value_type value_type; |
---|
22 | |
---|
23 | const T& ca = a; |
---|
24 | |
---|
25 | BOOST_STATIC_ASSERT((::boost::is_same< typename std::tr1::tuple_element<0,T>::type, value_type>::value)); |
---|
26 | verify_return_type(&std::tr1::get<0>(a), static_cast<value_type*>(0)); |
---|
27 | verify_return_type(&std::tr1::get<0>(ca), static_cast<const value_type*>(0)); |
---|
28 | } |
---|
29 | |
---|
30 | template <class T> |
---|
31 | void check_tuple_access(T& a, const boost::mpl::true_&) |
---|
32 | { |
---|
33 | // nothing to check the array is empty |
---|
34 | } |
---|
35 | |
---|
36 | template <class T> |
---|
37 | void check_array(T& a) |
---|
38 | { |
---|
39 | typedef typename T::reference reference; |
---|
40 | typedef typename T::const_reference const_reference; |
---|
41 | typedef typename T::iterator iterator; |
---|
42 | typedef typename T::const_iterator const_iterator; |
---|
43 | typedef typename T::size_type size_type; |
---|
44 | typedef typename T::difference_type difference_type; |
---|
45 | typedef typename T::value_type value_type; |
---|
46 | typedef typename T::reverse_iterator reverse_iterator; |
---|
47 | typedef typename T::const_reverse_iterator const_reverse_iterator; |
---|
48 | |
---|
49 | BOOST_STATIC_ASSERT((::boost::is_same<value_type&, reference>::value)); |
---|
50 | BOOST_STATIC_ASSERT((::boost::is_same<value_type const&, const_reference>::value)); |
---|
51 | BOOST_STATIC_ASSERT((::boost::is_same<std::size_t, size_type>::value)); |
---|
52 | BOOST_STATIC_ASSERT((::boost::is_same<std::ptrdiff_t, difference_type>::value)); |
---|
53 | BOOST_STATIC_ASSERT((::boost::is_same<std::reverse_iterator<iterator>, reverse_iterator>::value)); |
---|
54 | BOOST_STATIC_ASSERT((::boost::is_same<std::reverse_iterator<const_iterator>, const_reverse_iterator>::value)); |
---|
55 | |
---|
56 | const T& ca = a; |
---|
57 | const T& ca2 = a; |
---|
58 | verify_return_type(a.begin(), iterator()); |
---|
59 | verify_return_type(ca.begin(), const_iterator()); |
---|
60 | verify_return_type(a.end(), iterator()); |
---|
61 | verify_return_type(ca.end(), const_iterator()); |
---|
62 | verify_return_type(a.rbegin(), reverse_iterator()); |
---|
63 | verify_return_type(ca.rbegin(), const_reverse_iterator()); |
---|
64 | verify_return_type(a.rend(), reverse_iterator()); |
---|
65 | verify_return_type(ca.rend(), const_reverse_iterator()); |
---|
66 | |
---|
67 | verify_return_type(ca.size(), size_type(0)); |
---|
68 | verify_return_type(ca.max_size(), size_type(0)); |
---|
69 | verify_return_type(ca.empty(), false); |
---|
70 | |
---|
71 | verify_return_type(&a[0], static_cast<value_type*>(0)); |
---|
72 | verify_return_type(&ca[0], static_cast<const value_type*>(0)); |
---|
73 | verify_return_type(&a.at(0), static_cast<value_type*>(0)); |
---|
74 | verify_return_type(&ca.at(0), static_cast<const value_type*>(0)); |
---|
75 | verify_return_type(&a.front(), static_cast<value_type*>(0)); |
---|
76 | verify_return_type(&ca.front(), static_cast<const value_type*>(0)); |
---|
77 | verify_return_type(&a.back(), static_cast<value_type*>(0)); |
---|
78 | verify_return_type(&ca.back(), static_cast<const value_type*>(0)); |
---|
79 | verify_return_type(a.data(), static_cast<value_type*>(0)); |
---|
80 | verify_return_type(ca.data(), static_cast<const value_type*>(0)); |
---|
81 | |
---|
82 | // swap: |
---|
83 | std::tr1::swap(a, a); |
---|
84 | verify_return_type(ca == ca2, false); |
---|
85 | verify_return_type(ca != ca2, false); |
---|
86 | verify_return_type(ca < ca2, false); |
---|
87 | verify_return_type(ca > ca2, false); |
---|
88 | verify_return_type(ca <= ca2, false); |
---|
89 | verify_return_type(ca >= ca2, false); |
---|
90 | |
---|
91 | typedef boost::mpl::bool_<std::tr1::tuple_size<T>::value == 0> emtyness; |
---|
92 | check_tuple_access(a, emtyness()); |
---|
93 | } |
---|
94 | |
---|
95 | int main() |
---|
96 | { |
---|
97 | std::tr1::array<int,2> a1 = {}; |
---|
98 | check_array(a1); |
---|
99 | BOOST_STATIC_ASSERT((std::tr1::tuple_size<std::tr1::array<int,2> >::value == 2)); |
---|
100 | |
---|
101 | std::tr1::array<std::string,4> a2 = { "abc", "def", "", "y", }; |
---|
102 | check_array(a2); |
---|
103 | BOOST_STATIC_ASSERT((std::tr1::tuple_size<std::tr1::array<std::string,4> >::value == 4)); |
---|
104 | |
---|
105 | std::tr1::array<int,0> a3 = {}; |
---|
106 | check_array(a3); |
---|
107 | BOOST_STATIC_ASSERT((std::tr1::tuple_size<std::tr1::array<int,0> >::value == 0)); |
---|
108 | |
---|
109 | return 0; |
---|
110 | } |
---|
111 | |
---|