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

std::fill_n

提供: cppreference.com
< cpp‎ | algorithm

 
 
アルゴリズムライブラリ
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
シーケンス動作を非改変
Original:
Non-modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
シーケンス動作を変更する
Original:
Modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
操作を仕切る
Original:
Partitioning operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(ソートされた範囲で)ソート操作
Original:
Sorting operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
バイナリ検索操作(ソート範囲で)
Original:
Binary search operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(ソートされた範囲で)操作を設定します
Original:
Set operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ヒープ操作
Original:
Heap operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
最小値/最大値操作
Original:
Minimum/maximum operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
数値演算
Original:
Numeric operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Cライブラリ
Original:
C library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Defined in header <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

[編集]参照

要素の範囲を特定の値を割り当てます
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.

(関数テンプレート)[edit]
close