From daeb19f6932f56186686499f090d7d3e006e9b15 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 18 Dec 2012 17:59:08 +0000 Subject: [PATCH 01/17] Add support for std::get<> to Boost.Array [SVN r82083] --- include/boost/array.hpp | 17 +++++++++++++ test/Jamfile.v2 | 1 + test/array7.cpp | 54 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 test/array7.cpp diff --git a/include/boost/array.hpp b/include/boost/array.hpp index fa06fa9..b290c4b 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -42,6 +42,7 @@ #include #include #include +#include #include // Handles broken standard libraries better than @@ -438,6 +439,22 @@ namespace boost { } /* namespace boost */ +#ifndef BOOST_NO_CXX11_HDR_ARRAY +// If we don't have std::array, I'm assuming that we don't have std::get +namespace std { + template + T &get(boost::array &arr) BOOST_NOEXCEPT { + BOOST_STATIC_ASSERT_MSG ( Idx < N, "std::get<>(boost::array &) index out of range" ); + return arr[Idx]; + } + + template + const T &get(const boost::array &arr) BOOST_NOEXCEPT { + BOOST_STATIC_ASSERT_MSG ( Idx < N, "std::get<>(const boost::array &) index out of range" ); + return arr[Idx]; + } +} +#endif #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) # pragma warning(pop) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index a09ba68..f6db6a1 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -12,5 +12,6 @@ test-suite array : [ run array4.cpp ] [ run array5.cpp ] [ run array6.cpp ] + [ run array7.cpp ] [ run array_hash.cpp ] ; diff --git a/test/array7.cpp b/test/array7.cpp new file mode 100644 index 0000000..844b09c --- /dev/null +++ b/test/array7.cpp @@ -0,0 +1,54 @@ +/* tests for using class array<> specialization for size 0 + * (C) Copyright Alisdair Meredith 2006. + * 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) + */ + +#include +#include +#include +#include +#ifndef BOOST_NO_CXX11_HDR_ARRAY +#include +#endif + +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 }; + + T &aRef = std::get<0> ( test_case ); + if ( &*test_case.begin () != &aRef ) + fail_test ( "Array7: Same thing not equal?(1)" ); + + const T &caRef = std::get<0> ( test_case ); + if ( &*test_case.cbegin () != &caRef ) + fail_test ( "Array7: Same thing not equal?(2)" ); +} +#endif + +} + +int main() +{ +#ifndef BOOST_NO_CXX11_HDR_ARRAY + RunTests< bool >(); + RunTests< void * >(); + RunTests< long double >(); + RunTests< std::string >(); +#endif + return failed_tests; +} + From e02e7dcc003138920e3cfddb0e587fca9e53d337 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 19 Dec 2012 00:53:31 +0000 Subject: [PATCH 02/17] Add boost::get<> support to Boost.Array [SVN r82089] --- include/boost/array.hpp | 14 +++++++- test/Jamfile.v2 | 2 ++ test/array6.cpp | 41 ++++++++++-------------- test/array7.cpp | 71 ++++++++++++++++++++++++----------------- test/array_getfail1.cpp | 51 +++++++++++++++++++++++++++++ test/array_getfail2.cpp | 64 +++++++++++++++++++++++++++++++++++++ test/array_hash.cpp | 39 ++++++++++------------ 7 files changed, 206 insertions(+), 76 deletions(-) create mode 100644 test/array_getfail1.cpp create mode 100644 test/array_getfail2.cpp diff --git a/include/boost/array.hpp b/include/boost/array.hpp index b290c4b..4b35bf4 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -437,10 +437,22 @@ namespace boost { return boost::hash_range(arr.begin(), arr.end()); } + template + T &get(boost::array &arr) BOOST_NOEXCEPT { + BOOST_STATIC_ASSERT_MSG ( Idx < N, "boost::get<>(boost::array &) index out of range" ); + return arr[Idx]; + } + + template + const T &get(const boost::array &arr) BOOST_NOEXCEPT { + BOOST_STATIC_ASSERT_MSG ( Idx < N, "boost::get<>(const boost::array &) index out of range" ); + return arr[Idx]; + } + } /* namespace boost */ #ifndef BOOST_NO_CXX11_HDR_ARRAY -// If we don't have std::array, I'm assuming that we don't have std::get +// If we don't have std::array, I'm assuming that we don't have std::get namespace std { template T &get(boost::array &arr) BOOST_NOEXCEPT { diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index f6db6a1..fab405e 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -13,5 +13,7 @@ test-suite array : [ run array5.cpp ] [ run array6.cpp ] [ run array7.cpp ] + [ compile-fail array_getfail1.cpp ] + [ compile-fail array_getfail2.cpp ] [ run array_hash.cpp ] ; diff --git a/test/array6.cpp b/test/array6.cpp index 658cec6..57eb51e 100644 --- a/test/array6.cpp +++ b/test/array6.cpp @@ -10,39 +10,32 @@ #include #include +#include + + namespace { -unsigned int failed_tests = 0; - -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 }; + 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 }; - arr &aRef = get_c_array ( test_case ); - if ( &*test_case.begin () != &aRef[0] ) - fail_test ( "Array6: Same thing not equal?(1)" ); + arr &aRef = get_c_array ( test_case ); + BOOST_CHECK ( &*test_case.begin () == &aRef[0] ); - const arr &caRef = get_c_array ( test_case ); - typename test_type::const_iterator iter = test_case.begin (); - if ( &*iter != &caRef[0] ) - fail_test ( "Array6: Same thing not equal?(2)" ); + const arr &caRef = get_c_array ( test_case ); + typename test_type::const_iterator iter = test_case.begin (); + BOOST_CHECK ( &*iter == &caRef[0] ); + } } -} - -int main() +int test_main( int , char* [] ) { RunTests< bool >(); RunTests< void * >(); RunTests< long double >(); RunTests< std::string >(); - return failed_tests; + return 0; } diff --git a/test/array7.cpp b/test/array7.cpp index 844b09c..b3d99aa 100644 --- a/test/array7.cpp +++ b/test/array7.cpp @@ -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 #endif +#include + 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; } diff --git a/test/array_getfail1.cpp b/test/array_getfail1.cpp new file mode 100644 index 0000000..cdae8ed --- /dev/null +++ b/test/array_getfail1.cpp @@ -0,0 +1,51 @@ +/* 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) + */ + +#include +#include +#include +#ifndef BOOST_NO_CXX11_HDR_ARRAY +#include +#endif + +#include +#include + + +#include + +namespace { + + #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<5> ( test_case ); // should fail to compile + BOOST_CHECK ( &*test_case.begin () == &aRef ); + } + #endif + +} + +int test_main( int , char* [] ) +{ + +#ifndef BOOST_NO_CXX11_HDR_ARRAY + RunStdTests< bool >(); + RunStdTests< void * >(); + RunStdTests< long double >(); + RunStdTests< std::string >(); +#else + BOOST_STATIC_ASSERT ( false ); // fail on C++03 systems. +#endif + return 0; +} + diff --git a/test/array_getfail2.cpp b/test/array_getfail2.cpp new file mode 100644 index 0000000..0b49510 --- /dev/null +++ b/test/array_getfail2.cpp @@ -0,0 +1,64 @@ +/* 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) + */ + +#include +#include +#include +#include +#ifndef BOOST_NO_CXX11_HDR_ARRAY +#include +#endif + +#include + +namespace { + + #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 ); + BOOST_CHECK ( &*test_case.begin () == &aRef ); + + 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<5> ( test_case ); + BOOST_CHECK ( &*test_case.begin () == &aRef ); + } + +} + +int test_main( int , char* [] ) +{ + RunBoostTests< bool >(); + RunBoostTests< void * >(); + RunBoostTests< long double >(); + RunBoostTests< std::string >(); + +#ifndef BOOST_NO_CXX11_HDR_ARRAY + RunStdTests< bool >(); + RunStdTests< void * >(); + RunStdTests< long double >(); + RunStdTests< std::string >(); +#endif + return 0; +} + diff --git a/test/array_hash.cpp b/test/array_hash.cpp index 474e29c..0859296 100644 --- a/test/array_hash.cpp +++ b/test/array_hash.cpp @@ -11,39 +11,34 @@ #include #include +#include + namespace { -unsigned int failed_tests = 0; -void fail_test( const char * reason ) { - ++failed_tests; - std::cerr << "Test failure " << failed_tests << ": " << reason << std::endl; -} - -template< class T > -void RunTests() -{ -// std::size_t hash0 = boost::hash > () ( boost::array ()); -// std::size_t hash1 = boost::hash > () ( boost::array ()); + template< class T > + void RunTests() + { + // std::size_t hash0 = boost::hash > () ( boost::array ()); + // std::size_t hash1 = boost::hash > () ( boost::array ()); - typedef boost::array< T, 5 > barr; - typedef T arr[5]; - barr test_barr = {{ 1, 1, 2, 3, 5 }}; - arr test_arr = { 1, 1, 2, 3, 5 }; + typedef boost::array< T, 5 > barr; + typedef T arr[5]; + barr test_barr = {{ 1, 1, 2, 3, 5 }}; + arr test_arr = { 1, 1, 2, 3, 5 }; - std::size_t bhash = boost::hash () ( test_barr ); - std::size_t ahash = boost::hash () ( test_arr ); - if ( ahash != bhash ) - fail_test ( "Array_hash: Hash-mismatch on " ); -} + std::size_t bhash = boost::hash () ( test_barr ); + std::size_t ahash = boost::hash () ( test_arr ); + BOOST_CHECK ( ahash == bhash ); + } } -int main() +int test_main( int , char* [] ) { RunTests< int >(); RunTests< long >(); RunTests< long double >(); - return failed_tests; + return 0; } From 88abb34b4d8404d88c12858067fcbfe93b19e3c1 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 19 Dec 2012 17:49:04 +0000 Subject: [PATCH 03/17] Fix bug where failure test failed for the wrong reason on C++03 [SVN r82102] --- test/array_getfail1.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/array_getfail1.cpp b/test/array_getfail1.cpp index cdae8ed..c9540a5 100644 --- a/test/array_getfail1.cpp +++ b/test/array_getfail1.cpp @@ -5,6 +5,10 @@ * http://www.boost.org/LICENSE_1_0.txt) */ +#include +#include + + #include #include #include @@ -12,10 +16,6 @@ #include #endif -#include -#include - - #include namespace { From 97a26a15999d14fa9becff7e21425daa06413fbf Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 19 Dec 2012 20:32:34 +0000 Subject: [PATCH 04/17] Documented boost::get support in Boost.Array [SVN r82105] --- doc/Jamfile.v2 | 5 +++ doc/array.xml | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 doc/Jamfile.v2 diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 new file mode 100644 index 0000000..ce8e110 --- /dev/null +++ b/doc/Jamfile.v2 @@ -0,0 +1,5 @@ +using boostbook ; + +boostbook standalone + : array.xml + : boost.root=../../../.. ; diff --git a/doc/array.xml b/doc/array.xml index 62bf7c2..eac8087 100644 --- a/doc/array.xml +++ b/doc/array.xml @@ -7,6 +7,10 @@ Nicolai Josuttis + + Marshall + Clow + 2001 @@ -16,6 +20,11 @@ Nicolai M. Josuttis + + 2012 + Marshall Clow + + Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at @@ -176,6 +185,24 @@ iterator for position after the last element will not throw + + + + const_iterator + + + constant iterator for the first element + will not throw + + + + + const_iterator + + + constant iterator for position after the last element + will not throw + @@ -200,6 +227,24 @@ reverse iterator for position after the last element in reverse iteration + + + + const_reverse_iterator + + + constant reverse iterator for the first element of reverse iteration + will not throw + + + + + const_reverse_iterator + + + constant reverse iterator for position after the last element in reverse iteration + will not throw + @@ -465,6 +510,49 @@ !(x < y) + + + + + + T + + + array<T, N>& + + element of array with index Idx + Will static_assert if Idx >= N + + + + + + T + + + const array<T, N>& + + const element of array with index Idx + Will static_assert if Idx >= N + + + From 117584a2ceae58d7c19e6571f6ad213da79596f5 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Mon, 11 Feb 2013 17:16:55 +0000 Subject: [PATCH 05/17] Update Boost.Array tests to use newer Boost.Test features [SVN r82822] --- test/Jamfile.v2 | 13 ++++++--- test/array0.cpp | 58 ++++++++++++----------------------------- test/array6.cpp | 7 +++-- test/array7.cpp | 6 ++--- test/array_getfail1.cpp | 7 +++-- test/array_getfail2.cpp | 6 ++--- test/array_hash.cpp | 7 +++-- 7 files changed, 40 insertions(+), 64 deletions(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index fab405e..60186e3 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -4,16 +4,21 @@ import testing ; +alias unit_test_framework + : # sources + /boost//unit_test_framework + ; + test-suite array : - [ run array0.cpp ] + [ run array0.cpp unit_test_framework : : : : array0 ] [ run array1.cpp ] [ run array2.cpp ] [ run array3.cpp ] [ run array4.cpp ] [ run array5.cpp ] - [ run array6.cpp ] - [ run array7.cpp ] + [ run array6.cpp unit_test_framework : : : : array6 ] + [ run array7.cpp unit_test_framework : : : : array7 ] [ compile-fail array_getfail1.cpp ] [ compile-fail array_getfail2.cpp ] - [ run array_hash.cpp ] + [ run array_hash.cpp unit_test_framework : : : : array_hash ] ; diff --git a/test/array0.cpp b/test/array0.cpp index d75db76..c1c047e 100644 --- a/test/array0.cpp +++ b/test/array0.cpp @@ -9,18 +9,15 @@ #include #include -namespace { -unsigned int failed_tests = 0; +#define BOOST_TEST_MAIN +#include -void fail_test( const char * reason ) { - ++failed_tests; - std::cerr << "Test failure " << failed_tests << ": " << reason << std::endl; -} +namespace { template< class T > void BadValue( const T & ) { - fail_test( "Unexpected value" ); + BOOST_CHECK ( false ); } template< class T > @@ -36,46 +33,24 @@ void RunTests() // front/back and operator[] must compile, but calling them is undefined // Likewise, all tests below should evaluate to false, avoiding undefined behaviour - if( !test_case.empty() ) { - BadValue( test_case.front() ); - } + BOOST_CHECK ( test_case.empty()); + BOOST_CHECK ( const_test_case.empty()); - if( !const_test_case.empty() ) { - BadValue( const_test_case.back() ); - } - - if( test_case.size() > 0 ) { - BadValue( test_case[ 0 ] ); - } - - if( const_test_case.max_size() > 0 ) { - BadValue( const_test_case[ 0 ] ); - } + BOOST_CHECK ( test_case.size() == 0 ); + BOOST_CHECK ( const_test_case.size() == 0 ); // Assert requirements of TR1 6.2.2.4 - if( test_case.begin() != test_case.end() ) { - fail_test( "Not an empty range" ); - } - if( test_case.cbegin() != test_case.cend() ) { - fail_test( "Not an empty range" ); - } - if( const_test_case.begin() != const_test_case.end() ) { - fail_test( "Not an empty range" ); - } - if( const_test_case.cbegin() != const_test_case.cend() ) { - fail_test( "Not an empty range" ); - } - - if( test_case.begin() == const_test_case.begin() ) { - fail_test( "iterators for different containers are not distinct" ); - } + BOOST_CHECK ( test_case.begin() == test_case.end()); + BOOST_CHECK ( test_case.cbegin() == test_case.cend()); + BOOST_CHECK ( const_test_case.begin() == const_test_case.end()); + BOOST_CHECK ( const_test_case.cbegin() == const_test_case.cend()); + BOOST_CHECK ( test_case.begin() != const_test_case.begin() ); if( test_case.data() == const_test_case.data() ) { // Value of data is unspecified in TR1, so no requirement this test pass or fail // However, it must compile! } - // Check can safely use all iterator types with std algorithms std::for_each( test_case.begin(), test_case.end(), BadValue< T > ); std::for_each( test_case.rbegin(), test_case.rend(), BadValue< T > ); @@ -87,12 +62,12 @@ void RunTests() // Check swap is well formed std::swap( test_case, test_case ); - // Check assigment operator and overloads are well formed + // Check assignment operator and overloads are well formed test_case = const_test_case; // Confirm at() throws the std lib defined exception try { - BadValue( test_case.at( 0 ) ); + BadValue( test_case.at( 0 )); } catch ( const std::out_of_range & ) { } @@ -104,12 +79,11 @@ void RunTests() } -int main() +BOOST_AUTO_TEST_CASE( test_main ) { RunTests< bool >(); RunTests< void * >(); RunTests< long double >(); RunTests< std::string >(); - return failed_tests; } diff --git a/test/array6.cpp b/test/array6.cpp index 57eb51e..3d737fd 100644 --- a/test/array6.cpp +++ b/test/array6.cpp @@ -10,8 +10,8 @@ #include #include -#include - +#define BOOST_TEST_MAIN +#include namespace { template< class T > @@ -30,12 +30,11 @@ namespace { } } -int test_main( int , char* [] ) +BOOST_AUTO_TEST_CASE( test_main ) { RunTests< bool >(); RunTests< void * >(); RunTests< long double >(); RunTests< std::string >(); - return 0; } diff --git a/test/array7.cpp b/test/array7.cpp index b3d99aa..de2ebe0 100644 --- a/test/array7.cpp +++ b/test/array7.cpp @@ -13,7 +13,8 @@ #include #endif -#include +#define BOOST_TEST_MAIN +#include namespace { @@ -49,7 +50,7 @@ namespace { } -int test_main( int , char* [] ) +BOOST_AUTO_TEST_CASE( test_main ) { RunBoostTests< bool >(); RunBoostTests< void * >(); @@ -62,6 +63,5 @@ int test_main( int , char* [] ) RunStdTests< long double >(); RunStdTests< std::string >(); #endif - return 0; } diff --git a/test/array_getfail1.cpp b/test/array_getfail1.cpp index c9540a5..3cb1f49 100644 --- a/test/array_getfail1.cpp +++ b/test/array_getfail1.cpp @@ -16,7 +16,8 @@ #include #endif -#include +#define BOOST_TEST_MAIN +#include namespace { @@ -35,9 +36,8 @@ namespace { } -int test_main( int , char* [] ) +BOOST_AUTO_TEST_CASE( test_main ) { - #ifndef BOOST_NO_CXX11_HDR_ARRAY RunStdTests< bool >(); RunStdTests< void * >(); @@ -46,6 +46,5 @@ int test_main( int , char* [] ) #else BOOST_STATIC_ASSERT ( false ); // fail on C++03 systems. #endif - return 0; } diff --git a/test/array_getfail2.cpp b/test/array_getfail2.cpp index 0b49510..e2277b0 100644 --- a/test/array_getfail2.cpp +++ b/test/array_getfail2.cpp @@ -13,7 +13,8 @@ #include #endif -#include +#define BOOST_TEST_MAIN +#include namespace { @@ -46,7 +47,7 @@ namespace { } -int test_main( int , char* [] ) +BOOST_AUTO_TEST_CASE( test_main ) { RunBoostTests< bool >(); RunBoostTests< void * >(); @@ -59,6 +60,5 @@ int test_main( int , char* [] ) RunStdTests< long double >(); RunStdTests< std::string >(); #endif - return 0; } diff --git a/test/array_hash.cpp b/test/array_hash.cpp index 0859296..a83eead 100644 --- a/test/array_hash.cpp +++ b/test/array_hash.cpp @@ -11,7 +11,8 @@ #include #include -#include +#define BOOST_TEST_MAIN +#include namespace { @@ -33,12 +34,10 @@ namespace { } -int test_main( int , char* [] ) +BOOST_AUTO_TEST_CASE( test_main ) { RunTests< int >(); RunTests< long >(); RunTests< long double >(); - - return 0; } From 4a60b8c146a0543b9030fef2b19f2c81d70d4138 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 12 Feb 2013 18:07:15 +0000 Subject: [PATCH 06/17] Add constexpr support to Boost.Array [SVN r82834] --- include/boost/array.hpp | 44 ++++++++++++++++++---------------------- test/Jamfile.v2 | 1 + test/array_constexpr.cpp | 43 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 24 deletions(-) create mode 100644 test/array_constexpr.cpp diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 4b35bf4..b907cf6 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -13,6 +13,7 @@ * accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * + * 9 Jan 2013 - (mtc) Added constexpr * 14 Apr 2012 - (mtc) Added support for boost::hash * 28 Dec 2010 - (mtc) Added cbegin and cend (and crbegin and crend) for C++Ox compatibility. * 10 Mar 2010 - (mtc) fill method added, matching resolution of the standard library working group. @@ -121,19 +122,17 @@ namespace boost { // operator[] reference operator[](size_type i) { - BOOST_ASSERT_MSG( i < N, "out of range" ); - return elems[i]; + return BOOST_ASSERT_MSG( i < N, "out of range" ), elems[i]; } - const_reference operator[](size_type i) const + BOOST_CONSTEXPR const_reference operator[](size_type i) const { - BOOST_ASSERT_MSG( i < N, "out of range" ); - return elems[i]; + return BOOST_ASSERT_MSG( i < N, "out of range" ), elems[i]; } // at() with range check - reference at(size_type i) { rangecheck(i); return elems[i]; } - const_reference at(size_type i) const { rangecheck(i); return elems[i]; } + reference at(size_type i) { return rangecheck(i), elems[i]; } + BOOST_CONSTEXPR const_reference at(size_type i) const { return rangecheck(i), elems[i]; } // front() and back() reference front() @@ -141,7 +140,7 @@ namespace boost { return elems[0]; } - const_reference front() const + BOOST_CONSTEXPR const_reference front() const { return elems[0]; } @@ -151,15 +150,15 @@ namespace boost { return elems[N-1]; } - const_reference back() const + BOOST_CONSTEXPR const_reference back() const { return elems[N-1]; } // size is constant - static size_type size() { return N; } - static bool empty() { return false; } - static size_type max_size() { return N; } + static BOOST_CONSTEXPR size_type size() { return N; } + static BOOST_CONSTEXPR bool empty() { return false; } + static BOOST_CONSTEXPR size_type max_size() { return N; } enum { static_size = N }; // swap (note: linear complexity) @@ -190,11 +189,8 @@ namespace boost { } // check range (may be private because it is static) - static void rangecheck (size_type i) { - if (i >= size()) { - std::out_of_range e("array<>: index out of range"); - boost::throw_exception(e); - } + static BOOST_CONSTEXPR bool rangecheck (size_type i) { + return i > size() ? boost::throw_exception(std::out_of_range ("array<>: index out of range")), true : true; } }; @@ -265,14 +261,14 @@ namespace boost { return failed_rangecheck(); } - const_reference operator[](size_type /*i*/) const + BOOST_CONSTEXPR const_reference operator[](size_type /*i*/) const { return failed_rangecheck(); } // at() with range check reference at(size_type /*i*/) { return failed_rangecheck(); } - const_reference at(size_type /*i*/) const { return failed_rangecheck(); } + BOOST_CONSTEXPR const_reference at(size_type /*i*/) const { return failed_rangecheck(); } // front() and back() reference front() @@ -280,7 +276,7 @@ namespace boost { return failed_rangecheck(); } - const_reference front() const + BOOST_CONSTEXPR const_reference front() const { return failed_rangecheck(); } @@ -290,15 +286,15 @@ namespace boost { return failed_rangecheck(); } - const_reference back() const + BOOST_CONSTEXPR const_reference back() const { return failed_rangecheck(); } // size is constant - static size_type size() { return 0; } - static bool empty() { return true; } - static size_type max_size() { return 0; } + static BOOST_CONSTEXPR size_type size() { return 0; } + static BOOST_CONSTEXPR bool empty() { return true; } + static BOOST_CONSTEXPR size_type max_size() { return 0; } enum { static_size = 0 }; void swap (array& /*y*/) { diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 60186e3..9181eac 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -18,6 +18,7 @@ test-suite array : [ run array5.cpp ] [ run array6.cpp unit_test_framework : : : : array6 ] [ run array7.cpp unit_test_framework : : : : array7 ] + [ run array_constexpr.cpp unit_test_framework : : : : array_constexpr ] [ compile-fail array_getfail1.cpp ] [ compile-fail array_getfail2.cpp ] [ run array_hash.cpp unit_test_framework : : : : array_hash ] diff --git a/test/array_constexpr.cpp b/test/array_constexpr.cpp new file mode 100644 index 0000000..8d35b88 --- /dev/null +++ b/test/array_constexpr.cpp @@ -0,0 +1,43 @@ +/* tests using constexpr 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) + */ + +#include +#include +#include +#include +#ifndef BOOST_NO_CXX11_HDR_ARRAY +#include +#endif + +#define BOOST_TEST_MAIN +#include + +#ifndef BOOST_NO_CXX11_CONSTEXPR +constexpr boost::array arr {{ 0,1,2,3,4,5,6,7,8,9 }}; +constexpr std::array arr_std {{ 0,1,2,3,4,5,6,7,8,9 }}; + +template +void sink ( T t ) {} + +template +void sink ( boost::array &arr ) {} + +BOOST_AUTO_TEST_CASE( test_main ) +{ +// constexpr int two = arr_std.at (2); + constexpr int three = arr.at (3); + int whatever [ arr.at(4) ]; + (void)three; + (void) whatever; +} + +#else // no constexpr means no constexpr tests! +BOOST_AUTO_TEST_CASE( test_main ) +{ +} +#endif + From 12fcbb59c2d6df55a56956b80cfc2ee42cdb2c1f Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Fri, 15 Feb 2013 17:11:09 +0000 Subject: [PATCH 07/17] Back out some of the constexpr support Boost.Array; it crashes gcc [SVN r82906] --- include/boost/array.hpp | 10 +++++----- test/Jamfile.v2 | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index b907cf6..0fc35fc 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -125,14 +125,14 @@ namespace boost { return BOOST_ASSERT_MSG( i < N, "out of range" ), elems[i]; } - BOOST_CONSTEXPR const_reference operator[](size_type i) const + /*BOOST_CONSTEXPR*/ const_reference operator[](size_type i) const { return BOOST_ASSERT_MSG( i < N, "out of range" ), elems[i]; } // at() with range check - reference at(size_type i) { return rangecheck(i), elems[i]; } - BOOST_CONSTEXPR const_reference at(size_type i) const { return rangecheck(i), elems[i]; } + reference at(size_type i) { return rangecheck(i), elems[i]; } + /*BOOST_CONSTEXPR*/ const_reference at(size_type i) const { return rangecheck(i), elems[i]; } // front() and back() reference front() @@ -261,14 +261,14 @@ namespace boost { return failed_rangecheck(); } - BOOST_CONSTEXPR const_reference operator[](size_type /*i*/) const + /*BOOST_CONSTEXPR*/ const_reference operator[](size_type /*i*/) const { return failed_rangecheck(); } // at() with range check reference at(size_type /*i*/) { return failed_rangecheck(); } - BOOST_CONSTEXPR const_reference at(size_type /*i*/) const { return failed_rangecheck(); } + /*BOOST_CONSTEXPR*/ const_reference at(size_type /*i*/) const { return failed_rangecheck(); } // front() and back() reference front() diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 9181eac..1a04d91 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -18,7 +18,7 @@ test-suite array : [ run array5.cpp ] [ run array6.cpp unit_test_framework : : : : array6 ] [ run array7.cpp unit_test_framework : : : : array7 ] - [ run array_constexpr.cpp unit_test_framework : : : : array_constexpr ] +# [ run array_constexpr.cpp unit_test_framework : : : : array_constexpr ] [ compile-fail array_getfail1.cpp ] [ compile-fail array_getfail2.cpp ] [ run array_hash.cpp unit_test_framework : : : : array_hash ] From 6ad6249e1c75baa77747b44e6a503af0ce7c0170 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 25 Sep 2013 13:51:37 +0000 Subject: [PATCH 08/17] Array: Remove obsolete MSVC version check. [SVN r85903] --- include/boost/array.hpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 0fc35fc..ae1f48f 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -86,12 +86,6 @@ namespace boost { #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS) typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; -#elif defined(_MSC_VER) && (_MSC_VER == 1300) && defined(BOOST_DINKUMWARE_STDLIB) && (BOOST_DINKUMWARE_STDLIB == 310) - // workaround for broken reverse_iterator in VC7 - typedef std::reverse_iterator > reverse_iterator; - typedef std::reverse_iterator > const_reverse_iterator; #elif defined(_RWSTD_NO_CLASS_PARTIAL_SPEC) typedef std::reverse_iterator reverse_iterator; @@ -222,12 +216,6 @@ namespace boost { #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS) typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; -#elif defined(_MSC_VER) && (_MSC_VER == 1300) && defined(BOOST_DINKUMWARE_STDLIB) && (BOOST_DINKUMWARE_STDLIB == 310) - // workaround for broken reverse_iterator in VC7 - typedef std::reverse_iterator > reverse_iterator; - typedef std::reverse_iterator > const_reverse_iterator; #elif defined(_RWSTD_NO_CLASS_PARTIAL_SPEC) typedef std::reverse_iterator reverse_iterator; From 2e0052d49fc331c11ffac1954b128070a2e5fbcd Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 11 Oct 2013 23:15:00 +0000 Subject: [PATCH 09/17] Remove BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION Process #ifndef...#endif conditions. [SVN r86244] --- include/boost/array.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index ae1f48f..43ea8a1 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -189,7 +189,6 @@ namespace boost { }; -#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) template< class T > class array< T, 0 > { @@ -320,7 +319,6 @@ namespace boost { #endif } }; -#endif // comparisons template From 4584f63f0108ec193c54749b1aa1c5e42c8b3b98 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 11 Oct 2013 23:20:59 +0000 Subject: [PATCH 10/17] Simplify multi-component ifdefs containing BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION [SVN r86248] --- include/boost/array.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 43ea8a1..e147a18 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -83,7 +83,7 @@ namespace boost { const_iterator cend() const { return elems+N; } // reverse iterator support -#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS) +#if !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS) typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; #elif defined(_RWSTD_NO_CLASS_PARTIAL_SPEC) @@ -212,7 +212,7 @@ namespace boost { const_iterator cend() const { return cbegin(); } // reverse iterator support -#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS) +#if !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS) typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; #elif defined(_RWSTD_NO_CLASS_PARTIAL_SPEC) From 40c5dae84c5e6b134efcbce99ebc88c6df7b5b2f Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Mon, 14 Oct 2013 21:31:19 +0000 Subject: [PATCH 11/17] Remove tabs [SVN r86310] --- test/array_constexpr.cpp | 5 ++--- test/array_getfail1.cpp | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/test/array_constexpr.cpp b/test/array_constexpr.cpp index 8d35b88..927bdec 100644 --- a/test/array_constexpr.cpp +++ b/test/array_constexpr.cpp @@ -32,12 +32,11 @@ BOOST_AUTO_TEST_CASE( test_main ) constexpr int three = arr.at (3); int whatever [ arr.at(4) ]; (void)three; - (void) whatever; + (void) whatever; } -#else // no constexpr means no constexpr tests! +#else // no constexpr means no constexpr tests! BOOST_AUTO_TEST_CASE( test_main ) { } #endif - diff --git a/test/array_getfail1.cpp b/test/array_getfail1.cpp index 3cb1f49..21ae62f 100644 --- a/test/array_getfail1.cpp +++ b/test/array_getfail1.cpp @@ -29,7 +29,7 @@ namespace { typedef T arr[5]; test_type test_case; // = { 1, 1, 2, 3, 5 }; - T &aRef = std::get<5> ( test_case ); // should fail to compile + T &aRef = std::get<5> ( test_case ); // should fail to compile BOOST_CHECK ( &*test_case.begin () == &aRef ); } #endif @@ -44,7 +44,6 @@ BOOST_AUTO_TEST_CASE( test_main ) RunStdTests< long double >(); RunStdTests< std::string >(); #else - BOOST_STATIC_ASSERT ( false ); // fail on C++03 systems. + BOOST_STATIC_ASSERT ( false ); // fail on C++03 systems. #endif } - From 1966dd034b3827dc075b9a107130b5815c9ad070 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Mon, 14 Oct 2013 21:35:20 +0000 Subject: [PATCH 12/17] Updated license and copyright [SVN r86311] --- doc/Jamfile.v2 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index ce8e110..843a079 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -1,3 +1,7 @@ +#~ Copyright Marshall Clow 2013 +#~ 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) + using boostbook ; boostbook standalone From dfeb6bd0a5d57120761d3c97efb957984832802e Mon Sep 17 00:00:00 2001 From: Michel Morin Date: Wed, 30 Oct 2013 12:51:24 +0000 Subject: [PATCH 13/17] Correct broken links to C++ standard papers. Refs #9212. [SVN r86524] --- doc/array.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/array.xml b/doc/array.xml index eac8087..68ee5a3 100644 --- a/doc/array.xml +++ b/doc/array.xml @@ -77,7 +77,7 @@ Note that this class is suggested to be part of the next Technical Report, which will extend the C++ Standard (see - http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1548.htm). + http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1548.htm). Update: std::array is (as of C++11) part of the C++ standard. The differences between boost::array and std::array are minimal. From ce71078681f42a46779cfcc8e5c804a5908dc38b Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 18 Aug 2014 14:57:18 +0100 Subject: [PATCH 14/17] Add metadata file. --- meta/libraries.json | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 meta/libraries.json diff --git a/meta/libraries.json b/meta/libraries.json new file mode 100644 index 0000000..7710ee2 --- /dev/null +++ b/meta/libraries.json @@ -0,0 +1,17 @@ +{ + "key": "array", + "name": "Array", + "authors": [ + "Nicolai Josuttis" + ], + "description": "STL compliant container wrapper for arrays of constant size.", + "std": [ + "tr1" + ], + "category": [ + "Containers" + ], + "maintainers": [ + "Marshall Clow " + ] +} From cb4df41bd6bb64eead5e8d38b49716e7b681204c Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 9 Jan 2015 00:01:41 +0200 Subject: [PATCH 15/17] Replace inclusion of hash_fwd.hpp with a declaration of hash_range --- include/boost/array.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index e147a18..3ac0ffc 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -49,7 +49,6 @@ // Handles broken standard libraries better than #include #include -#include #include // FIXES for broken compilers @@ -412,6 +411,7 @@ namespace boost { } #endif + template std::size_t hash_range(It, It); template std::size_t hash_value(const array& arr) From 16824fe0f13fe8c067f394818ccd6b64b8f55303 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Fri, 7 Oct 2016 23:03:40 -0500 Subject: [PATCH 16/17] Add, and update, documentation build targets. --- doc/Jamfile.v2 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index 843a079..b7f51b7 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -7,3 +7,13 @@ using boostbook ; boostbook standalone : array.xml : boost.root=../../../.. ; + +############################################################################### +alias boostdoc + : array.xml + : + : + : ; +explicit boostdoc ; +alias boostrelease ; +explicit boostrelease ; From 5d06f1074a00fa69d31f41c0d62ab9ba8db75975 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Tue, 24 Jan 2017 02:31:27 +0400 Subject: [PATCH 17/17] Fix compilation for Oracle Studio 12.5 The compiler expects a qualified dependent name after `typename`, so move `const` after the name. --- include/boost/array.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 3ac0ffc..210c072 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -373,7 +373,7 @@ namespace boost { // Specific for boost::array: simply returns its elems data member. template - typename const detail::c_array::type& get_c_array(const boost::array& arg) + typename detail::c_array::type const& get_c_array(const boost::array& arg) { return arg.elems; }