diff --git a/include/boost/range/detail/const_iterator.hpp b/include/boost/range/detail/const_iterator.hpp index e7824d5..503804d 100755 --- a/include/boost/range/detail/const_iterator.hpp +++ b/include/boost/range/detail/const_iterator.hpp @@ -12,6 +12,7 @@ #define BOOST_RANGE_DETAIL_CONST_ITERATOR_HPP #include +#include ////////////////////////////////////////////////////////////////////////////// // missing partial specialization workaround. @@ -51,7 +52,8 @@ namespace boost template< typename T > struct pts { - typedef void /*dummy*/ type; + typedef const BOOST_RANGE_DEDUCED_TYPENAME + remove_bounds::type* type; }; }; @@ -61,7 +63,8 @@ namespace boost template< typename T > struct pts { - typedef void /*dummy*/ type; + typedef const BOOST_RANGE_DEDUCED_TYPENAME + remove_bounds::type* type; }; }; diff --git a/include/boost/range/detail/iterator.hpp b/include/boost/range/detail/iterator.hpp index 377f442..506778c 100755 --- a/include/boost/range/detail/iterator.hpp +++ b/include/boost/range/detail/iterator.hpp @@ -12,6 +12,7 @@ #define BOOST_RANGE_DETAIL_ITERATOR_HPP #include +#include ////////////////////////////////////////////////////////////////////////////// // missing partial specialization workaround. @@ -50,7 +51,8 @@ namespace boost template< typename T > struct pts { - typedef void /*dummy*/ type; + typedef BOOST_RANGE_DEDUCED_TYPENAME + remove_bounds::type* type; }; }; @@ -60,7 +62,8 @@ namespace boost template< typename T > struct pts { - typedef void /*dummy*/ type; + typedef BOOST_RANGE_DEDUCED_TYPENAME + remove_bounds::type* type; }; }; diff --git a/include/boost/range/iterator_range.hpp b/include/boost/range/iterator_range.hpp index 95403b7..d3c08a2 100755 --- a/include/boost/range/iterator_range.hpp +++ b/include/boost/range/iterator_range.hpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include diff --git a/include/boost/range/sub_range.hpp b/include/boost/range/sub_range.hpp index 634780a..8b1963a 100755 --- a/include/boost/range/sub_range.hpp +++ b/include/boost/range/sub_range.hpp @@ -14,11 +14,8 @@ #include #include #include -#include #include #include -//#include -//#include namespace boost { @@ -26,6 +23,7 @@ namespace boost template< class Range > class sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME result_iterator_of::type > { + typedef BOOST_DEDUCED_TYPENAME result_iterator_of::type iterator_t; typedef iterator_range< iterator_t > base; @@ -66,61 +64,12 @@ namespace boost size_type size() const { - // - // performance discontinuity problem!! - // return base::size(); } + }; - - - /* - template< class Range > - class reverse_sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME reverse_result_iterator_of::type > - { - typedef BOOST_DEDUCED_TYPENAME reverse_result_iterator_of::type - iterator_t; - typedef iterator_range base; - public: - using base::iterator; - using base::const_iterator; - using base::value_type; - using base::difference_type; - using base::size_type; - - public: - template< class Range2 > - reverse_sub_range( Range2& r ) : base( rbegin( r ), rend( r ) ) - { } - - template< class Range2 > - reverse_sub_range( const Range2& r ) : base( rbegin( r ), rend( r ) ) - { } - - template< class Iter > - reverse_sub_range( Iter first, Iter last ) : - base( iterator_t( last ), iterator_t( first ) ) - { } - - template< class Range2 > - sub_range& operator=( Range2& r ) - { - base::operator=( r ); - return *this; - } - - template< class Range2 > - sub_range& operator=( const Range2& r ) - { - base::operator=( r ); - return *this; - } - - }; - */ - } // namespace 'boost' #endif diff --git a/test/sub_range.cpp b/test/sub_range.cpp new file mode 100755 index 0000000..fb59d1e --- /dev/null +++ b/test/sub_range.cpp @@ -0,0 +1,100 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen 2003-2004. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/range/ +// + +#include +#include +#include +#include +#include +#include + +// This should be included before "using namespace boost", +// otherwise gcc headers will be confused with boost::iterator +// namespace. +#include + +using namespace boost; +using namespace std; + +struct add_one +{ + template< class T > + T operator()( T r ) const + { + return r + 1; + } +}; + +void check_iterator_range() +{ + + + typedef string::iterator iterator; + typedef string::const_iterator const_iterator; + typedef iterator_range irange; + typedef iterator_range cirange; + string str = "hello world"; + const string cstr = "const world"; + irange r = make_iterator_range( str ); + r = make_iterator_range( str.begin(), str.end() ); + cirange r2 = make_iterator_range( cstr ); + r2 = make_iterator_range( cstr.begin(), cstr.end() ); + r2 = make_iterator_range( str ); + + typedef sub_range srange; + typedef sub_range csrange; + srange s = r; + BOOST_CHECK( r == s ); + s = make_iterator_range( str ); + csrange s2 = r; + s2 = r2; + s2 = make_iterator_range( cstr ); + BOOST_CHECK( r != s2 ); + s2 = make_iterator_range( str ); + + BOOST_CHECK( r.begin() == s.begin() ); + BOOST_CHECK( r2.begin()== s2.begin() ); + BOOST_CHECK( r.end() == s.end() ); + BOOST_CHECK( r2.end() == s2.end() ); + BOOST_CHECK_EQUAL( r.size(), s.size() ); + BOOST_CHECK_EQUAL( r2.size(), s2.size() ); + + if( !r ) + BOOST_CHECK( false ); + if( !r2 ) + BOOST_CHECK( false ); + if( !s ) + BOOST_CHECK( false ); + if( !s2 ) + BOOST_CHECK( false ); + + cout << r << r2 << s << s2; + + string res = copy_range( r ); + BOOST_CHECK( equal( res.begin(), res.end(), r.begin() ) ); + +} + + +using boost::unit_test_framework::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); + + test->add( BOOST_TEST_CASE( &check_iterator_range ) ); + + return test; +} + + + + +