Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61071 - in trunk: boost/range libs/range/test
From: neil_at_[hidden]
Date: 2010-04-05 10:12:24


Author: neilgroves
Date: 2010-04-05 10:12:24 EDT (Mon, 05 Apr 2010)
New Revision: 61071
URL: http://svn.boost.org/trac/boost/changeset/61071

Log:
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.
Text files modified:
   trunk/boost/range/combine.hpp | 272 ++++++++++++++++++---------------------
   trunk/libs/range/test/combine.cpp | 20 +-
   2 files changed, 140 insertions(+), 152 deletions(-)

Modified: trunk/boost/range/combine.hpp
==============================================================================
--- trunk/boost/range/combine.hpp (original)
+++ trunk/boost/range/combine.hpp 2010-04-05 10:12:24 EDT (Mon, 05 Apr 2010)
@@ -3,6 +3,7 @@
 
 #include <boost/iterator/zip_iterator.hpp>
 #include <boost/tuple/tuple.hpp>
+#include <boost/range/iterator.hpp>
 #include <boost/range/iterator_range.hpp>
 #include <boost/type_traits/is_void.hpp>
 #include <boost/type_traits/is_same.hpp>
@@ -14,40 +15,48 @@
 
 namespace boost
 {
- namespace detail
+ namespace range_detail
     {
         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_& )
- { return tuples::null_type(); }
+ inline ::boost::tuples::null_type range_begin( ::boost::range_detail::void_& )
+ { return ::boost::tuples::null_type(); }
 
- inline tuples::null_type range_end( void_& )
- { return tuples::null_type(); }
+ inline ::boost::tuples::null_type range_begin( const ::boost::range_detail::void_& )
+ { 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 >
         struct tuple_iter
         {
- typedef typename mpl::eval_if_c< is_same<T,void_>::value,
- mpl::identity<tuples::null_type>,
- range_iterator<T> >::type
- type;
+ typedef BOOST_DEDUCED_TYPENAME ::boost::mpl::eval_if_c<
+ ::boost::is_same<T, ::boost::range_detail::void_ >::value,
+ ::boost::mpl::identity< ::boost::tuples::null_type >,
+ ::boost::range_iterator<T>
+ >::type type;
         };
 
         template< class Rng1, class Rng2 >
         struct tuple_range
         {
- typedef typename mpl::eval_if_c< is_same<Rng1,void_>::value,
- void_,
- mpl::identity<Rng1> >::type
- type;
+ typedef BOOST_DEDUCED_TYPENAME ::boost::mpl::eval_if_c<
+ ::boost::is_same<Rng1, ::boost::range_detail::void_ >::value,
+ ::boost::range_detail::void_,
+ ::boost::mpl::identity<Rng1>
+ >::type type;
         };
 
         template
@@ -57,36 +66,37 @@
             class R3,
             class R4,
             class R5,
- class R6
+ class R6
>
         struct generate_tuple
         {
- typedef boost::tuple< typename tuple_iter<R1>::type,
- typename tuple_iter<R2>::type,
- typename tuple_iter<R3>::type,
- typename tuple_iter<R4>::type,
- typename tuple_iter<R5>::type,
- typename tuple_iter<R6>::type >
- type;
+ typedef ::boost::tuples::tuple<
+ BOOST_DEDUCED_TYPENAME tuple_iter<R1>::type,
+ BOOST_DEDUCED_TYPENAME tuple_iter<R2>::type,
+ BOOST_DEDUCED_TYPENAME tuple_iter<R3>::type,
+ BOOST_DEDUCED_TYPENAME tuple_iter<R4>::type,
+ BOOST_DEDUCED_TYPENAME tuple_iter<R5>::type,
+ BOOST_DEDUCED_TYPENAME tuple_iter<R6>::type
+ > type;
 
             static type begin( R1& r1, R2& r2, R3& r3, R4& r4, R5& r5, R6& r6 )
             {
- return make_tuple( boost::begin(r1),
- boost::begin(r2),
- boost::begin(r3),
- boost::begin(r4),
- boost::begin(r5),
- boost::begin(r6) );
+ return ::boost::tuples::make_tuple( ::boost::begin(r1),
+ ::boost::begin(r2),
+ ::boost::begin(r3),
+ ::boost::begin(r4),
+ ::boost::begin(r5),
+ ::boost::begin(r6) );
             }
 
             static type end( R1& r1, R2& r2, R3& r3, R4& r4, R5& r5, R6& r6 )
             {
- return make_tuple( boost::end(r1),
- boost::end(r2),
- boost::end(r3),
- boost::end(r4),
- boost::end(r5),
- boost::end(r6) );
+ return ::boost::tuples::make_tuple( ::boost::end(r1),
+ ::boost::end(r2),
+ ::boost::end(r3),
+ ::boost::end(r4),
+ ::boost::end(r5),
+ ::boost::end(r6) );
             }
         };
 
@@ -101,54 +111,52 @@
>
         struct zip_rng
             : 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:
- typedef generate_tuple<R1,R2,R3,R4,R5,R6>
- generator;
- typedef typename generator::type
- tuple;
- typedef zip_iterator<tuple>
- zip_iter;
- typedef iterator_range<zip_iter>
- base;
+ typedef generate_tuple<R1,R2,R3,R4,R5,R6> generator_t;
+ typedef BOOST_DEDUCED_TYPENAME generator_t::type tuple_t;
+ typedef zip_iterator<tuple_t> zip_iter_t;
+ typedef iterator_range<zip_iter_t> base_t;
 
         public:
             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) ),
