forked from boostorg/range
Boost.Range fix to the combine function that did not show as a defect on most compilers.
This iteration also makes the code compatible with more compilers. [SVN r61071]
This commit is contained in:
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <boost/iterator/zip_iterator.hpp>
|
#include <boost/iterator/zip_iterator.hpp>
|
||||||
#include <boost/tuple/tuple.hpp>
|
#include <boost/tuple/tuple.hpp>
|
||||||
|
#include <boost/range/iterator.hpp>
|
||||||
#include <boost/range/iterator_range.hpp>
|
#include <boost/range/iterator_range.hpp>
|
||||||
#include <boost/type_traits/is_void.hpp>
|
#include <boost/type_traits/is_void.hpp>
|
||||||
#include <boost/type_traits/is_same.hpp>
|
#include <boost/type_traits/is_same.hpp>
|
||||||
@ -14,40 +15,48 @@
|
|||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
namespace detail
|
namespace range_detail
|
||||||
{
|
{
|
||||||
struct void_ { typedef void_ type; };
|
struct void_ { typedef void_ type; };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> struct range_iterator<detail::void_>
|
template<> struct range_iterator< ::boost::range_detail::void_ >
|
||||||
{
|
{
|
||||||
typedef tuples::null_type type;
|
typedef ::boost::tuples::null_type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail
|
namespace range_detail
|
||||||
{
|
{
|
||||||
inline tuples::null_type range_begin( void_& )
|
inline ::boost::tuples::null_type range_begin( ::boost::range_detail::void_& )
|
||||||
{ return tuples::null_type(); }
|
{ return ::boost::tuples::null_type(); }
|
||||||
|
|
||||||
inline tuples::null_type range_end( void_& )
|
inline ::boost::tuples::null_type range_begin( const ::boost::range_detail::void_& )
|
||||||
{ return tuples::null_type(); }
|
{ return ::boost::tuples::null_type(); }
|
||||||
|
|
||||||
|
inline ::boost::tuples::null_type range_end( ::boost::range_detail::void_& )
|
||||||
|
{ return ::boost::tuples::null_type(); }
|
||||||
|
|
||||||
|
inline ::boost::tuples::null_type range_end( const ::boost::range_detail::void_& )
|
||||||
|
{ return ::boost::tuples::null_type(); }
|
||||||
|
|
||||||
template< class T >
|
template< class T >
|
||||||
struct tuple_iter
|
struct tuple_iter
|
||||||
{
|
{
|
||||||
typedef typename mpl::eval_if_c< is_same<T,void_>::value,
|
typedef BOOST_DEDUCED_TYPENAME ::boost::mpl::eval_if_c<
|
||||||
mpl::identity<tuples::null_type>,
|
::boost::is_same<T, ::boost::range_detail::void_ >::value,
|
||||||
range_iterator<T> >::type
|
::boost::mpl::identity< ::boost::tuples::null_type >,
|
||||||
type;
|
::boost::range_iterator<T>
|
||||||
|
>::type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template< class Rng1, class Rng2 >
|
template< class Rng1, class Rng2 >
|
||||||
struct tuple_range
|
struct tuple_range
|
||||||
{
|
{
|
||||||
typedef typename mpl::eval_if_c< is_same<Rng1,void_>::value,
|
typedef BOOST_DEDUCED_TYPENAME ::boost::mpl::eval_if_c<
|
||||||
void_,
|
::boost::is_same<Rng1, ::boost::range_detail::void_ >::value,
|
||||||
mpl::identity<Rng1> >::type
|
::boost::range_detail::void_,
|
||||||
type;
|
::boost::mpl::identity<Rng1>
|
||||||
|
>::type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template
|
template
|
||||||
@ -61,32 +70,33 @@ namespace boost
|
|||||||
>
|
>
|
||||||
struct generate_tuple
|
struct generate_tuple
|
||||||
{
|
{
|
||||||
typedef boost::tuple< typename tuple_iter<R1>::type,
|
typedef ::boost::tuples::tuple<
|
||||||
typename tuple_iter<R2>::type,
|
BOOST_DEDUCED_TYPENAME tuple_iter<R1>::type,
|
||||||
typename tuple_iter<R3>::type,
|
BOOST_DEDUCED_TYPENAME tuple_iter<R2>::type,
|
||||||
typename tuple_iter<R4>::type,
|
BOOST_DEDUCED_TYPENAME tuple_iter<R3>::type,
|
||||||
typename tuple_iter<R5>::type,
|
BOOST_DEDUCED_TYPENAME tuple_iter<R4>::type,
|
||||||
typename tuple_iter<R6>::type >
|
BOOST_DEDUCED_TYPENAME tuple_iter<R5>::type,
|
||||||
type;
|
BOOST_DEDUCED_TYPENAME tuple_iter<R6>::type
|
||||||
|
> type;
|
||||||
|
|
||||||
static type begin( R1& r1, R2& r2, R3& r3, R4& r4, R5& r5, R6& r6 )
|
static type begin( R1& r1, R2& r2, R3& r3, R4& r4, R5& r5, R6& r6 )
|
||||||
{
|
{
|
||||||
return make_tuple( boost::begin(r1),
|
return ::boost::tuples::make_tuple( ::boost::begin(r1),
|
||||||
boost::begin(r2),
|
::boost::begin(r2),
|
||||||
boost::begin(r3),
|
::boost::begin(r3),
|
||||||
boost::begin(r4),
|
::boost::begin(r4),
|
||||||
boost::begin(r5),
|
::boost::begin(r5),
|
||||||
boost::begin(r6) );
|
::boost::begin(r6) );
|
||||||
}
|
}
|
||||||
|
|
||||||
static type end( R1& r1, R2& r2, R3& r3, R4& r4, R5& r5, R6& r6 )
|
static type end( R1& r1, R2& r2, R3& r3, R4& r4, R5& r5, R6& r6 )
|
||||||
{
|
{
|
||||||
return make_tuple( boost::end(r1),
|
return ::boost::tuples::make_tuple( ::boost::end(r1),
|
||||||
boost::end(r2),
|
::boost::end(r2),
|
||||||
boost::end(r3),
|
::boost::end(r3),
|
||||||
boost::end(r4),
|
::boost::end(r4),
|
||||||
boost::end(r5),
|
::boost::end(r5),
|
||||||
boost::end(r6) );
|
::boost::end(r6) );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -101,54 +111,52 @@ namespace boost
|
|||||||
>
|
>
|
||||||
struct zip_rng
|
struct zip_rng
|
||||||
: iterator_range<
|
: iterator_range<
|
||||||
zip_iterator< typename generate_tuple<R1,R2,R3,R4,R5,R6>::type >
|
zip_iterator<
|
||||||
|
BOOST_DEDUCED_TYPENAME generate_tuple<R1,R2,R3,R4,R5,R6>::type
|
||||||
|
>
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
typedef generate_tuple<R1,R2,R3,R4,R5,R6>
|
typedef generate_tuple<R1,R2,R3,R4,R5,R6> generator_t;
|
||||||
generator;
|
typedef BOOST_DEDUCED_TYPENAME generator_t::type tuple_t;
|
||||||
typedef typename generator::type
|
typedef zip_iterator<tuple_t> zip_iter_t;
|
||||||
tuple;
|
typedef iterator_range<zip_iter_t> base_t;
|
||||||
typedef zip_iterator<tuple>
|
|
||||||
zip_iter;
|
|
||||||
typedef iterator_range<zip_iter>
|
|
||||||
base;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
zip_rng( R1& r1, R2& r2, R3& r3, R4& r4, R5& r5, R6& r6 )
|
zip_rng( R1& r1, R2& r2, R3& r3, R4& r4, R5& r5, R6& r6 )
|
||||||
: base( zip_iter( generator::begin(r1,r2,r3,r4,r5,r6) ),
|
: base_t( zip_iter_t( generator_t::begin(r1,r2,r3,r4,r5,r6) ),
|
||||||
zip_iter( generator::end(r1,r2,r3,r4,r5,r6) ) )
|
zip_iter_t( generator_t::end(r1,r2,r3,r4,r5,r6) ) )
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(boost::distance(r1) <= boost::distance(r2));
|
BOOST_ASSERT(::boost::distance(r1) <= ::boost::distance(r2));
|
||||||
BOOST_ASSERT(boost::distance(r1) <= boost::distance(r3));
|
BOOST_ASSERT(::boost::distance(r1) <= ::boost::distance(r3));
|
||||||
BOOST_ASSERT(boost::distance(r1) <= boost::distance(r4));
|
BOOST_ASSERT(::boost::distance(r1) <= ::boost::distance(r4));
|
||||||
BOOST_ASSERT(boost::distance(r1) <= boost::distance(r5));
|
BOOST_ASSERT(::boost::distance(r1) <= ::boost::distance(r5));
|
||||||
BOOST_ASSERT(boost::distance(r1) <= boost::distance(r6));
|
BOOST_ASSERT(::boost::distance(r1) <= ::boost::distance(r6));
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class Zip, class Rng >
|
template< class Zip, class Rng >
|
||||||
zip_rng( Zip& z, Rng& r )
|
zip_rng( Zip& z, Rng& r )
|
||||||
: base( zip_iter( generator::begin( z, r ) ),
|
: base_t( zip_iter_t( generator_t::begin( z, r ) ),
|
||||||
zip_iter( generator::end( z, r ) ) )
|
zip_iter_t( generator_t::end( z, r ) ) )
|
||||||
{
|
{
|
||||||
|
|
||||||
// @todo: tuple::begin( should be overloaded for this situation
|
// @todo: tuple::begin( should be overloaded for this situation
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tuple_length : tuples::length<tuple>
|
struct tuple_length : ::boost::tuples::length<tuple_t>
|
||||||
{ };
|
{ };
|
||||||
|
|
||||||
template< unsigned N >
|
template< unsigned N >
|
||||||
struct get
|
struct get
|
||||||
{
|
{
|
||||||
template< class Z, class R >
|
template< class Z, class R >
|
||||||
static typename tuples::element<N,tuple>::type begin( Z& z, R& )
|
static BOOST_DEDUCED_TYPENAME ::boost::tuples::element<N,tuple_t>::type begin( Z& z, R& )
|
||||||
{
|
{
|
||||||
return get<N>( z.begin().get_iterator_tuple() );
|
return get<N>( z.begin().get_iterator_tuple() );
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class Z, class R >
|
template< class Z, class R >
|
||||||
static typename tuples::element<N,tuple>::type end( Z& z, R& r )
|
static BOOST_DEDUCED_TYPENAME ::boost::tuples::element<N,tuple_t>::type end( Z& z, R& r )
|
||||||
{
|
{
|
||||||
return get<N>( z.end().get_iterator_tuple() );
|
return get<N>( z.end().get_iterator_tuple() );
|
||||||
}
|
}
|
||||||
@ -160,27 +168,30 @@ namespace boost
|
|||||||
struct zip_range
|
struct zip_range
|
||||||
: iterator_range<
|
: iterator_range<
|
||||||
zip_iterator<
|
zip_iterator<
|
||||||
tuple< typename range_iterator<Rng1>::type,
|
::boost::tuples::tuple<
|
||||||
typename range_iterator<Rng2>::type >
|
BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng1>::type,
|
||||||
> >
|
BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng2>::type
|
||||||
|
>
|
||||||
|
>
|
||||||
|
>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
typedef zip_iterator<
|
typedef zip_iterator<
|
||||||
tuple< typename range_iterator<Rng1>::type,
|
::boost::tuples::tuple<
|
||||||
typename range_iterator<Rng2>::type >
|
BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng1>::type,
|
||||||
|
BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng2>::type
|
||||||
>
|
>
|
||||||
zip_iter;
|
> zip_iter_t;
|
||||||
typedef iterator_range<zip_iter>
|
typedef iterator_range<zip_iter_t> base_t;
|
||||||
base;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
zip_range( Rng1& r1, Rng2& r2 )
|
zip_range( Rng1& r1, Rng2& r2 )
|
||||||
: base( zip_iter( make_tuple(boost::begin(r1),
|
: base_t( zip_iter_t( ::boost::tuples::make_tuple(::boost::begin(r1),
|
||||||
boost::begin(r2)) ),
|
::boost::begin(r2)) ),
|
||||||
zip_iter( make_tuple(boost::end(r1),
|
zip_iter_t( ::boost::tuples::make_tuple(::boost::end(r1),
|
||||||
boost::end(r2)) ) )
|
::boost::end(r2)) ) )
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(boost::distance(r1) <= boost::distance(r2));
|
BOOST_ASSERT(::boost::distance(r1) <= ::boost::distance(r2));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -188,33 +199,36 @@ namespace boost
|
|||||||
struct zip_range3
|
struct zip_range3
|
||||||
: iterator_range<
|
: iterator_range<
|
||||||
zip_iterator<
|
zip_iterator<
|
||||||
tuple< typename range_iterator<Rng1>::type,
|
::boost::tuples::tuple<
|
||||||
typename range_iterator<Rng2>::type,
|
BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng1>::type,
|
||||||
typename range_iterator<Rng3>::type >
|
BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng2>::type,
|
||||||
> >
|
BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng3>::type
|
||||||
|
>
|
||||||
|
>
|
||||||
|
>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
typedef zip_iterator<
|
typedef zip_iterator<
|
||||||
tuple< typename range_iterator<Rng1>::type,
|
::boost::tuples::tuple<
|
||||||
typename range_iterator<Rng2>::type,
|
BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng1>::type,
|
||||||
typename range_iterator<Rng3>::type >
|
BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng2>::type,
|
||||||
|
BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng3>::type
|
||||||
>
|
>
|
||||||
zip_iter;
|
> zip_iter_t;
|
||||||
typedef iterator_range<zip_iter>
|
typedef iterator_range<zip_iter_t> base_t;
|
||||||
base;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
zip_range3( Rng1& r1, Rng2& r2, Rng3& r3 )
|
zip_range3( Rng1& r1, Rng2& r2, Rng3& r3 )
|
||||||
: base( zip_iter( make_tuple(boost::begin(r1),
|
: base_t( zip_iter_t( ::boost::tuples::make_tuple(::boost::begin(r1),
|
||||||
boost::begin(r2),
|
::boost::begin(r2),
|
||||||
boost::begin(r3)) ),
|
::boost::begin(r3)) ),
|
||||||
zip_iter( make_tuple(boost::end(r1),
|
zip_iter_t( ::boost::tuples::make_tuple(::boost::end(r1),
|
||||||
boost::end(r2),
|
::boost::end(r2),
|
||||||
boost::end(r3)) )
|
::boost::end(r3)) )
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(distance(r1) <= distance(r2));
|
BOOST_ASSERT(::boost::distance(r1) <= ::boost::distance(r2));
|
||||||
BOOST_ASSERT(distance(r1) <= distance(r3));
|
BOOST_ASSERT(::boost::distance(r1) <= ::boost::distance(r3));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -244,67 +258,39 @@ namespace boost
|
|||||||
class R5,
|
class R5,
|
||||||
class Rng
|
class Rng
|
||||||
>
|
>
|
||||||
inline typename zip_rng<R1,R2,R3,R4,R5>::next
|
inline BOOST_DEDUCED_TYPENAME zip_rng<R1,R2,R3,R4,R5>::next
|
||||||
operator&( const zip_rng<R1,R2,R3,R4,R5>& zip,
|
operator&( const zip_rng<R1,R2,R3,R4,R5>& zip,
|
||||||
Rng& r )
|
Rng& r )
|
||||||
{
|
{
|
||||||
return zip_rng<R1,R2,R3,R4,R5>::next( zip, r );
|
return zip_rng<R1,R2,R3,R4,R5>::next( zip, r );
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
} // namespace range_detail
|
||||||
// This one should be able to be made generic
|
|
||||||
//
|
|
||||||
// template
|
|
||||||
// <
|
|
||||||
// class R1,
|
|
||||||
// class R2 = void,
|
|
||||||
// class R3 = void,
|
|
||||||
// class R4 = void,
|
|
||||||
// class R5 = void,
|
|
||||||
// class R6 = void
|
|
||||||
// >
|
|
||||||
// inline zip_range<R1,R2,R3,R4,R4,R5,R6>::type
|
|
||||||
// x
|
|
||||||
//
|
|
||||||
//
|
|
||||||
/*
|
|
||||||
template< class Rng1, class Rng2, class Rng3 >
|
|
||||||
inline zip_range3<Rng1,Rng2,Rng3>
|
|
||||||
operator&( const zip_range<Rng1,Rng2>& r1, const Rng3& r3 )
|
|
||||||
{
|
|
||||||
return zip_range3<Rn1,Rng2,Rng3>(
|
|
||||||
}*/
|
|
||||||
|
|
||||||
} // namespace 'detail'
|
|
||||||
|
|
||||||
template< class Rng1, class Rng2 >
|
template< class Rng1, class Rng2 >
|
||||||
inline detail::zip_range<Rng1,Rng2> combine( Rng1& r1, Rng2& r2 )
|
inline ::boost::range_detail::zip_range<Rng1, Rng2> combine( Rng1& r1, Rng2& r2 )
|
||||||
{
|
{
|
||||||
return detail::zip_range<Rng1,Rng2>(r1,r2);
|
return ::boost::range_detail::zip_range<Rng1, Rng2>(r1, r2);
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class Rng1, class Rng2 >
|
template< class Rng1, class Rng2 >
|
||||||
inline detail::zip_range<const Rng1,Rng2> combine( const Rng1& r1, Rng2& r2 )
|
inline ::boost::range_detail::zip_range<const Rng1, Rng2> combine( const Rng1& r1, Rng2& r2 )
|
||||||
{
|
{
|
||||||
return detail::zip_range<const Rng1,Rng2>(r1,r2);
|
return ::boost::range_detail::zip_range<const Rng1, Rng2>(r1, r2);
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class Rng1, class Rng2 >
|
template< class Rng1, class Rng2 >
|
||||||
inline detail::zip_range<Rng1,const Rng2> combine( Rng1& r1, const Rng2& r2 )
|
inline ::boost::range_detail::zip_range<Rng1, const Rng2> combine( Rng1& r1, const Rng2& r2 )
|
||||||
{
|
{
|
||||||
return detail::zip_range<Rng1,Rng2>(r1,r2);
|
return ::boost::range_detail::zip_range<Rng1, const Rng2>(r1, r2);
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class Rng1, class Rng2 >
|
template< class Rng1, class Rng2 >
|
||||||
inline detail::zip_range<const Rng1,const Rng2> combine( const Rng1& r1, const Rng2& r2 )
|
inline ::boost::range_detail::zip_range<const Rng1, const Rng2> combine( const Rng1& r1, const Rng2& r2 )
|
||||||
{
|
{
|
||||||
return detail::zip_range<const Rng1,const Rng2>(r1,r2);
|
return ::boost::range_detail::zip_range<const Rng1, const Rng2>(r1, r2);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
} // namespace boost
|
||||||
// @todo: find a solution that scales better
|
|
||||||
// instead of adding 6 overloads!
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#include <boost/range/combine.hpp>
|
#include <boost/range/combine.hpp>
|
||||||
#include <boost/test/test_tools.hpp>
|
#include <boost/test/test_tools.hpp>
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
#include <boost/assign/list_of.hpp>
|
#include <boost/tuple/tuple.hpp>
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -29,20 +29,22 @@ template< class CombinedRng >
|
|||||||
void apply( const CombinedRng& r )
|
void apply( const CombinedRng& r )
|
||||||
{
|
{
|
||||||
std::vector<int> v;
|
std::vector<int> v;
|
||||||
for( typename boost::range_iterator<const CombinedRng>::type
|
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<const CombinedRng>::type iterator_t;
|
||||||
i = boost::begin(r),
|
|
||||||
e = boost::end(r);
|
|
||||||
i != e; ++i )
|
|
||||||
{
|
|
||||||
|
|
||||||
|
iterator_t e = boost::end(r);
|
||||||
|
for (iterator_t i = boost::begin(r); i != e; ++i)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_combine()
|
void test_combine()
|
||||||
{
|
{
|
||||||
std::vector<int> v1, v2, v3;
|
std::vector<int> v1, v2, v3;
|
||||||
v1 = boost::assign::list_of(1)(2)(3)(4);
|
for (int i = 1; i <= 4; ++i)
|
||||||
v2 = boost::assign::list_of(1)(2)(3)(4);
|
{
|
||||||
|
v1.push_back(i);
|
||||||
|
v2.push_back(i);
|
||||||
|
}
|
||||||
|
|
||||||
int i1, i2;
|
int i1, i2;
|
||||||
BOOST_FOREACH( boost::tie( i1, i2 ), boost::combine(v1,v2) )
|
BOOST_FOREACH( boost::tie( i1, i2 ), boost::combine(v1,v2) )
|
||||||
|
Reference in New Issue
Block a user