forked from boostorg/array
Added cbegin and cend to Boost.Array; refs #4761. Will close ticket when merged to release branch
[SVN r67478]
This commit is contained in:
@ -13,6 +13,7 @@
|
|||||||
* accompanying file LICENSE_1_0.txt or copy at
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
* 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.
|
* 10 Mar 2010 - (mtc) fill method added, matching resolution of the standard library working group.
|
||||||
* See <http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#776> or Trac issue #3168
|
* See <http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#776> or Trac issue #3168
|
||||||
* Eventually, we should remove "assign" which is now a synonym for "fill" (Marshall Clow)
|
* Eventually, we should remove "assign" which is now a synonym for "fill" (Marshall Clow)
|
||||||
@ -71,8 +72,11 @@ namespace boost {
|
|||||||
// iterator support
|
// iterator support
|
||||||
iterator begin() { return elems; }
|
iterator begin() { return elems; }
|
||||||
const_iterator begin() const { return elems; }
|
const_iterator begin() const { return elems; }
|
||||||
|
const_iterator cbegin() const { return elems; }
|
||||||
|
|
||||||
iterator end() { return elems+N; }
|
iterator end() { return elems+N; }
|
||||||
const_iterator end() const { return elems+N; }
|
const_iterator end() const { return elems+N; }
|
||||||
|
const_iterator cend() const { return elems+N; }
|
||||||
|
|
||||||
// reverse iterator support
|
// reverse iterator support
|
||||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
|
||||||
@ -202,8 +206,11 @@ namespace boost {
|
|||||||
// iterator support
|
// iterator support
|
||||||
iterator begin() { return iterator( reinterpret_cast< T * >( this ) ); }
|
iterator begin() { return iterator( reinterpret_cast< T * >( this ) ); }
|
||||||
const_iterator begin() const { return const_iterator( reinterpret_cast< const 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(); }
|
iterator end() { return begin(); }
|
||||||
const_iterator end() const { return begin(); }
|
const_iterator end() const { return begin(); }
|
||||||
|
const_iterator cend() const { return cbegin(); }
|
||||||
|
|
||||||
// reverse iterator support
|
// reverse iterator support
|
||||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
|
||||||
|
@ -56,9 +56,15 @@ void RunTests()
|
|||||||
if( test_case.begin() != test_case.end() ) {
|
if( test_case.begin() != test_case.end() ) {
|
||||||
fail_test( "Not an empty range" );
|
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() ) {
|
if( const_test_case.begin() != const_test_case.end() ) {
|
||||||
fail_test( "Not an empty range" );
|
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() ) {
|
if( test_case.begin() == const_test_case.begin() ) {
|
||||||
fail_test( "iterators for different containers are not distinct" );
|
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
|
// 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.begin(), test_case.end(), BadValue< T > );
|
||||||
std::for_each( test_case.rbegin(), test_case.rend(), 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.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.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
|
// Check swap is well formed
|
||||||
std::swap( test_case, test_case );
|
std::swap( test_case, test_case );
|
||||||
|
Reference in New Issue
Block a user