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

std::fill_n

提供: cppreference.com
< cpp‎ | algorithm

 
 
アルゴリズムライブラリ
実行ポリシー (C++17)
非変更シーケンス操作
(C++11)(C++11)(C++11)
(C++17)
変更シーケンス操作
未初期化記憶域の操作
分割操作
ソート操作
バイナリサーチ操作
集合操作 (ソート済み範囲に対する)
ヒープ操作
(C++11)
最小/最大演算
(C++11)
(C++17)
順列
数値演算
C のライブラリ
 
ヘッダ <algorithm> で定義
template<class OutputIt, class Size, class T >

void fill_n( OutputIt first, Size count, const T& value );
template<class OutputIt, class Size, class T >

OutputIt 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.

目次

[編集]パラメータ

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.
型の要件
-
OutputItOutputIterator の要件を満たさなければなりません。

[編集]値を返します

(なし)(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.
count>0firstそうでない場合、割り当てられた最後の要素の反復子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.

[編集]複雑性

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.

[編集]可能な実装

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.

#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";}

出力:

-1 -1 -1 -1 -1 5 6 7 8 9

[編集]参照

指定された要素を範囲内の全要素にコピー代入します
(関数テンプレート)[edit]
close