boost::range::fill_n

References

Headers

boost::range::fill_n is available by including any of the following headers:

  • boost/range/algorithm/fill_n.hpp or
  • boost/range/algorithm.hpp

Examples

fill.cpp

#include <iostream>
#include <vector>
#include <boost/range/algorithm.hpp>

int main() {
    std::vector<int> vec = {1, 2, 3, 4, 5};

    // Fill the whole vector with zero.
    boost::range::fill(vec, 0);

    // Set the first three elements to 42.
    // The order of arguments is (n, value), consistent with fill constructors.
    // n must be smaller or equal to size(vec).
    boost::range::fill_n(vec, 3, 42);

    return 0;
}

Output:

 

Boost Range for Humans

This reference is part of Boost Range for Humans. Click the link to the overview.