Boost logo

Boost Users :

Subject: [Boost-users] Is there a 1 line wonder for counting iterator and back_inserter - say a counting iterator where the start and step can be specified?
From: Brian Davis (bitminer_at_[hidden])
Date: 2014-01-05 13:41:24


Is there a 1 line wonder for counting iterator and back_inserter - say a
counting iterator where the start and step can be specified?

The following code creates an vector of angles from zero to N-1 * angle
step;

     std::vector angles;
     float angle_step = 0.275;
     int number_angles = 293;

     std::copy(
         boost::counting_iterator<float>(0),
         boost::counting_iterator<float>(number_angles),
         std::back_inserter(angles) );

     std::copy(
         boost::make_transform_iterator(angles.begin(),
boost::bind1st(std::multiplies<float>(), angle_step )),
         boost::make_transform_iterator(angles.end(),
boost::bind1st(std::multiplies<float>(), angle_step )),
         angles.begin() );

Is there or could there be a counting iterator or other mechanism to do
this in 1 line?
Say where the start and step could be specified?

Thanks


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