- zip_iter( generator::end(r1,r2,r3,r4,r5,r6) ) )
+ : base_t( zip_iter_t( generator_t::begin(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(r3));
- BOOST_ASSERT(boost::distance(r1) <= boost::distance(r4));
- BOOST_ASSERT(boost::distance(r1) <= boost::distance(r5));
- BOOST_ASSERT(boost::distance(r1) <= boost::distance(r6));
+ BOOST_ASSERT(::boost::distance(r1) <= ::boost::distance(r2));
+ BOOST_ASSERT(::boost::distance(r1) <= ::boost::distance(r3));
+ BOOST_ASSERT(::boost::distance(r1) <= ::boost::distance(r4));
+ BOOST_ASSERT(::boost::distance(r1) <= ::boost::distance(r5));
+ BOOST_ASSERT(::boost::distance(r1) <= ::boost::distance(r6));
             }
 
             template< class Zip, class Rng >
             zip_rng( Zip& z, Rng& r )
- : base( zip_iter( generator::begin( z, r ) ),
- zip_iter( generator::end( z, r ) ) )
+ : base_t( zip_iter_t( generator_t::begin( z, r ) ),
+ zip_iter_t( generator_t::end( z, r ) ) )
             {
 
                 // @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 >
             struct get
             {
                 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() );
                 }
 
                 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() );
                 }
@@ -157,64 +165,70 @@
         };
 
         template< class Rng1, class Rng2 >
- struct zip_range
- : iterator_range<
- zip_iterator<
- tuple< typename range_iterator<Rng1>::type,
- typename range_iterator<Rng2>::type >
- > >
+ struct zip_range
+ : iterator_range<
+ zip_iterator<
+ ::boost::tuples::tuple<
+ BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng1>::type,
+ BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng2>::type
+ >
+ >
+ >
         {
         private:
- typedef zip_iterator<
- tuple< typename range_iterator<Rng1>::type,
- typename range_iterator<Rng2>::type >
+ typedef zip_iterator<
+ ::boost::tuples::tuple<
+ BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng1>::type,
+ BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng2>::type
>
- zip_iter;
- typedef iterator_range<zip_iter>
- base;
+ > zip_iter_t;
+ typedef iterator_range<zip_iter_t> base_t;
 
         public:
             zip_range( Rng1& r1, Rng2& r2 )
- : base( zip_iter( make_tuple(boost::begin(r1),
- boost::begin(r2)) ),
- zip_iter( make_tuple(boost::end(r1),
- boost::end(r2)) ) )
+ : base_t( zip_iter_t( ::boost::tuples::make_tuple(::boost::begin(r1),
+ ::boost::begin(r2)) ),
+ zip_iter_t( ::boost::tuples::make_tuple(::boost::end(r1),
+ ::boost::end(r2)) ) )
             {
- BOOST_ASSERT(boost::distance(r1) <= boost::distance(r2));
+ BOOST_ASSERT(::boost::distance(r1) <= ::boost::distance(r2));
             }
         };
 
         template< class Rng1, class Rng2, class Rng3 >
