If I wanted to copy the same value across an iterator range, I would think that it would be easy to have a noop iterator where you pass it a value, and when it is incremented, it would not move anywhere. This would allow using the existing std::copy and std::copy_if algorithms.
However, I can't seem to find such a beast. Am I going to have to roll my own?
Use std::fill or std::fill_n algorithm.
Some containers, e.g. std::vector<> and std::list<>, have a constructor with size and initializer:
std::vector<int> v(10, 42); // 42 is the initializer
v.resize(20, 42); // Initialize new elements with 42.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With