std::generate_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 Generator > void generate_n( OutputIt first, Size count, Generator g ); |
(C + + 11時まで) (C + + 11以来) |
|
g場合、countで範囲の先頭で最初first要素に、指定された関数オブジェクトcount>0によって生成された値を、代入します。そうでなければ何もしません.Original:
Assigns values, generated by given function object
g, 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 generate 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 the elements to generate The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |||||||||
| g | - | generator function object that will be called. The signature of the function should be equivalent to the following:
The type Ret must be such that an object of type OutputIt can be dereferenced and assigned a value of type Ret. | |||||||||
| 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用g()および割り当ての正確count>0呼び出し、.Original:
Exactly
count invocations of g() and 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 Generator > OutputIt generate_n( OutputIt first, Size count, Generator g ) { for( Size i = 0; i < count; i++ ) { *first++ = g(); } return first; } |
[編集] 例
次のコードは、乱数を整数の配列を埋め.
Original:
The following code fills an array of integers with random numbers.
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 <cstddef> #include <cstdlib> #include <iostream> #include <iterator> #include <algorithm> int main() { const std::size_t N = 5; int ar[N]; std::generate_n(ar, N, std::rand); // Using the C function rand() std::cout << "ar: "; std::copy(ar, ar+N, std::ostream_iterator<int>(std::cout, " ")); std::cout << "\n"; }
Output:
52894 15984720 41513563 41346135 51451456
[編集] も参照してください
| 要素の数に値を代入します 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. (関数テンプレート) | |