vendredi 5 juin 2015

Increase vector values by a constant floating point value

I know iota function, but it will just work integer values since it is calling ++ operator.

I have to increase my vector by lets say 0.5 like [0.5, 1, 1.5....]

The final solution I came up with is :

    double last = 0;
    std::generate(out , out + 10, [&]{
        return last += 0.5; 
    }); 

Which kind of works but I have to use a extra variable. Is there a std func that I am missing like D iota auto rf = iota(0.0, 0.5, 0.1);

Aucun commentaire:

Enregistrer un commentaire