Add boost::get<> support to Boost.Array

[SVN r82089]
This commit is contained in:
Marshall Clow
2012-12-19 00:53:31 +00:00
parent daeb19f693
commit e02e7dcc00
7 changed files with 206 additions and 76 deletions

View File

@ -1,5 +1,5 @@
/* tests for using class array<> specialization for size 0
* (C) Copyright Alisdair Meredith 2006.
/* tests using std::get on boost:array
* (C) Copyright Marshall Clow 2012
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@ -13,42 +13,55 @@
#include <array>
#endif
#include <boost/test/included/test_exec_monitor.hpp>
namespace {
unsigned int failed_tests = 0;
#ifndef BOOST_NO_CXX11_HDR_ARRAY
void fail_test( const char * reason ) {
++failed_tests;
std::cerr << "Test failure " << failed_tests << ": " << reason << std::endl;
}
template< class T >
void RunTests()
{
typedef boost::array< T, 5 > test_type;
typedef T arr[5];
test_type test_case; // = { 1, 1, 2, 3, 5 };
#ifndef BOOST_NO_CXX11_HDR_ARRAY
template< class T >
void RunStdTests()
{
typedef boost::array< T, 5 > test_type;
typedef T arr[5];
test_type test_case; // = { 1, 1, 2, 3, 5 };
T &aRef = std::get<0> ( test_case );
if ( &*test_case.begin () != &aRef )
fail_test ( "Array7: Same thing not equal?(1)" );
T &aRef = std::get<0> ( test_case );
BOOST_CHECK ( &*test_case.begin () == &aRef );
const T &caRef = std::get<0> ( test_case );
if ( &*test_case.cbegin () != &caRef )
fail_test ( "Array7: Same thing not equal?(2)" );
}
#endif
const T &caRef = std::get<0> ( test_case );
BOOST_CHECK ( &*test_case.cbegin () == &caRef );
}
#endif
template< class T >
void RunBoostTests()
{
typedef boost::array< T, 5 > test_type;
typedef T arr[5];
test_type test_case; // = { 1, 1, 2, 3, 5 };
T &aRef = boost::get<0> ( test_case );
BOOST_CHECK ( &*test_case.begin () == &aRef );
const T &caRef = boost::get<0> ( test_case );
BOOST_CHECK ( &*test_case.cbegin () == &caRef );
}
}
int main()
int test_main( int , char* [] )
{
RunBoostTests< bool >();
RunBoostTests< void * >();
RunBoostTests< long double >();
RunBoostTests< std::string >();
#ifndef BOOST_NO_CXX11_HDR_ARRAY
RunTests< bool >();
RunTests< void * >();
RunTests< long double >();
RunTests< std::string >();
RunStdTests< bool >();
RunStdTests< void * >();
RunStdTests< long double >();
RunStdTests< std::string >();
#endif
return failed_tests;
return 0;
}