*** empty log message ***

[SVN r24177]
This commit is contained in:
Thorsten Jørgen Ottosen
2004-07-30 03:12:22 +00:00
parent b86b99190b
commit dc7d30bab6
3 changed files with 82 additions and 69 deletions

View File

@ -51,6 +51,8 @@ namespace boost {
template<typename IteratorT>
class iterator_range
{
iterator_range(); // not implemented
public:
//! this type
typedef iterator_range<IteratorT> 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 ) ) {}
m_Begin( begin_impl( r ) ), m_End( end_impl( 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<OtherItT>& 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<OtherItT>& Other )
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<OtherItT>& Other ) const
template< class XRange >
iterator_range& operator=( const XRange& r )
{
return ! (*this != Other);
}
//! Comparison operator ( not-equal )
/*!
Compare operands for non-equality
*/
template< typename OtherItT >
bool operator!=( const iterator_range<OtherItT>& Other ) const
{
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<Elem,Traits>& operator<<(
inline std::basic_ostream<Elem,Traits>& operator<<(
std::basic_ostream<Elem, Traits>& Os,
const iterator_range<IteratorT>& r )
{
std::copy( begin(r), end(r), std::ostream_iterator<Elem>(Os));
return Os;
}
//! Comparison operator ( equal )
/*!
Compare operands for equality
*/
template< class IteratorT >
inline bool operator==( const iterator_range<IteratorT>& l,
const iterator_range<IteratorT>& r )
{
return ! (l != r);
}
//! Comparison operator ( not-equal )
/*!
Compare operands for non-equality
*/
template< class IteratorT >
inline bool operator!=( const iterator_range<IteratorT>& l,
const iterator_range<IteratorT>& 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<Range>::type >
make_iterator_range( Range& r )
template< class XRange >
inline iterator_range< BOOST_DEDUCED_TYPENAME iterator_of<XRange>::type >
make_iterator_range( XRange& r )
{
return iterator_range< BOOST_DEDUCED_TYPENAME iterator_of<Range>::type >
return iterator_range< BOOST_DEDUCED_TYPENAME iterator_of<XRange>::type >
( r );
}
template< typename Range >
inline iterator_range< BOOST_DEDUCED_TYPENAME const_iterator_of<Range>::type >
make_iterator_range( const Range& r )
template< class XRange >
inline iterator_range< BOOST_DEDUCED_TYPENAME const_iterator_of<XRange>::type >
make_iterator_range( const XRange& r )
{
return iterator_range< BOOST_DEDUCED_TYPENAME const_iterator_of<Range>::type >
return iterator_range< BOOST_DEDUCED_TYPENAME const_iterator_of<XRange>::type >
( r );
}
#endif

View File

@ -20,27 +20,28 @@
namespace boost
{
template< class Range >
class sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME result_iterator_of<Range>::type >
template< class XRange >
class sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME result_iterator_of<XRange>::type >
{
sub_range(); // not implemented
typedef BOOST_DEDUCED_TYPENAME result_iterator_of<Range>::type iterator_t;
typedef BOOST_DEDUCED_TYPENAME result_iterator_of<XRange>::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<Range>::type difference_type;
typedef BOOST_DEDUCED_TYPENAME size_type_of<Range>::type size_type;
typedef BOOST_DEDUCED_TYPENAME difference_type_of<XRange>::type difference_type;
typedef BOOST_DEDUCED_TYPENAME size_type_of<XRange>::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;

View File

@ -59,13 +59,14 @@ void check_iterator_range()
typedef sub_range<string> srange;
typedef sub_range<const string> 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() );