(C++) std::fill
February 24, 2017 · View on GitHub
(C++) std::fill
std::fill is an STL algorithm to assign values to a container.
#include <algorithm> #include <cassert> #include <numeric> #include <vector> int main() { //Create a std::vector storing '1' 10x std::vector<int> v(10,1); //10 x 1 = 10 assert(std::accumulate(v.begin(),v.end(),0)==10); //Fill the std::vector with '2' std::fill(v.begin(),v.end(),2); //10 x 2 = 20 assert(std::accumulate(v.begin(),v.end(),0)==20); }