I have just been burned by the following.
If I want to initialize a std::vector
of n
elements with a constant X
I do this:
std::vector<double> v(n, X);
But if I need to initialize a std::valarray
of n
elements with a constant X
I need to swap the size and initializing constant:
std::valarray<double> va(X, n);
This seems to me like an arbitrary 'gotcha'.
Is there a technical reason or some design rationale provided by the standards committee when deciding about the order of the fill constructor's parameters when std::vector
and std::valarray
were standardized?