In the first version (with iterators), the new contents are a copy of the elements in the sequence between first and last (in the range [first,last)).
In the second version, the new content is the repetition n times of copies of element u.
Parameters
- first, last
- Input iterators to the initial and final positions in a sequence. The range used is [first,last), which includes all the elements between first and last, including the element pointed by first but not the element pointed by last.
The template type can be any type of input iterator. - n
- Times that u is repeated to form the new content of the object.
Member type size_type is an unsigned integral type. - u
- Value to be repeated n times as the new content of the object.
T is the first class template parameter (the type of the elements stored in the vector).
Return value
noneExample
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
Output:
Size of first: 7 Size of second: 5 Size of third: 3 |
Complexity
Linear on initial and final sizes (destruction, copy construction).In the case of the iteration version, if the iterators are forward, bidirectional or random-access, the new capacity is determined before beginning, otherwise logarithmic complexity (object reallocations) must be added on top of that.
See also
| vector::operator= | Copy vector content (public member function) |
