forked from boostorg/range
*** empty log message ***
[SVN r24177]
This commit is contained in:
@ -51,6 +51,8 @@ namespace boost {
|
|||||||
template<typename IteratorT>
|
template<typename IteratorT>
|
||||||
class iterator_range
|
class iterator_range
|
||||||
{
|
{
|
||||||
|
iterator_range(); // not implemented
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! this type
|
//! this type
|
||||||
typedef iterator_range<IteratorT> type;
|
typedef iterator_range<IteratorT> type;
|
||||||
@ -75,62 +77,35 @@ namespace boost {
|
|||||||
//! iterator type
|
//! iterator type
|
||||||
typedef IteratorT iterator;
|
typedef IteratorT iterator;
|
||||||
|
|
||||||
//! Default constructor
|
|
||||||
iterator_range() {}
|
|
||||||
|
|
||||||
//! Constructor from a pair of iterators
|
//! 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) {}
|
m_Begin(Begin), m_End(End) {}
|
||||||
|
|
||||||
//! Constructor from a Range
|
//! Constructor from a Range
|
||||||
template< class Range >
|
template< class Range >
|
||||||
iterator_range( const Range& r ) :
|
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
|
//! Constructor from a Range
|
||||||
template< class Range >
|
template< class Range >
|
||||||
iterator_range( Range& r ) :
|
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
|
template< class XRange >
|
||||||
|
iterator_range& operator=( XRange& r )
|
||||||
//! 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 )
|
|
||||||
{
|
{
|
||||||
m_Begin=Other.begin(); m_End=Other.end();
|
m_Begin = begin_impl( r );
|
||||||
|
m_End = end_impl( r );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Comparison operator ( equal )
|
|
||||||
/*!
|
|
||||||
Compare operands for equality
|
|
||||||
*/
|
|
||||||
template< typename OtherItT >
|
|
||||||
bool operator==( const iterator_range<OtherItT>& Other ) const
|
|
||||||
{
|
|
||||||
return ! (*this != Other);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Comparison operator ( not-equal )
|
template< class XRange >
|
||||||
/*!
|
iterator_range& operator=( const XRange& r )
|
||||||
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
|
//! begin access
|
||||||
@ -203,6 +178,22 @@ namespace boost {
|
|||||||
// begin and end iterators
|
// begin and end iterators
|
||||||
IteratorT m_Begin;
|
IteratorT m_Begin;
|
||||||
IteratorT m_End;
|
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 ---------------------------//
|
// iterator range free-standing operators ---------------------------//
|
||||||
@ -213,15 +204,35 @@ namespace boost {
|
|||||||
in a sequence without separators.
|
in a sequence without separators.
|
||||||
*/
|
*/
|
||||||
template< typename IteratorT, typename Elem, typename Traits >
|
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,
|
std::basic_ostream<Elem, Traits>& Os,
|
||||||
const iterator_range<IteratorT>& r )
|
const iterator_range<IteratorT>& r )
|
||||||
{
|
{
|
||||||
std::copy( begin(r), end(r), std::ostream_iterator<Elem>(Os));
|
std::copy( begin(r), end(r), std::ostream_iterator<Elem>(Os));
|
||||||
|
|
||||||
return 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 -----------------------------------------//
|
// iterator range utilities -----------------------------------------//
|
||||||
|
|
||||||
@ -256,19 +267,19 @@ namespace boost {
|
|||||||
Construct an \c iterator_range from a \c Range containing the begin
|
Construct an \c iterator_range from a \c Range containing the begin
|
||||||
and end iterators.
|
and end iterators.
|
||||||
*/
|
*/
|
||||||
template< typename Range >
|
template< class XRange >
|
||||||
inline iterator_range< BOOST_DEDUCED_TYPENAME iterator_of<Range>::type >
|
inline iterator_range< BOOST_DEDUCED_TYPENAME iterator_of<XRange>::type >
|
||||||
make_iterator_range( Range& r )
|
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 );
|
( r );
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename Range >
|
template< class XRange >
|
||||||
inline iterator_range< BOOST_DEDUCED_TYPENAME const_iterator_of<Range>::type >
|
inline iterator_range< BOOST_DEDUCED_TYPENAME const_iterator_of<XRange>::type >
|
||||||
make_iterator_range( const Range& r )
|
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 );
|
( r );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,27 +20,28 @@
|
|||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
|
|
||||||
template< class Range >
|
template< class XRange >
|
||||||
class sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME result_iterator_of<Range>::type >
|
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;
|
typedef iterator_range< iterator_t > base;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using base::iterator;
|
using base::iterator;
|
||||||
using base::const_iterator;
|
using base::const_iterator;
|
||||||
using base::value_type;
|
using base::value_type;
|
||||||
typedef BOOST_DEDUCED_TYPENAME difference_type_of<Range>::type difference_type;
|
typedef BOOST_DEDUCED_TYPENAME difference_type_of<XRange>::type difference_type;
|
||||||
typedef BOOST_DEDUCED_TYPENAME size_type_of<Range>::type size_type;
|
typedef BOOST_DEDUCED_TYPENAME size_type_of<XRange>::type size_type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template< class Range2 >
|
template< class XRange2 >
|
||||||
sub_range( Range2& r ) : base( r )
|
sub_range( XRange2& r ) : base( r )
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
template< class Range2 >
|
template< class XRange2 >
|
||||||
sub_range( const Range2& r ) : base( r )
|
sub_range( const XRange2& r ) : base( r )
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
template< class Iter >
|
template< class Iter >
|
||||||
@ -48,15 +49,15 @@ namespace boost
|
|||||||
base( first, last )
|
base( first, last )
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
template< class Range2 >
|
template< class XRange2 >
|
||||||
sub_range& operator=( Range2& r )
|
sub_range& operator=( XRange2& r )
|
||||||
{
|
{
|
||||||
base::operator=( r );
|
base::operator=( r );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class Range2 >
|
template< class XRange2 >
|
||||||
sub_range& operator=( const Range2& r )
|
sub_range& operator=( const XRange2& r )
|
||||||
{
|
{
|
||||||
base::operator=( r );
|
base::operator=( r );
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -59,13 +59,14 @@ void check_iterator_range()
|
|||||||
typedef sub_range<string> srange;
|
typedef sub_range<string> srange;
|
||||||
typedef sub_range<const string> csrange;
|
typedef sub_range<const string> csrange;
|
||||||
srange s = r;
|
srange s = r;
|
||||||
BOOST_CHECK( r == s );
|
BOOST_CHECK( r == r );
|
||||||
s = make_iterator_range( str );
|
s = make_iterator_range( str );
|
||||||
csrange s2 = r;
|
csrange s2 = r;
|
||||||
s2 = r2;
|
s2 = r2;
|
||||||
s2 = make_iterator_range( cstr );
|
s2 = make_iterator_range( cstr );
|
||||||
BOOST_CHECK( r != s2 );
|
BOOST_CHECK( r2 == r2 );
|
||||||
s2 = make_iterator_range( str );
|
s2 = make_iterator_range( str );
|
||||||
|
BOOST_CHECK( !(s != s) );
|
||||||
|
|
||||||
BOOST_CHECK( r.begin() == s.begin() );
|
BOOST_CHECK( r.begin() == s.begin() );
|
||||||
BOOST_CHECK( r2.begin()== s2.begin() );
|
BOOST_CHECK( r2.begin()== s2.begin() );
|
||||||
|
Reference in New Issue
Block a user