std::fill_n - cppreference.com
De cppreference.com
<metanoindex/>
<tbody> </tbody>
| Definido no cabeçalho <algorithm> |
||
|
|
(até C++11) (desde C++11) |
|
Atribui o value valor dado aos elementos count primeira no início gama de first se count>0. Não faz nada de outra forma.
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.
Parâmetros
| first | - | o início do intervalo de elementos para modificar Original: the beginning of the range of elements to modify The text has been machine-translated via Google Translate. |
| count | - | número de elementos a modificar Original: number of elements to modify The text has been machine-translated via Google Translate. |
| value | - | o valor a ser atribuído Original: the value to be assigned The text has been machine-translated via Google Translate. |
| Type requirements | ||
-OutputIt must meet the requirements of OutputIterator.
| ||
Valor de retorno
(Nenhum) (até C++11)
Original:
(none) (até C++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Iterator um passado o último elemento atribuído se count>0, first contrário. (desde C++11)
Original:
Iterator one past the last element assigned if count>0, first otherwise. (desde C++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Complexidade
Exactamente atribuições count, por 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.
Possível implementação
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; }
Exemplo
O código a seguir usa fill_n() atribuir -1 a primeira metade de um vetor de números inteiros:
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"; }
Saída:
Veja também
atribui um intervalo de elementos de um certo valor Original: assigns a range of elements a certain value The text has been machine-translated via Google Translate. (modelo de função) [edit] | |