function template
<algorithm>
std::filltemplate <class ForwardIterator, class T> void fill (ForwardIterator first, ForwardIterator last, const T& val);
Fill range with value
Assigns val to all the elements in the range[first,last)
.
The behavior of this function template is equivalent to:
1
2
3
4
5
6
7
8
template <class ForwardIterator, class T>
void fill (ForwardIterator first, ForwardIterator last, const T& val)
{
while (first != last) {
*first = val;
++first;
}
}
[first,last)
, which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// fill algorithm example
#include <iostream> // std::cout
#include <algorithm> // std::fill
#include <vector> // std::vector
int main () {
std::vector<int> myvector (8); // myvector: 0 0 0 0 0 0 0 0
std::fill (myvector.begin(),myvector.begin()+4,5); // myvector: 5 5 5 5 0 0 0 0
std::fill (myvector.begin()+3,myvector.end()-2,8); // myvector: 5 5 5 8 8 8 0 0
std::cout << "myvector contains:";
for (std::vector<int>::iterator it=myvector.begin(); it!=myvector.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}
myvector contains: 5 5 5 8 8 8 0 0
[first,last)
are modified (each object is accessed exactly once).
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4