Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / array / test / array6.cpp
1 /* tests for using class array<> specialization for size 0
2  * (C) Copyright Alisdair Meredith 2006.
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
13 #include <boost/core/lightweight_test_trait.hpp>
14
15 namespace {
16     template< class T >
17     void    RunTests()
18     {
19         typedef boost::array< T, 5 >    test_type;
20         typedef T arr[5];
21         test_type           test_case; //   =   { 1, 1, 2, 3, 5 };
22     
23         arr &aRef = get_c_array ( test_case );
24         BOOST_TEST ( &*test_case.begin () == &aRef[0] );
25         
26         const arr &caRef = get_c_array ( test_case );
27         typename test_type::const_iterator iter = test_case.begin ();
28         BOOST_TEST ( &*iter == &caRef[0] );
29
30     //  Confirm at() throws the std lib defined exception
31         try {
32             test_case.at( test_case.size());
33             BOOST_TEST(false);
34             }
35         catch ( const std::out_of_range & ) {}
36
37         try {
38             test_case.at( test_case.size() + 1);
39             BOOST_TEST(false);
40             }
41         catch ( const std::out_of_range & ) {}
42
43         try {
44             test_case.at( test_case.size() + 100);
45             BOOST_TEST(false);
46             }
47         catch ( const std::out_of_range & ) {}
48     }
49 }
50
51 int main ()
52 {
53     RunTests< bool >();
54     RunTests< void * >();
55     RunTests< long double >();
56     RunTests< std::string >();
57
58     return boost::report_errors();
59 }
60