From dc7d30bab6268ce3bf4f7e24300691d12f10593d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Fri, 30 Jul 2004 03:12:22 +0000 Subject: [PATCH] *** empty log message *** [SVN r24177] --- include/boost/range/iterator_range.hpp | 117 ++++++++++++++----------- include/boost/range/sub_range.hpp | 29 +++--- test/sub_range.cpp | 5 +- 3 files changed, 82 insertions(+), 69 deletions(-) diff --git a/include/boost/range/iterator_range.hpp b/include/boost/range/iterator_range.hpp index d3c08a2..b701bd1 100755 --- a/include/boost/range/iterator_range.hpp +++ b/include/boost/range/iterator_range.hpp @@ -51,6 +51,8 @@ namespace boost { template class iterator_range { + iterator_range(); // not implemented + public: //! this type typedef iterator_range type; @@ -75,62 +77,35 @@ namespace boost { //! iterator type typedef IteratorT iterator; - //! Default constructor - iterator_range() {} - //! Constructor from a pair of iterators - iterator_range( iterator Begin, iterator End ) : + template< class Iterator > + iterator_range( Iterator Begin, Iterator End ) : m_Begin(Begin), m_End(End) {} //! Constructor from a Range template< class Range > iterator_range( const Range& r ) : - m_Begin( boost::begin( r ) ), m_End( boost::end( r ) ) {} + m_Begin( begin_impl( r ) ), m_End( end_impl( r ) ) {} //! Constructor from a Range template< class Range > iterator_range( Range& r ) : - m_Begin( boost::begin( r ) ), m_End( boost::end( r ) ) {} - - //! Copy constructor -- default OK - - //! Templated copy constructor - /*! - This constructor is provided to allow conversion between - const and mutable iterator instances of this class template - */ - template< typename OtherItT > - iterator_range( const iterator_range& Other ) : - m_Begin(Other.begin()), m_End(Other.end()) {} - - //! Assignment operator -- defefault OK - - //! Assignment operator ( templated version ) - template< typename OtherItT > - iterator_range& operator=( const iterator_range& Other ) + m_Begin( begin_impl( r ) ), m_End( end_impl( r ) ) {} + + template< class XRange > + iterator_range& operator=( XRange& r ) { - m_Begin=Other.begin(); m_End=Other.end(); + m_Begin = begin_impl( r ); + m_End = end_impl( r ); return *this; } - - //! Comparison operator ( equal ) - /*! - Compare operands for equality - */ - template< typename OtherItT > - bool operator==( const iterator_range& Other ) const - { - return ! (*this != Other); - } - //! Comparison operator ( not-equal ) - /*! - Compare operands for non-equality - */ - template< typename OtherItT > - bool operator!=( const iterator_range& Other ) const + template< class XRange > + iterator_range& operator=( const XRange& r ) { - return m_Begin!=Other.begin() || m_End!=Other.end(); + m_Begin = begin_impl( r ); + m_End = end_impl( r ); + return *this; } //! begin access @@ -203,6 +178,22 @@ namespace boost { // begin and end iterators IteratorT m_Begin; IteratorT m_End; + + private: + template< class XRange > + iterator end_impl( XRange& r ) const + { + using boost::end; + return end( r ); + } + + template< class XRange > + iterator begin_impl( XRange& r ) const + { + using boost::begin; + return begin( r ); + } + }; // iterator range free-standing operators ---------------------------// @@ -213,15 +204,35 @@ namespace boost { in a sequence without separators. */ template< typename IteratorT, typename Elem, typename Traits > - std::basic_ostream& operator<<( - std::basic_ostream& Os, - const iterator_range& r ) + inline std::basic_ostream& operator<<( + std::basic_ostream& Os, + const iterator_range& r ) { std::copy( begin(r), end(r), std::ostream_iterator(Os)); - return Os; } + //! Comparison operator ( equal ) + /*! + Compare operands for equality + */ + template< class IteratorT > + inline bool operator==( const iterator_range& l, + const iterator_range& r ) + { + return ! (l != r); + } + + //! Comparison operator ( not-equal ) + /*! + Compare operands for non-equality + */ + template< class IteratorT > + inline bool operator!=( const iterator_range& l, + const iterator_range& r ) + { + return l.begin() != r.begin() || l.end() != r.end(); + } // iterator range utilities -----------------------------------------// @@ -256,19 +267,19 @@ namespace boost { Construct an \c iterator_range from a \c Range containing the begin and end iterators. */ - template< typename Range > - inline iterator_range< BOOST_DEDUCED_TYPENAME iterator_of::type > - make_iterator_range( Range& r ) + template< class XRange > + inline iterator_range< BOOST_DEDUCED_TYPENAME iterator_of::type > + make_iterator_range( XRange& r ) { - return iterator_range< BOOST_DEDUCED_TYPENAME iterator_of::type > + return iterator_range< BOOST_DEDUCED_TYPENAME iterator_of::type > ( r ); } - template< typename Range > - inline iterator_range< BOOST_DEDUCED_TYPENAME const_iterator_of::type > - make_iterator_range( const Range& r ) + template< class XRange > + inline iterator_range< BOOST_DEDUCED_TYPENAME const_iterator_of::type > + make_iterator_range( const XRange& r ) { - return iterator_range< BOOST_DEDUCED_TYPENAME const_iterator_of::type > + return iterator_range< BOOST_DEDUCED_TYPENAME const_iterator_of::type > ( r ); } #endif diff --git a/include/boost/range/sub_range.hpp b/include/boost/range/sub_range.hpp index 5e231c7..1de309f 100755 --- a/include/boost/range/sub_range.hpp +++ b/include/boost/range/sub_range.hpp @@ -20,27 +20,28 @@ namespace boost { - template< class Range > - class sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME result_iterator_of::type > + template< class XRange > + class sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME result_iterator_of::type > { - - typedef BOOST_DEDUCED_TYPENAME result_iterator_of::type iterator_t; + sub_range(); // not implemented + + typedef BOOST_DEDUCED_TYPENAME result_iterator_of::type iterator_t; typedef iterator_range< iterator_t > base; public: using base::iterator; using base::const_iterator; using base::value_type; - typedef BOOST_DEDUCED_TYPENAME difference_type_of::type difference_type; - typedef BOOST_DEDUCED_TYPENAME size_type_of::type size_type; + typedef BOOST_DEDUCED_TYPENAME difference_type_of::type difference_type; + typedef BOOST_DEDUCED_TYPENAME size_type_of::type size_type; public: - template< class Range2 > - sub_range( Range2& r ) : base( r ) + template< class XRange2 > + sub_range( XRange2& r ) : base( r ) { } - template< class Range2 > - sub_range( const Range2& r ) : base( r ) + template< class XRange2 > + sub_range( const XRange2& r ) : base( r ) { } template< class Iter > @@ -48,15 +49,15 @@ namespace boost base( first, last ) { } - template< class Range2 > - sub_range& operator=( Range2& r ) + template< class XRange2 > + sub_range& operator=( XRange2& r ) { base::operator=( r ); return *this; } - template< class Range2 > - sub_range& operator=( const Range2& r ) + template< class XRange2 > + sub_range& operator=( const XRange2& r ) { base::operator=( r ); return *this; diff --git a/test/sub_range.cpp b/test/sub_range.cpp index 86313c8..fe3edb8 100755 --- a/test/sub_range.cpp +++ b/test/sub_range.cpp @@ -59,13 +59,14 @@ void check_iterator_range() typedef sub_range srange; typedef sub_range csrange; srange s = r; - BOOST_CHECK( r == s ); + BOOST_CHECK( r == r ); s = make_iterator_range( str ); csrange s2 = r; s2 = r2; s2 = make_iterator_range( cstr ); - BOOST_CHECK( r != s2 ); + BOOST_CHECK( r2 == r2 ); s2 = make_iterator_range( str ); + BOOST_CHECK( !(s != s) ); BOOST_CHECK( r.begin() == s.begin() ); BOOST_CHECK( r2.begin()== s2.begin() );