std::fill
提供: cppreference.com
![]() | このページは、Google 翻訳を使って英語版から機械翻訳されました。 翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
Defined in header <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.
このコードを実行します
#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
[編集]参照
要素の数に値を代入します Original: assigns a value to a number of elements The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (関数テンプレート) | |
範囲内の関数の結果を保存します Original: saves the result of a function in a range The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (関数テンプレート) | |
ある範囲の要素に関数が適用されます Original: applies a function to a range of elements The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (関数テンプレート) |