forked from boostorg/array
Add support for std::get<> to Boost.Array
[SVN r82083]
This commit is contained in:
@ -42,6 +42,7 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
#include <boost/swap.hpp>
|
#include <boost/swap.hpp>
|
||||||
|
|
||||||
// Handles broken standard libraries better than <iterator>
|
// Handles broken standard libraries better than <iterator>
|
||||||
@ -438,6 +439,22 @@ namespace boost {
|
|||||||
|
|
||||||
} /* 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 <size_t Idx, typename T, size_t N>
|
||||||
|
T &get(boost::array<T,N> &arr) BOOST_NOEXCEPT {
|
||||||
|
BOOST_STATIC_ASSERT_MSG ( Idx < N, "std::get<>(boost::array &) index out of range" );
|
||||||
|
return arr[Idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t Idx, typename T, size_t N>
|
||||||
|
const T &get(const boost::array<T,N> &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)
|
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||||
# pragma warning(pop)
|
# pragma warning(pop)
|
||||||
|
@ -12,5 +12,6 @@ test-suite array :
|
|||||||
[ run array4.cpp ]
|
[ run array4.cpp ]
|
||||||
[ run array5.cpp ]
|
[ run array5.cpp ]
|
||||||
[ run array6.cpp ]
|
[ run array6.cpp ]
|
||||||
|
[ run array7.cpp ]
|
||||||
[ run array_hash.cpp ]
|
[ run array_hash.cpp ]
|
||||||
;
|
;
|
||||||
|
54
test/array7.cpp
Normal file
54
test/array7.cpp
Normal file
@ -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 <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/array.hpp>
|
||||||
|
#include <algorithm>
|
||||||
|
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
||||||
|
#include <array>
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user