Is there a 1 line wonder for counting iterator and back_inserter - say a counting iterator where the start and step can be specified?
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
2014/1/5 Brian Davis
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
I recommend Boost.Range. In your example I also suggest using
Boost.Phoenix instead of bind1st and multiplies; and push_back from
Boost.Range instead of back_inserter.
#include
participants (2)
-
Brian Davis
-
Krzysztof Czainski