diff --git a/include/boost/array.hpp b/include/boost/array.hpp index a5bee24..c34478b 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) * + * 28 Dec 2010 - (mtc) Added cbegin and cend for C++Ox compatibility. * 10 Mar 2010 - (mtc) fill method added, matching resolution of the standard library working group. * See or Trac issue #3168 * Eventually, we should remove "assign" which is now a synonym for "fill" (Marshall Clow) @@ -69,10 +70,13 @@ namespace boost { typedef std::ptrdiff_t difference_type; // iterator support - iterator begin() { return elems; } - const_iterator begin() const { return elems; } - iterator end() { return elems+N; } - const_iterator end() const { return elems+N; } + iterator begin() { return elems; } + const_iterator begin() const { return elems; } + const_iterator cbegin() const { return elems; } + + iterator end() { return elems+N; } + const_iterator end() const { return elems+N; } + 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) @@ -200,10 +204,13 @@ namespace boost { typedef std::ptrdiff_t difference_type; // iterator support - iterator begin() { return iterator( reinterpret_cast< T * >( this ) ); } - const_iterator begin() const { return const_iterator( reinterpret_cast< const T * >( this ) ); } - iterator end() { return begin(); } - const_iterator end() const { return begin(); } + iterator begin() { return iterator( reinterpret_cast< T * >( this ) ); } + const_iterator begin() const { return const_iterator( reinterpret_cast< const T * >( this ) ); } + const_iterator cbegin() const { return const_iterator( reinterpret_cast< const T * >( this ) ); } + + iterator end() { return begin(); } + const_iterator end() const { return begin(); } + 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) diff --git a/test/array0.cpp b/test/array0.cpp index 92135f1..d75db76 100644 --- a/test/array0.cpp +++ b/test/array0.cpp @@ -56,9 +56,15 @@ void RunTests() 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" ); @@ -73,8 +79,10 @@ void RunTests() // 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 > ); + std::for_each( test_case.cbegin(), test_case.cend(), BadValue< T > ); std::for_each( const_test_case.begin(), const_test_case.end(), BadValue< T > ); std::for_each( const_test_case.rbegin(), const_test_case.rend(), BadValue< T > ); + std::for_each( const_test_case.cbegin(), const_test_case.cend(), BadValue< T > ); // Check swap is well formed std::swap( test_case, test_case );