jeudi 31 décembre 2015

std::iota is very limited

Coming from a Python world, I find the function std::iota very limited. Why is the interface restricted to not take any UnaryFunction ?

For instance I can convert

>>> x = range(0, 10)

into

std::vector<int> x(10);
std::iota(std::begin(x), std::end(x), 0);

But how would one do:

>>> x = range(0,20,2)

or even

>>> x = range(10,0,-1)

I know this is trivial to write one such function or use Boost, but I figured that C++ committee must have picked this design with care. So clearly I am missing something from C++11.

Aucun commentaire:

Enregistrer un commentaire