Assigns the given value to all elements in the range [
first,
first + n)
.
The function-like entities described on this page are algorithm function objects (informally known as niebloids), that is:
An output iterator that compares equal to first + n.
[edit] ComplexityExactly n assignments.
[edit] Possible implementation [edit] Notes [edit] Example#include <algorithm> #include <complex> #include <iostream> #include <string> #include <vector> void println(const auto& v) { for (const auto& elem : v) std::cout << ' ' << elem; std::cout << '\n'; } int main() { constexpr auto n{8}; std::vector<std::string> v(n, "ââââ"); println(v); std::ranges::fill_n(v.begin(), n, "ââââ"); println(v); std::vector<std::complex<double>> nums{{1, 3}, {2, 2}, {4, 8}}; println(nums); #ifdef __cpp_lib_algorithm_default_value_type std::ranges::fill_n(nums.begin(), 2, {4, 2}); #else std::ranges::fill_n(nums.begin(), 2, std::complex<double>{4, 2}); #endif println(nums); }
Output:
ââââ ââââ ââââ ââââ ââââ ââââ ââââ ââââ ââââ ââââ ââââ ââââ ââââ ââââ ââââ ââââ (1,3) (2,2) (4,8) (4,2) (4,2) (4,8)[edit] See also assigns a range of elements a certain value
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4