Is there an equivalent of vec![n; len]
that fills an existing vector with a given value? (i.e. sets every element to n)
I thought I’ve seen something like vec.fill(n)
, but it doesn’t exist.
Is there an equivalent of vec![n; len]
that fills an existing vector with a given value? (i.e. sets every element to n)
I thought I’ve seen something like vec.fill(n)
, but it doesn’t exist.
.resize() if you want to add them as new elements, and a for loop if you want to overwrite. (Yes resize ends up using the same code path as the vec![]
macro for adding elements).