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; +} +