std::fill_n
提供:cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <algorithm>
|
||
| template< class OutputIt, class Size, class T > void fill_n( OutputIt first, Size count, const T& value ); |
(C + + 11時まで) (C + + 11以来) |
|
value場合countで範囲の先頭で最初first要素に指定された値count>0を割り当てます。そうでなければ何もしません.Original:
Assigns the given value
value to the first count elements in the range beginning at first if count>0. Does nothing otherwise.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 | - | 変更する要素の範囲の先頭
Original: the beginning of 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. |
| count | - | 変更する要素の数
Original: number 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. |
| Type requirements | ||
-OutputIt must meet the requirements of OutputIterator.
| ||
[編集] 値を返します
(なし)(C + + 11時まで)
Original:
(none) (C + + 11時まで)
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.
count>0、firstそうでない場合、割り当てられた最後の要素の反復子1。 (C + + 11以来)Original:
Iterator one past the last element assigned if
count>0, first otherwise. (C + + 11以来)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.
[編集] 複雑
countため正確count>0割り当て、.Original:
Exactly
count assignments, for count>0.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 OutputIt, class Size, class T> OutputIt fill_n(OutputIt first, Size count, const T& value) { for (Size i = 0; i < count; i++) { *first++ = value; } return first; } |
[編集] 例
次のコードは、整数のベクタの最初の半分に-1を代入する
fill_n()使用しています
Original:
The following code uses
fill_n() to assign -1 to the first half of a vector of integers:
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() { std::vector<int> v1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; std::fill_n(v1.begin(), 5, -1); for (vector<int>::iterator it = v1.begin(); it != v1.end(); ++it) { std::cout << *it << " "; } std::cout << "\n"; }
Output:
-1 -1 -1 -1 -1 5 6 7 8 9
[編集] も参照してください
| 要素の範囲を特定の値を割り当てます Original: assigns a range of elements a certain value The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (関数テンプレート) | |