- struct zip_range3
- : iterator_range<
- zip_iterator<
- tuple< typename range_iterator<Rng1>::type,
- typename range_iterator<Rng2>::type,
- typename range_iterator<Rng3>::type >
- > >
+ struct zip_range3
+ : iterator_range<
+ zip_iterator<
+ ::boost::tuples::tuple<
+ BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng1>::type,
+ BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng2>::type,
+ BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng3>::type
+ >
+ >
+ >
         {
         private:
- typedef zip_iterator<
- tuple< typename range_iterator<Rng1>::type,
- typename range_iterator<Rng2>::type,
- typename range_iterator<Rng3>::type >
- >
- zip_iter;
- typedef iterator_range<zip_iter>
- base;
+ typedef zip_iterator<
+ ::boost::tuples::tuple<
+ BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng1>::type,
+ BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng2>::type,
+ BOOST_DEDUCED_TYPENAME ::boost::range_iterator<Rng3>::type
+ >
+ > zip_iter_t;
+ typedef iterator_range<zip_iter_t> base_t;
 
         public:
             zip_range3( Rng1& r1, Rng2& r2, Rng3& r3 )
- : base( zip_iter( make_tuple(boost::begin(r1),
- boost::begin(r2),
- boost::begin(r3)) ),
- zip_iter( make_tuple(boost::end(r1),
- boost::end(r2),
- boost::end(r3)) )
- )
+ : base_t( zip_iter_t( ::boost::tuples::make_tuple(::boost::begin(r1),
+ ::boost::begin(r2),
+ ::boost::begin(r3)) ),
+ zip_iter_t( ::boost::tuples::make_tuple(::boost::end(r1),
+ ::boost::end(r2),
+ ::boost::end(r3)) )
+ )
             {
- BOOST_ASSERT(distance(r1) <= distance(r2));
- BOOST_ASSERT(distance(r1) <= distance(r3));
+ BOOST_ASSERT(::boost::distance(r1) <= ::boost::distance(r2));
+ BOOST_ASSERT(::boost::distance(r1) <= ::boost::distance(r3));
             }
         };
 
@@ -222,89 +236,61 @@
         struct combine_tag {};
 
         template< class Rng >
- inline zip_rng<Rng>
+ inline zip_rng<Rng>
         operator&( combine_tag, Rng& r )
         {
             return zip_rng<Rng>(r);
         }
 
         template< class Rng >
- inline iterator_range<const Rng>
+ inline iterator_range<const Rng>
         operator&( combine_tag, const Rng& r )
         {
             return iterator_range<const Rng>(r);
         }
 
         template
- <
- class R1,
+ <
+ class R1,
             class R2,
             class R3,
             class R4,
             class R5,
             class Rng
>
- inline typename zip_rng<R1,R2,R3,R4,R5>::next
- operator&( const zip_rng<R1,R2,R3,R4,R5>& zip,
+ inline BOOST_DEDUCED_TYPENAME zip_rng<R1,R2,R3,R4,R5>::next
+ operator&( const zip_rng<R1,R2,R3,R4,R5>& zip,
                    Rng& r )
         {
             return zip_rng<R1,R2,R3,R4,R5>::next( zip, r );
         }
 
- //
- // 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'
+ } // namespace range_detail
 
     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 >
- 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 >
- 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 >
- 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);
     }
 
- //
- // @todo: find a solution that scales better
- // instead of adding 6 overloads!
- //
-}
+} // namespace boost
 
 #endif

Modified: trunk/libs/range/test/combine.cpp
==============================================================================
--- trunk/libs/range/test/combine.cpp (original)
+++ trunk/libs/range/test/combine.cpp 2010-04-05 10:12:24 EDT (Mon, 05 Apr 2010)
@@ -11,7 +11,7 @@
 #include <boost/range/combine.hpp>
 #include <boost/test/test_tools.hpp>
 #include <boost/test/unit_test.hpp>
-#include <boost/assign/list_of.hpp>
+#include <boost/tuple/tuple.hpp>
 #include <boost/foreach.hpp>
 #include <vector>
 
@@ -26,23 +26,25 @@
 };
 
 template< class CombinedRng >
-void apply( const CombinedRng& r )
+void apply( const CombinedRng& r )
 {
     std::vector<int> v;
- for( typename boost::range_iterator<const CombinedRng>::type
- i = boost::begin(r),
- e = boost::end(r);
- i != e; ++i )
+ typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<const CombinedRng>::type iterator_t;
+
+ iterator_t e = boost::end(r);
+ for (iterator_t i = boost::begin(r); i != e; ++i)
     {
-
     }
 }
 
 void test_combine()
 {
     std::vector<int> v1, v2, v3;
- v1 = boost::assign::list_of(1)(2)(3)(4);
- v2 = boost::assign::list_of(1)(2)(3)(4);
+ for (int i = 1; i <= 4; ++i)
+ {
+ v1.push_back(i);
+ v2.push_back(i);
+ }
 
     int i1, i2;
     BOOST_FOREACH( boost::tie( i1, i2 ), boost::combine(v1,v2) )


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk