The Wayback Machine - https://web.archive.org/web/20180429132243/http://ja.cppreference.com:80/w/cpp/algorithm/fill
名前空間
変種
操作

std::fill

提供: cppreference.com
< cpp‎ | algorithm

 
 
アルゴリズムライブラリ
実行ポリシー (C++17)
非変更シーケンス操作
(C++11)(C++11)(C++11)
(C++17)
変更シーケンス操作
未初期化記憶域の操作
分割操作
ソート操作
バイナリサーチ操作
集合操作 (ソート済み範囲に対する)
ヒープ操作
(C++11)
最小/最大演算
(C++11)
(C++17)
順列
数値演算
C のライブラリ
 
ヘッダ <algorithm> で定義
template<class ForwardIt, class T >
void fill( ForwardIt first, ForwardIt last, const T& value );
レンジvalue内の要素に与え[first, last)を代入.
Original:
Assigns the given value to the elements in the range [first, last).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集]パラメータ

first, last -
変更する要素の範囲
Original:
the range of elements to modify
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
value -
値が割り当てられる
Original:
the value to be assigned
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
型の要件
-
ForwardItForwardIterator の要件を満たさなければなりません。

[編集]値を返します

(なし)

[編集]複雑性

まさにlast - first割り当て.
Original:
Exactly last - first assignments.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]可能な実装

template<class ForwardIt, class T >void fill(ForwardIt first, ForwardIt last, const T& value){for(; first != last;++first){*first = value;}}

[編集]

次のコードは、-1までの整数のベクトルのすべての要素を設定するfill()使用しています
Original:
The following code uses fill() to set all of the elements of a vector of integers to -1:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <algorithm>#include <vector>#include <iostream>   int main(){int data[]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9}std::vector<int> v1(data, data+10);   std::fill(v1.begin(), v1.end(), -1);   for(vector<int>::iterator it = v1.begin(); it != v1.end();++it){std::cout<<*it <<" ";}std::cout<<"\n";}

出力:

-1 -1 -1 -1 -1 -1 -1 -1 -1 -1

[編集]参照

指定された要素を指定個数の要素にコピー代入します
(関数テンプレート)[edit]
関数を連続的に呼び出した結果を指定範囲の全要素に代入します
(関数テンプレート)[edit]
指定範囲の要素に関数を適用します
(関数テンプレート)[edit]
close