iterator_range interop with variant.

This commit is contained in:
Neil Groves
2014-03-02 22:50:24 +00:00
parent 79d2a66831
commit 8b60f2c768
4 changed files with 144 additions and 92 deletions

View File

@ -31,14 +31,18 @@
namespace boost
{
template< class ForwardRange >
class sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type >
class sub_range
: public iterator_range<
BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
>
{
typedef BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type iterator_t;
typedef iterator_range< iterator_t > base;
typedef BOOST_DEDUCED_TYPENAME base::impl impl;
public:
typedef BOOST_DEDUCED_TYPENAME range_value<ForwardRange>::type value_type;
typedef BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type iterator;
@ -46,17 +50,25 @@ namespace boost
typedef BOOST_DEDUCED_TYPENAME range_difference<ForwardRange>::type difference_type;
typedef BOOST_DEDUCED_TYPENAME range_size<ForwardRange>::type size_type;
typedef BOOST_DEDUCED_TYPENAME base::reference reference;
public: // for return value of front/back
typedef BOOST_DEDUCED_TYPENAME
boost::mpl::if_< boost::is_reference<reference>,
const BOOST_DEDUCED_TYPENAME boost::remove_reference<reference>::type&,
reference >::type const_reference;
private:
template<class Source>
struct is_compatible_range
: is_convertible<
BOOST_DEDUCED_TYPENAME mpl::eval_if<
has_range_iterator<Source>,
range_iterator<Source>,
mpl::identity<void>
>::type,
iterator
>
{
};
public:
sub_range() : base()
sub_range()
{ }
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) )
sub_range( const sub_range& r )
: base( static_cast<const base&>( r ) )
@ -64,39 +76,57 @@ namespace boost
#endif
template< class ForwardRange2 >
sub_range( ForwardRange2& r ) :
#if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 )
base( impl::adl_begin( r ), impl::adl_end( r ) )
#else
base( r )
#endif
{ }
template< class ForwardRange2 >
sub_range( const ForwardRange2& r ) :
sub_range(
ForwardRange2& r,
BOOST_DEDUCED_TYPENAME enable_if<
is_compatible_range<ForwardRange2>
>::type* = 0
) :
#if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 )
base( impl::adl_begin( r ), impl::adl_end( r ) )
#else
base( r )
#endif
#endif
{ }
template< class ForwardRange2 >
sub_range(
const ForwardRange2& r,
BOOST_DEDUCED_TYPENAME enable_if<
is_compatible_range<const ForwardRange2>
>::type* = 0
) :
#if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 )
base( impl::adl_begin( r ), impl::adl_end( r ) )
#else
base( r )
#endif
{ }
template< class Iter >
sub_range( Iter first, Iter last ) :
base( first, last )
{ }
template< class ForwardRange2 >
sub_range& operator=( ForwardRange2& r )
template<class ForwardRange2>
BOOST_DEDUCED_TYPENAME enable_if<
is_compatible_range<ForwardRange2>,
sub_range&
>::type
operator=(ForwardRange2& r)
{
base::operator=( r );
return *this;
}
template< class ForwardRange2 >
sub_range& operator=( const ForwardRange2& r )
template<class ForwardRange2>
BOOST_DEDUCED_TYPENAME enable_if<
is_compatible_range<const ForwardRange2>,
sub_range&
>::type
operator=( const ForwardRange2& r )
{
base::operator=( r );
return *this;
@ -107,71 +137,8 @@ namespace boost
base::operator=( static_cast<const base&>(r) );
return *this;
}
public:
iterator begin() { return base::begin(); }
const_iterator begin() const { return base::begin(); }
iterator end() { return base::end(); }
const_iterator end() const { return base::end(); }
difference_type size() const { return base::size(); }
public: // convenience
reference front()
{
return base::front();
}
const_reference front() const
{
return base::front();
}
reference back()
{
return base::back();
}
const_reference back() const
{
return base::back();
}
reference operator[]( difference_type sz )
{
return base::operator[](sz);
}
const_reference operator[]( difference_type sz ) const
{
return base::operator[](sz);
}
};
template< class ForwardRange, class ForwardRange2 >
inline bool operator==( const sub_range<ForwardRange>& l,
const sub_range<ForwardRange2>& r )
{
return boost::equal( l, r );
}
template< class ForwardRange, class ForwardRange2 >
inline bool operator!=( const sub_range<ForwardRange>& l,
const sub_range<ForwardRange2>& r )
{
return !boost::equal( l, r );
}
template< class ForwardRange, class ForwardRange2 >
inline bool operator<( const sub_range<ForwardRange>& l,
const sub_range<ForwardRange2>& r )
{
return iterator_range_detail::less_than( l, r );
}
} // namespace 'boost'
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))