std::fill
提供: cppreference.com
![]() | このページは、Google 翻訳を使って英語版から機械翻訳されました。 翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
ヘッダ <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.
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. |
型の要件 | ||
-ForwardIt は ForwardIterator の要件を満たさなければなりません。 |
[編集]値を返します
(なし)
[編集]複雑性
まさに
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.
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.
You can help to correct and verify the translation. Click here for instructions.
Run this code
#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
[編集]参照
指定された要素を指定個数の要素にコピー代入します (関数テンプレート) | |
関数を連続的に呼び出した結果を指定範囲の全要素に代入します (関数テンプレート) | |
指定範囲の要素に関数を適用します (関数テンプレート) |