Boost logo

Boost Users :

From: Erik Åldstedt Sund (eriksund_at_[hidden])
Date: 2007-02-07 03:56:47


Hi,

just a short question: Why does not the zip_iterator header have the
following (or something along the lines of the following) creator function:

   template <typename Iter1Type, typename Iter2Type>
   boost::zip_iterator<boost::tuple<Iter1Type, Iter2Type> >
   make_zip_iterator(Iter1Type i, Iter2Type j)
   {
     return boost::make_zip_iterator(boost::make_tuple(i, j));
   }

That would make creating a zip_iterator much simpler. Instead of
writing the following:

   std::set<double> s;
   std::vector<int> v;

   // populate s and v....

   std::for_each(boost::make_zip_iterator(boost::make_tuple(s.begin(),
                                                            v.begin())),
                 boost::make_zip_iterator(boost::make_tuple(s.end(),
                                                            v.end())),
                 my_functor_that_does_something_useful());

you could write the following:

   std::set<double> aSet;
   std::vector<int> aVector;

   // populate aSet and aVector....

   std::for_each(boost::make_zip_iterator(aSet.begin(), aVector.begin()),
                 boost::make_zip_iterator(aSet.end(), aVector.end())),
                 my_functor_that_does_something_useful());

Regards,
Erik Åldstedt Sund


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net