std::fill
Preenche um intervalo [first, last)
com um valor específico.
- Cabeçalho:
<algorithm>
- Assinatura:
fill(ForwardIt first, ForwardIt last, const T& value);
- Parâmetros:
- first, last - Iteradores que definem o intervalo a ser preenchido.
- value - Valor a ser atribuído aos elementos.
- Retorno: Nenhum (void).
- Exceções: Nenhuma, a menos que operações de atribuição lancem.
- Versão:
C++98
- Performance: O(N), onde N é o número de elementos no intervalo.
- Exemplo:
#include <algorithm>
#include <vector>
#include <iostream>
int main() {
std::vector<int> vec(5);
std::fill(vec.begin(), vec.end(), 42);
for (int x : vec) std::cout << x << " "; // Imprime: 42 42 42 42 42
return 0;
}