Ticket #3684: zip_iterator.patch

File zip_iterator.patch, 10.6 KB (added by Dave Abrahams, 13 years ago)
  • libs/iterator/test/zip_iterator_test.cpp

     
    4747#include <list>
    4848#include <set>
    4949#include <functional>
    50 #include <boost/tuple/tuple.hpp>
     50#include <boost/fusion/tuple.hpp>
    5151#include <boost/iterator/transform_iterator.hpp>
    5252#include <boost/iterator/is_readable_iterator.hpp>
    5353#include <boost/type_traits/is_same.hpp>
     
    104104
    105105  typedef
    106106  boost::zip_iterator<
    107       boost::tuples::tuple<
     107      boost::fusion::tuple<
    108108          std::set<int>::iterator
    109109        , std::vector<double>::iterator
    110110      >
    111111  > zit_mixed;
    112112
    113113  zit_mixed zip_it_mixed = zit_mixed(
    114     boost::make_tuple(
     114                                     boost::fusion::make_tuple(
    115115        intset.begin()
    116116      , vect1.begin()
    117117    )
    118118  );
    119119
    120   boost::tuples::tuple<int, double> val_tuple(
     120  boost::fusion::tuple<int, double> val_tuple(
    121121      *zip_it_mixed);
    122122 
    123   boost::tuples::tuple<const int&, double&> ref_tuple(
     123  boost::fusion::tuple<const int&, double&> ref_tuple(
    124124      *zip_it_mixed);
    125125
    126   double dblOldVal = boost::tuples::get<1>(ref_tuple);
    127   boost::tuples::get<1>(ref_tuple) -= 41.;
     126  double dblOldVal = boost::fusion::get<1>(ref_tuple);
     127  boost::fusion::get<1>(ref_tuple) -= 41.;
    128128
    129   if( 52 == boost::tuples::get<0>(val_tuple) &&
    130       42. == boost::tuples::get<1>(val_tuple) &&
    131       52 == boost::tuples::get<0>(ref_tuple)  &&
    132       1. == boost::tuples::get<1>(ref_tuple)  &&
     129  if( 52 == boost::fusion::get<0>(val_tuple) &&
     130      42. == boost::fusion::get<1>(val_tuple) &&
     131      52 == boost::fusion::get<0>(ref_tuple)  &&
     132      1. == boost::fusion::get<1>(ref_tuple)  &&
    133133      1. == *vect1.begin()
    134134    )
    135135  {
     
    143143  }
    144144
    145145  // Undo change to vect1
    146   boost::tuples::get<1>(ref_tuple) = dblOldVal;
     146  boost::fusion::get<1>(ref_tuple) = dblOldVal;
    147147
    148148  /////////////////////////////////////////////////////////////////////////////
    149149  //
     
    185185  ve4.push_back(12);
    186186
    187187  // typedefs for cons lists of iterators.
    188   typedef boost::tuples::cons<
     188  typedef boost::fusion::cons<
    189189    std::set<int>::iterator,
    190     boost::tuples::tuple<
     190    boost::fusion::tuple<
    191191      std::vector<int>::iterator,
    192192      std::list<int>::iterator,
    193193      std::set<int>::iterator,
     
    201201      >::inherited
    202202    > cons_11_its_type;
    203203  //
    204   typedef boost::tuples::cons<
     204  typedef boost::fusion::cons<
    205205    std::list<int>::const_iterator,
    206206    cons_11_its_type
    207207    > cons_12_its_type;
    208208
    209209  // typedefs for cons lists for dereferencing the zip iterator
    210210  // made from the cons list above.
    211   typedef boost::tuples::cons<
     211  typedef boost::fusion::cons<
    212212    const int&,
    213     boost::tuples::tuple<
     213    boost::fusion::tuple<
    214214      int&,
    215215      int&,
    216216      const int&,
     
    224224      >::inherited
    225225    > cons_11_refs_type;
    226226  //
    227   typedef boost::tuples::cons<
     227  typedef boost::fusion::cons<
    228228    const int&,
    229229    cons_11_refs_type
    230230    > cons_12_refs_type;
     
    238238      li1.begin(),
    239239      cons_11_its_type(
    240240        se1.begin(),
    241         boost::make_tuple(
     241        boost::fusion::make_tuple(
    242242          ve1.begin(),
    243243          li2.begin(),
    244244          se2.begin(),
     
    256256
    257257  // Dereference, mess with the result a little.
    258258  cons_12_refs_type zip_it_12_dereferenced(*zip_it_12);
    259   boost::tuples::get<9>(zip_it_12_dereferenced) = 42;
     259  boost::fusion::get<9>(zip_it_12_dereferenced) = 42;
    260260 
    261261  // Make a copy and move it a little to force some instantiations.
    262262  zip_it_12_type zip_it_12_copy(zip_it_12);
    263263  ++zip_it_12_copy;
    264264
    265   if( boost::tuples::get<11>(zip_it_12.get_iterator_tuple()) == ve4.begin() &&
    266       boost::tuples::get<11>(zip_it_12_copy.get_iterator_tuple()) == ve4.end() &&
    267       1 == boost::tuples::get<0>(zip_it_12_dereferenced) &&
    268       12 == boost::tuples::get<11>(zip_it_12_dereferenced) &&
     265  if( boost::fusion::get<11>(zip_it_12.get_iterator_tuple()) == ve4.begin() &&
     266      boost::fusion::get<11>(zip_it_12_copy.get_iterator_tuple()) == ve4.end() &&
     267      1 == boost::fusion::get<0>(zip_it_12_dereferenced) &&
     268      12 == boost::fusion::get<11>(zip_it_12_dereferenced) &&
    269269      42 == *(li4.begin())
    270270    )
    271271  {
     
    293293  vect2[2] = 4.4;
    294294 
    295295  boost::zip_iterator<
    296     boost::tuples::tuple<
     296    boost::fusion::tuple<
    297297      std::vector<double>::const_iterator,
    298298      std::vector<double>::const_iterator
    299299      >
    300300    >
    301301  zip_it_begin(
    302     boost::make_tuple(
     302    boost::fusion::make_tuple(
    303303     vect1.begin(),
    304304     vect2.begin()
    305305     )
    306306  );
    307307
    308308  boost::zip_iterator<
    309     boost::tuples::tuple<
     309    boost::fusion::tuple<
    310310      std::vector<double>::const_iterator,
    311311      std::vector<double>::const_iterator
    312312      >
    313313    >
    314314  zip_it_run(
    315     boost::make_tuple(
     315    boost::fusion::make_tuple(
    316316     vect1.begin(),
    317317     vect2.begin()
    318318     )
    319319  );
    320320
    321321  boost::zip_iterator<
    322     boost::tuples::tuple<
     322    boost::fusion::tuple<
    323323      std::vector<double>::const_iterator,
    324324      std::vector<double>::const_iterator
    325325      >
    326326    >
    327327  zip_it_end(
    328     boost::make_tuple(
     328    boost::fusion::make_tuple(
    329329     vect1.end(),
    330330     vect2.end()
    331331     )
    332332  );
    333333
    334334  if( zip_it_run == zip_it_begin &&
    335       42. == boost::tuples::get<0>(*zip_it_run) &&
    336       2.2 == boost::tuples::get<1>(*zip_it_run) &&
    337       43. == boost::tuples::get<0>(*(++zip_it_run)) &&
    338       3.3 == boost::tuples::get<1>(*zip_it_run) &&
    339       44. == boost::tuples::get<0>(*(++zip_it_run)) &&
    340       4.4 == boost::tuples::get<1>(*zip_it_run) &&
     335      42. == boost::fusion::get<0>(*zip_it_run) &&
     336      2.2 == boost::fusion::get<1>(*zip_it_run) &&
     337      43. == boost::fusion::get<0>(*(++zip_it_run)) &&
     338      3.3 == boost::fusion::get<1>(*zip_it_run) &&
     339      44. == boost::fusion::get<0>(*(++zip_it_run)) &&
     340      4.4 == boost::fusion::get<1>(*zip_it_run) &&
    341341      zip_it_end == ++zip_it_run
    342342    )
    343343  {
     
    361361
    362362  if( zip_it_run == zip_it_end &&
    363363      zip_it_end == zip_it_run-- &&
    364       44. == boost::tuples::get<0>(*zip_it_run) &&
    365       4.4 == boost::tuples::get<1>(*zip_it_run) &&
    366       43. == boost::tuples::get<0>(*(--zip_it_run)) &&
    367       3.3 == boost::tuples::get<1>(*zip_it_run) &&
    368       42. == boost::tuples::get<0>(*(--zip_it_run)) &&
    369       2.2 == boost::tuples::get<1>(*zip_it_run) &&
     364      44. == boost::fusion::get<0>(*zip_it_run) &&
     365      4.4 == boost::fusion::get<1>(*zip_it_run) &&
     366      43. == boost::fusion::get<0>(*(--zip_it_run)) &&
     367      3.3 == boost::fusion::get<1>(*zip_it_run) &&
     368      42. == boost::fusion::get<0>(*(--zip_it_run)) &&
     369      2.2 == boost::fusion::get<1>(*zip_it_run) &&
    370370      zip_it_begin == zip_it_run
    371371    )
    372372  {
     
    389389            << std::flush;
    390390
    391391  boost::zip_iterator<
    392     boost::tuples::tuple<
     392    boost::fusion::tuple<
    393393      std::vector<double>::const_iterator,
    394394      std::vector<double>::const_iterator
    395395      >
     
    642642  // Note: zip_it_run and zip_it_run_copy are both at
    643643  // begin plus one.
    644644  //
    645   if( boost::tuples::get<0>(zip_it_run.get_iterator_tuple()) == vect1.begin() + 1 &&
    646       boost::tuples::get<1>(zip_it_run.get_iterator_tuple()) == vect2.begin() + 1
     645  if( boost::fusion::get<0>(zip_it_run.get_iterator_tuple()) == vect1.begin() + 1 &&
     646      boost::fusion::get<1>(zip_it_run.get_iterator_tuple()) == vect2.begin() + 1
    647647    )
    648648  {
    649649    ++num_successful_tests;
     
    664664  std::cout << "Making zip iterators:                        "
    665665            << std::flush;
    666666
    667   std::vector<boost::tuples::tuple<double, double> >
     667  std::vector<boost::fusion::tuple<double, double> >
    668668    vect_of_tuples(3);
    669669
    670670  std::copy(
    671671    boost::make_zip_iterator(
    672     boost::make_tuple(
     672    boost::fusion::make_tuple(
    673673      vect1.begin(),
    674674      vect2.begin()
    675675      )
    676676    ),
    677677    boost::make_zip_iterator(
    678     boost::make_tuple(
     678    boost::fusion::make_tuple(
    679679      vect1.end(),
    680680      vect2.end()
    681681      )
     
    683683    vect_of_tuples.begin()
    684684  );
    685685
    686   if( 42. == boost::tuples::get<0>(*vect_of_tuples.begin()) &&
    687       2.2 == boost::tuples::get<1>(*vect_of_tuples.begin()) &&
    688       43. == boost::tuples::get<0>(*(vect_of_tuples.begin() + 1)) &&
    689       3.3 == boost::tuples::get<1>(*(vect_of_tuples.begin() + 1)) &&
    690       44. == boost::tuples::get<0>(*(vect_of_tuples.begin() + 2)) &&
    691       4.4 == boost::tuples::get<1>(*(vect_of_tuples.begin() + 2))
     686  if( 42. == boost::fusion::get<0>(*vect_of_tuples.begin()) &&
     687      2.2 == boost::fusion::get<1>(*vect_of_tuples.begin()) &&
     688      43. == boost::fusion::get<0>(*(vect_of_tuples.begin() + 1)) &&
     689      3.3 == boost::fusion::get<1>(*(vect_of_tuples.begin() + 1)) &&
     690      44. == boost::fusion::get<0>(*(vect_of_tuples.begin() + 2)) &&
     691      4.4 == boost::fusion::get<1>(*(vect_of_tuples.begin() + 2))
    692692    )
    693693  {
    694694    ++num_successful_tests;
     
    710710            << std::flush;
    711711 
    712712  boost::zip_iterator<
    713     boost::tuples::tuple<
     713    boost::fusion::tuple<
    714714      std::set<int>::const_iterator,
    715715      std::vector<double>::const_iterator
    716716      >
    717717    >
    718718  zip_it_const(
    719     boost::make_tuple(
     719    boost::fusion::make_tuple(
    720720      intset.begin(),
    721721      vect2.begin()
    722722    )
    723723  );
    724724  //
    725725  boost::zip_iterator<
    726     boost::tuples::tuple<
     726    boost::fusion::tuple<
    727727      std::set<int>::iterator,
    728728      std::vector<double>::const_iterator
    729729      >
    730730    >
    731731  zip_it_half_const(
    732     boost::make_tuple(
     732    boost::fusion::make_tuple(
    733733      intset.begin(),
    734734      vect2.begin()
    735735    )
    736736  );
    737737  //
    738738  boost::zip_iterator<
    739     boost::tuples::tuple<
     739    boost::fusion::tuple<
    740740      std::set<int>::iterator,
    741741      std::vector<double>::iterator
    742742      >
    743743    >
    744744  zip_it_non_const(
    745     boost::make_tuple(
     745    boost::fusion::make_tuple(
    746746      intset.begin(),
    747747      vect2.begin()
    748748    )
     
    753753  ++zip_it_const;
    754754//  zip_it_non_const = ++zip_it_const;  // Error: can't convert from const to non-const
    755755 
    756   if( 54 == boost::tuples::get<0>(*zip_it_const) &&
    757       4.4 == boost::tuples::get<1>(*zip_it_const)  &&
    758       53 == boost::tuples::get<0>(*zip_it_half_const)  &&
    759       3.3 == boost::tuples::get<1>(*zip_it_half_const)
     756  if( 54 == boost::fusion::get<0>(*zip_it_const) &&
     757      4.4 == boost::fusion::get<1>(*zip_it_const)  &&
     758      53 == boost::fusion::get<0>(*zip_it_half_const)  &&
     759      3.3 == boost::fusion::get<1>(*zip_it_half_const)
    760760    )
    761761  {
    762762    ++num_successful_tests;
     
    794794  // traversal.
    795795  //
    796796  typedef boost::zip_iterator<
    797     boost::tuples::tuple<
     797    boost::fusion::tuple<
    798798      std::vector<double>::const_iterator,
    799799      std::vector<double>::const_iterator
    800800      >