1 /* tests using std::get on boost:array
2 * (C) Copyright Marshall Clow 2012
3 * Distributed under the Boost Software License, Version 1.0. (See
4 * accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
6 */
7
8 #include <string>
9 #include <iostream>
10 #include <boost/array.hpp>
11 #include <algorithm>
12 #ifndef BOOST_NO_CXX11_HDR_ARRAY
13 #include <array>
14 #endif
15
16 #include <boost/core/lightweight_test_trait.hpp>
17
18 namespace {
19
20 #ifndef BOOST_NO_CXX11_HDR_ARRAY
21 template< class T >
RunStdTests()22 void RunStdTests()
23 {
24 typedef boost::array< T, 5 > test_type;
25 test_type test_case; // = { 1, 1, 2, 3, 5 };
26
27 T &aRef = std::get<0> ( test_case );
28 BOOST_TEST ( &*test_case.begin () == &aRef );
29
30 const T &caRef = std::get<0> ( test_case );
31 BOOST_TEST ( &*test_case.cbegin () == &caRef );
32 }
33 #endif
34
35 template< class T >
RunBoostTests()36 void RunBoostTests()
37 {
38 typedef boost::array< T, 5 > test_type;
39 test_type test_case; // = { 1, 1, 2, 3, 5 };
40
41 T &aRef = boost::get<0> ( test_case );
42 BOOST_TEST ( &*test_case.begin () == &aRef );
43
44 const T &caRef = boost::get<0> ( test_case );
45 BOOST_TEST ( &*test_case.cbegin () == &caRef );
46 }
47
48 }
49
main()50 int main()
51 {
52 RunBoostTests< bool >();
53 RunBoostTests< void * >();
54 RunBoostTests< long double >();
55 RunBoostTests< std::string >();
56
57 #ifndef BOOST_NO_CXX11_HDR_ARRAY
58 RunStdTests< bool >();
59 RunStdTests< void * >();
60 RunStdTests< long double >();
61 RunStdTests< std::string >();
62 #endif
63
64 return boost::report_errors();
65 }
66
67