namespace std::ranges {
template <class T,
output_iterator<const T&> O,
sentinel_for<O> S>
constexpr O
fill(O first, S last, const T& value); // (1) C++20
template <class T,
output_range<const T&> R>
constexpr borrowed_iterator_t<R>
fill(R&& r, const T& value); // (2) C++20
}
概要
指定された値で出力の範囲に書き込む。
- (1): イテレータ範囲を指定する
- (2): Rangeを直接指定する
効果
[first,last)
内の全ての要素に value
を代入する
戻り値
last
計算量
正確に last - first
回の代入を行う
例
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v(5);
// v を 3 の値で埋める
std::ranges::fill(v, 3);
for (int x : v) {
std::cout << x << ",";
}
}
出力
3,3,3,3,3,
バージョン
言語
- C++20
処理系
- Clang: ??
- GCC: 10.1.0 ✅
- ICC: ??
- Visual C++: 2019 Update 10 ✅