Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82083 - in trunk: boost libs/array/test
From: marshall_at_[hidden]
Date: 2012-12-18 12:59:09


Author: marshall
Date: 2012-12-18 12:59:08 EST (Tue, 18 Dec 2012)
New Revision: 82083
URL: http://svn.boost.org/trac/boost/changeset/82083

Log:
Add support for std::get<> to Boost.Array
Added:
   trunk/libs/array/test/array7.cpp (contents, props changed)
Text files modified:
   trunk/boost/array.hpp | 17 +++++++++++++++++
   trunk/libs/array/test/Jamfile.v2 | 1 +
   2 files changed, 18 insertions(+), 0 deletions(-)

Modified: trunk/boost/array.hpp
==============================================================================
--- trunk/boost/array.hpp (original)
+++ trunk/boost/array.hpp 2012-12-18 12:59:08 EST (Tue, 18 Dec 2012)
@@ -42,6 +42,7 @@
 #include <cstddef>
 #include <stdexcept>
 #include <boost/assert.hpp>
+#include <boost/static_assert.hpp>
 #include <boost/swap.hpp>
 
 // Handles broken standard libraries better than <iterator>
@@ -438,6 +439,22 @@
 
 } /* 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)
 # pragma warning(pop)

Modified: trunk/libs/array/test/Jamfile.v2
==============================================================================
--- trunk/libs/array/test/Jamfile.v2 (original)
+++ trunk/libs/array/test/Jamfile.v2 2012-12-18 12:59:08 EST (Tue, 18 Dec 2012)
@@ -12,5 +12,6 @@
     [ run array4.cpp ]
     [ run array5.cpp ]
     [ run array6.cpp ]
+ [ run array7.cpp ]
     [ run array_hash.cpp ]
     ;

Added: trunk/libs/array/test/array7.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/array/test/array7.cpp 2012-12-18 12:59:08 EST (Tue, 18 Dec 2012)
@@ -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;
+}
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk