*** empty log message ***

[SVN r27148]
This commit is contained in:
Thorsten Jørgen Ottosen
2005-02-05 20:07:02 +00:00
parent ed09875157
commit d82d9b9680
13 changed files with 165 additions and 259 deletions

View File

@ -28,31 +28,33 @@
a rich subset of Container interface. a rich subset of Container interface.
*/ */
namespace boost {
namespace range_detail namespace boost
{
namespace iterator_range_detail
{ {
template< class Left, class Right > template< class Left, class Right >
inline bool equal( const Left& l, const Right& r ) inline bool equal( const Left& l, const Right& r )
{ {
typedef BOOST_DEDUCED_TYPENAME range_size<Left>::type sz_type; typedef BOOST_DEDUCED_TYPENAME boost::range_size<Left>::type sz_type;
sz_type l_size = boost::size( l ),
r_size = boost::size( r ); sz_type l_size = size( l ),
r_size = size( r );
if( l_size != r_size ) if( l_size != r_size )
return false; return false;
return std::equal( boost::begin(l), boost::end(l), return std::equal( begin(l), end(l),
boost::begin(r) ); begin(r) );
} }
template< class Left, class Right > template< class Left, class Right >
inline bool less_than( const Left& l, const Right& r ) inline bool less_than( const Left& l, const Right& r )
{ {
return std::lexicographical_compare( boost::begin(l), return std::lexicographical_compare( begin(l),
boost::end(l), end(l),
boost::begin(r), begin(r),
boost::end(r) ); end(r) );
} }
} }
@ -195,7 +197,7 @@ namespace boost {
bool operator==( const iterator_range& r ) const bool operator==( const iterator_range& r ) const
{ {
return range_detail::equal( *this, r ); return iterator_range_detail::equal( *this, r );
} }
bool operator!=( const iterator_range& r ) const bool operator!=( const iterator_range& r ) const
@ -205,7 +207,7 @@ namespace boost {
bool operator<( const iterator_range& r ) const bool operator<( const iterator_range& r ) const
{ {
return range_detail::less_than( *this, r ); return iterator_range_detail::less_than( *this, r );
} }
#endif #endif
@ -220,7 +222,8 @@ namespace boost {
value_type& back() const value_type& back() const
{ {
BOOST_ASSERT( !empty() ); BOOST_ASSERT( !empty() );
return *--m_End; IteratorT last( m_End );
return *--last;
} }
value_type& operator[]( size_type sz ) const value_type& operator[]( size_type sz ) const
@ -230,42 +233,7 @@ namespace boost {
return m_Begin[sz]; return m_Begin[sz];
} }
value_type& at( size_type sz ) const protected:
{
//BOOST_STATIC_ASSERT( is_random_access );
if( sz < size() )
throw "foo";
return m_Begin[sz];
}
void advance( size_type sz )
{
BOOST_ASSERT( sz <= size() );
std::advance( m_Begin, sz );
}
void narrow( size_type left, size_type right )
{
BOOST_ASSERT( left + right <= size() );
std::advance( m_Begin, left );
std::advance( m_End, -right );
}
public: // iterable
iterator_range& operator++()
{
BOOST_ASSERT( !empty() );
++m_End;
return *this;
}
value_type& operator*() const
{
BOOST_ASSERT( !empty() );
return front();
}
private:
template< class ForwardRange > template< class ForwardRange >
iterator adl_begin( ForwardRange& r ) iterator adl_begin( ForwardRange& r )
{ {
@ -332,21 +300,21 @@ namespace boost {
inline bool operator==( const ForwardRange& l, inline bool operator==( const ForwardRange& l,
const iterator_range<IteratorT>& r ) const iterator_range<IteratorT>& r )
{ {
return range_detail::equal( l, r ); return iterator_range_detail::equal( l, r );
} }
template< class IteratorT, class ForwardRange > template< class IteratorT, class ForwardRange >
inline bool operator!=( const ForwardRange& l, inline bool operator!=( const ForwardRange& l,
const iterator_range<IteratorT>& r ) const iterator_range<IteratorT>& r )
{ {
return !range_detail::equal( l, r ); return !iterator_range_detail::equal( l, r );
} }
template< class IteratorT, class ForwardRange > template< class IteratorT, class ForwardRange >
inline bool operator<( const ForwardRange& l, inline bool operator<( const ForwardRange& l,
const iterator_range<IteratorT>& r ) const iterator_range<IteratorT>& r )
{ {
return range_detail::less_than( l, r ); return iterator_range_detail::less_than( l, r );
} }
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING #ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
@ -355,14 +323,14 @@ namespace boost {
inline bool operator==( const iterator_range<Iterator1T>& l, inline bool operator==( const iterator_range<Iterator1T>& l,
const iterator_range<Iterator2T>& r ) const iterator_range<Iterator2T>& r )
{ {
return range_detail::equal( l, r ); return iterator_range_detail::equal( l, r );
} }
template< class IteratorT, class ForwardRange > template< class IteratorT, class ForwardRange >
inline bool operator==( const iterator_range<IteratorT>& l, inline bool operator==( const iterator_range<IteratorT>& l,
const ForwardRange& r ) const ForwardRange& r )
{ {
return range_detail::equal( l, r ); return iterator_range_detail::equal( l, r );
} }
@ -370,14 +338,14 @@ namespace boost {
inline bool operator!=( const iterator_range<Iterator1T>& l, inline bool operator!=( const iterator_range<Iterator1T>& l,
const iterator_range<Iterator2T>& r ) const iterator_range<Iterator2T>& r )
{ {
return !range_detail::equal( l, r ); return !iterator_range_detail::equal( l, r );
} }
template< class IteratorT, class ForwardRange > template< class IteratorT, class ForwardRange >
inline bool operator!=( const iterator_range<IteratorT>& l, inline bool operator!=( const iterator_range<IteratorT>& l,
const ForwardRange& r ) const ForwardRange& r )
{ {
return !range_detail::equal( l, r ); return !iterator_range_detail::equal( l, r );
} }
@ -385,16 +353,16 @@ namespace boost {
inline bool operator<( const iterator_range<Iterator1T>& l, inline bool operator<( const iterator_range<Iterator1T>& l,
const iterator_range<Iterator2T>& r ) const iterator_range<Iterator2T>& r )
{ {
return range_detail::less_than( l, r ); return iterator_range_detail::less_than( l, r );
} }
template< class IteratorT, class ForwardRange > template< class IteratorT, class ForwardRange >
inline bool operator<( const iterator_range<IteratorT>& l, inline bool operator<( const iterator_range<IteratorT>& l,
const ForwardRange& r ) const ForwardRange& r )
{ {
return range_detail::less_than( l, r ); return iterator_range_detail::less_than( l, r );
} }
#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING #endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
// iterator range utilities -----------------------------------------// // iterator range utilities -----------------------------------------//
@ -413,8 +381,7 @@ namespace boost {
{ {
return iterator_range<IteratorT>( Begin, End ); return iterator_range<IteratorT>( Begin, End );
} }
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING #ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
template< typename Range > template< typename Range >
@ -447,6 +414,62 @@ namespace boost {
( r ); ( r );
} }
#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
namespace iterator_range_detail
{
template< class Range >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_result_iterator<Range>::type >
make_range_impl( Range& r,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_begin,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_end )
{
if( advance_begin == 0 && advance_end == 0 )
return make_iterator_range( r );
BOOST_DEDUCED_TYPENAME range_result_iterator<Range>::type
new_begin = begin( r ),
new_end = end( r );
std::advance( new_begin, advance_begin );
std::advance( new_end, advance_end );
return make_iterator_range( new_begin, new_end );
}
}
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
template< class Range >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_result_iterator<Range>::type >
make_iterator_range( Range& r,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_begin,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_end )
{
//BOOST_ASSERT( advance_begin - advance_end <= size(r) && "creating invalid range" );
return iterator_range_detail::make_range_impl( r, advance_begin, advance_end );
}
#else
template< class Range >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<Range>::type >
make_iterator_range( Range& r,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_begin,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_end )
{
//BOOST_ASSERT( advance_begin - advance_end <= size(r) && "creating invalid range" );
return iterator_range_detail::make_range_impl( r, advance_begin, advance_end );
}
template< class Range >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_const_iterator<Range>::type >
make_iterator_range( const Range& r,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_begin,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_end )
{
//BOOST_ASSERT( advance_begin - advance_end <= size(r) && "creating invalid range" );
return iterator_range_detail::make_range_impl( r, advance_begin, advance_end );
}
#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING #endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
//! copy a range into a sequence //! copy a range into a sequence

View File

@ -43,7 +43,7 @@ namespace boost
sub_range( ForwardRange2& r ) : sub_range( ForwardRange2& r ) :
#if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 ) #if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 )
base( boost::begin( r ), boost::end( r ) ) base( this->adl_begin( r ), this->adl_end( r ) )
#else #else
base( r ) base( r )
#endif #endif
@ -53,7 +53,7 @@ namespace boost
sub_range( const ForwardRange2& r ) : sub_range( const ForwardRange2& r ) :
#if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 ) #if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 )
base( boost::begin( r ), boost::end( r ) ) base( this->adl_begin( r ), this->adl_end( r ) )
#else #else
base( r ) base( r )
#endif #endif
@ -90,91 +90,55 @@ namespace boost
public: // convenience public: // convenience
value_type& front() value_type& front()
{ {
BOOST_ASSERT( !empty() ); return base::front();
return *m_Begin;
} }
const value_type& front() const const value_type& front() const
{ {
BOOST_ASSERT( !empty() ); return base::front();
return *m_Begin;
} }
value_type& back() value_type& back()
{ {
BOOST_ASSERT( !empty() ); return base::back();
return *--m_End;
} }
const value_type& back() const const value_type& back() const
{ {
BOOST_ASSERT( !empty() ); return base::back();
return *--m_End;
} }
value_type& operator[]( size_type sz ) value_type& operator[]( size_type sz )
{ {
//BOOST_STATIC_ASSERT( is_random_access ); return base::operator[](sz);
BOOST_ASSERT( sz < size() );
return m_Begin[sz];
} }
const value_type& operator[]( size_type sz ) const const value_type& operator[]( size_type sz ) const
{ {
//BOOST_STATIC_ASSERT( is_random_access ); return base::operator[](sz);
BOOST_ASSERT( sz < size() );
return m_Begin[sz];
} }
value_type& at( size_type sz )
{
//BOOST_STATIC_ASSERT( is_random_access );
if( sz < size() )
throw "foo";
return m_Begin[sz];
}
const value_type& at( size_type sz ) const
{
//BOOST_STATIC_ASSERT( is_random_access );
if( sz < size() )
throw "foo";
return m_Begin[sz];
}
public: // iterable
value_type& operator*()
{
BOOST_ASSERT( !empty() );
return front();
}
const value_type& operator*() const
{
BOOST_ASSERT( !empty() );
return front();
}
}; };
template< class ForwardRange, class ForwardRange2 > template< class ForwardRange, class ForwardRange2 >
inline bool operator==( const sub_range<ForwardRange>& l, inline bool operator==( const sub_range<ForwardRange>& l,
const sub_range<ForwardRange2>& r ) const sub_range<ForwardRange2>& r )
{ {
return range_detail::equal( l, r ); return iterator_range_detail::equal( l, r );
} }
template< class ForwardRange, class ForwardRange2 > template< class ForwardRange, class ForwardRange2 >
inline bool operator!=( const sub_range<ForwardRange>& l, inline bool operator!=( const sub_range<ForwardRange>& l,
const sub_range<ForwardRange2>& r ) const sub_range<ForwardRange2>& r )
{ {
return !range_detail::equal( l, r ); return !iterator_range_detail::equal( l, r );
} }
template< class ForwardRange, class ForwardRange2 > template< class ForwardRange, class ForwardRange2 >
inline bool operator<( const sub_range<ForwardRange>& l, inline bool operator<( const sub_range<ForwardRange>& l,
const sub_range<ForwardRange2>& r ) const sub_range<ForwardRange2>& r )
{ {
return range_detail::less_than( l, r ); return iterator_range_detail::less_than( l, r );
} }

View File

@ -10,94 +10,28 @@
subproject libs/range/test ; subproject libs/range/test ;
SEARCH on testing.jam = $(BOOST_BUILD_PATH) ; import testing ;
include testing.jam ;
DEPENDS all : test ;
rule range-test ( name )
{ {
test-suite range return [
: [ run run $(name).cpp
array.cpp <lib>../../test/build/boost_unit_test_framework
: : : : : <include>$(BOOST_ROOT)
: ] ;
: array_test }
]
[ run
iterator_pair.cpp
: :
:
: iterator_pair_test
]
[ run
std_container.cpp
: :
:
: std_container_test
]
[ run
string.cpp
: :
:
: string_test
]
[ run
iterator_range.cpp
: :
:
: iterator_range
]
[ run
sub_range.cpp
: :
:
: sub_range
]
[ run test-suite range :
partial_workaround.cpp [ range-test array ]
: : [ range-test iterator_pair ]
: [ range-test std_container ]
: workaround_test [ range-test string ]
] [ range-test iterator_range ]
[ run [ range-test sub_range ]
algorithm_example.cpp [ range-test partial_workaround ]
: : [ range-test algorithm_example ]
: [ range-test reversible_range ]
: example_test [ range-test const_ranges ]
]
[ run
reversible_range.cpp
: :
:
: reversible_range_test
]
[ run
const_ranges.cpp
: :
:
: const_ranges
]
# [ run
# compat3.cpp
# : :
# :
# : compat3_test
# ]
#
# [ run
# adl_conformance.cpp
# : :
# :
# : adl_conformance
# ]
# [ run
# adl_conformance_no_using.cpp
# : :
# :
# : adl_conformance_no_using_declaration
# ]
; ;
}

View File

@ -17,7 +17,6 @@
#include <boost/range/functions.hpp> #include <boost/range/functions.hpp>
#include <boost/range/metafunctions.hpp> #include <boost/range/metafunctions.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/test_tools.hpp> #include <boost/test/test_tools.hpp>
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
@ -80,9 +79,8 @@ void check_algorithm()
} }
#include <boost/test/included/unit_test_framework.hpp> #include <boost/test/unit_test.hpp>
using boost::unit_test::test_suite;
using boost::unit_test_framework::test_suite;
test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite* init_unit_test_suite( int argc, char* argv[] )
{ {

View File

@ -19,15 +19,9 @@
#include <boost/range.hpp> #include <boost/range.hpp>
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <boost/type_traits.hpp> #include <boost/type_traits.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/test_tools.hpp> #include <boost/test/test_tools.hpp>
#include <iostream> #include <iostream>
// This should be included before "using namespace boost",
// otherwise gcc headers will be confused with boost::iterator
// namespace.
#include <boost/test/included/unit_test_framework.hpp>
using namespace boost; using namespace boost;
using namespace std; using namespace std;
@ -69,9 +63,8 @@ void check_array()
} }
#include <boost/test/unit_test.hpp>
using boost::unit_test::test_suite;
using boost::unit_test_framework::test_suite;
test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite* init_unit_test_suite( int argc, char* argv[] )
{ {

View File

@ -17,13 +17,9 @@
#endif #endif
#include <boost/range.hpp> #include <boost/range.hpp>
#include <boost/test/test_tools.hpp>
#include <string> #include <string>
// This should be included before "using namespace boost",
// otherwise gcc headers will be confused with boost::iterator
// namespace.
#include <boost/test/included/unit_test_framework.hpp>
using namespace boost; using namespace boost;
using namespace std; using namespace std;
@ -52,7 +48,8 @@ void check_const_ranges()
using boost::unit_test_framework::test_suite; #include <boost/test/unit_test.hpp>
using boost::unit_test::test_suite;
test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite* init_unit_test_suite( int argc, char* argv[] )
{ {

View File

@ -19,12 +19,10 @@
#include <boost/range/metafunctions.hpp> #include <boost/range/metafunctions.hpp>
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <boost/type_traits.hpp> #include <boost/type_traits.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/test_tools.hpp> #include <boost/test/test_tools.hpp>
#include <vector> #include <vector>
using namespace boost; using namespace boost;
using boost::unit_test_framework::test_suite;
void check_iterator_pair() void check_iterator_pair()
{ {
@ -79,10 +77,8 @@ void check_iterator_pair()
} }
#include <boost/test/unit_test.hpp>
#include <boost/test/included/unit_test_framework.hpp> using boost::unit_test::test_suite;
using boost::unit_test_framework::test_suite;
test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite* init_unit_test_suite( int argc, char* argv[] )
{ {

View File

@ -16,18 +16,13 @@
# pragma warn -8057 // unused argument argc/argv in Boost.Test # pragma warn -8057 // unused argument argc/argv in Boost.Test
#endif #endif
#include <boost/range/iterator_range.hpp> #include <boost/range/iterator_range.hpp>
#include <boost/range/functions.hpp> #include <boost/range/functions.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/test_tools.hpp> #include <boost/test/test_tools.hpp>
#include <iostream> #include <iostream>
#include <string> #include <string>
// This should be included before "using namespace boost",
// otherwise gcc headers will be confused with boost::iterator
// namespace.
#include <boost/test/included/unit_test_framework.hpp>
using namespace boost; using namespace boost;
using namespace std; using namespace std;
@ -85,10 +80,21 @@ void check_iterator_range()
BOOST_CHECK( rrr == rr ); BOOST_CHECK( rrr == rr );
BOOST_CHECK( !( rrr != rr ) ); BOOST_CHECK( !( rrr != rr ) );
BOOST_CHECK( !( rrr < rr ) ); BOOST_CHECK( !( rrr < rr ) );
const irange cr = make_iterator_range( str );
BOOST_CHECK_EQUAL( cr.front(), 'h' );
BOOST_CHECK_EQUAL( cr.back(), 'd' );
BOOST_CHECK_EQUAL( cr[1], 'e' );
rrr = make_iterator_range( str, 1, -1 );
BOOST_CHECK( rrr == "ello worl" );
rrr = make_iterator_range( rrr, -1, 1 );
BOOST_CHECK( rrr == str );
} }
using boost::unit_test_framework::test_suite; #include <boost/test/unit_test.hpp>
using boost::unit_test::test_suite;
test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite* init_unit_test_suite( int argc, char* argv[] )
{ {

View File

@ -33,7 +33,6 @@
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <boost/type_traits.hpp> #include <boost/type_traits.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/test_tools.hpp> #include <boost/test/test_tools.hpp>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
@ -92,9 +91,8 @@ void check_partial_workaround()
} }
#include <boost/test/included/unit_test_framework.hpp> #include <boost/test/unit_test.hpp>
using boost::unit_test::test_suite;
using boost::unit_test_framework::test_suite;
test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite* init_unit_test_suite( int argc, char* argv[] )
{ {

View File

@ -22,7 +22,6 @@
#include <boost/range/end.hpp> #include <boost/range/end.hpp>
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <boost/type_traits.hpp> #include <boost/type_traits.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/test_tools.hpp> #include <boost/test/test_tools.hpp>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
@ -82,10 +81,9 @@ void check_iterator()
} }
#include <boost/test/unit_test.hpp>
using boost::unit_test::test_suite;
#include <boost/test/included/unit_test_framework.hpp>
using boost::unit_test_framework::test_suite;
test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite* init_unit_test_suite( int argc, char* argv[] )
{ {

View File

@ -20,7 +20,6 @@
#include <boost/range/metafunctions.hpp> #include <boost/range/metafunctions.hpp>
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <boost/type_traits.hpp> #include <boost/type_traits.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/test_tools.hpp> #include <boost/test/test_tools.hpp>
#include <vector> #include <vector>
@ -61,11 +60,8 @@ void check_std_container()
} }
#include <boost/test/unit_test.hpp>
using boost::unit_test::test_suite;
#include <boost/test/included/unit_test_framework.hpp>
using boost::unit_test_framework::test_suite;
test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite* init_unit_test_suite( int argc, char* argv[] )
{ {

View File

@ -22,7 +22,6 @@
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <boost/type_traits.hpp> #include <boost/type_traits.hpp>
#include <boost/test/test_tools.hpp> #include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
#include <vector> #include <vector>
#include <fstream> #include <fstream>
@ -184,12 +183,10 @@ void check_string()
} }
#include <boost/test/unit_test.hpp>
using boost::unit_test::test_suite;
#include <boost/test/included/unit_test_framework.hpp>
using boost::unit_test_framework::test_suite;
test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite* init_unit_test_suite( int argc, char* argv[] )
{ {
test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );

View File

@ -16,19 +16,12 @@
# pragma warn -8057 // unused argument argc/argv in Boost.Test # pragma warn -8057 // unused argument argc/argv in Boost.Test
#endif #endif
#include <boost/range/iterator_range.hpp>
#include <boost/range/sub_range.hpp> #include <boost/range/sub_range.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/test_tools.hpp> #include <boost/test/test_tools.hpp>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <vector> #include <vector>
// This should be included before "using namespace boost",
// otherwise gcc headers will be confused with boost::iterator
// namespace.
#include <boost/test/included/unit_test_framework.hpp>
using namespace boost; using namespace boost;
using namespace std; using namespace std;
@ -41,10 +34,9 @@ struct add_one
} }
}; };
void check_iterator_range() void check_sub_range()
{ {
typedef string::iterator iterator; typedef string::iterator iterator;
typedef string::const_iterator const_iterator; typedef string::const_iterator const_iterator;
typedef iterator_range<iterator> irange; typedef iterator_range<iterator> irange;
@ -139,16 +131,30 @@ void check_iterator_range()
BOOST_CHECK( rrr == rr ); BOOST_CHECK( rrr == rr );
BOOST_CHECK( !( rrr != rr ) ); BOOST_CHECK( !( rrr != rr ) );
BOOST_CHECK( !( rrr < rr ) ); BOOST_CHECK( !( rrr < rr ) );
}
const irange cr = make_iterator_range( str );
BOOST_CHECK_EQUAL( cr.front(), 'h' );
BOOST_CHECK_EQUAL( cr.back(), 'd' );
BOOST_CHECK_EQUAL( cr[1], 'e' );
using boost::unit_test_framework::test_suite; rrr = make_iterator_range( str, 1, -1 );
BOOST_CHECK( rrr == "ello worl" );
rrr = make_iterator_range( rrr, -1, 1 );
BOOST_CHECK( rrr == str );
rrr.front() = 'H';
rrr.back() = 'D';
rrr[1] = 'E';
BOOST_CHECK( rrr == "HEllo worlD" );
}
#include <boost/test/unit_test.hpp>
using boost::unit_test::test_suite;
test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite* init_unit_test_suite( int argc, char* argv[] )
{ {
test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
test->add( BOOST_TEST_CASE( &check_iterator_range ) ); test->add( BOOST_TEST_CASE( &check_sub_range ) );
return test; return test;
} }