vector_pro::assign¶
C++
// range
void assign(iterator_pro<value_type> from, iterator_pro<value_type> exclude_to);
// fill
void assign(size_type num, const value_type& val);
// initializer list
void assign(std::initializer_list<value_type> another);
Assign vector content¶
Assigns new contents to the container, replacing its current contents, and modifying its size accordingly.
-
range version
the new contents are elements constructed from each of the elements in the range[from, exclude_to), in the same order. -
fill version
the new contents arenumelements, each initialized to a copy ofval. -
initializer list version
the new contents are copies of the values passed as initializer list, in the same order.
Parameters¶
from,exclude_to
Input iterators to the initial and final positions in a sequence. The range used is[from, exclude_to), which includes all the elements betweenfromandexclude_to, including the element pointed byfrombut not the element pointed byexclude_to.num
New size for the container.val
Value to fill the container with.another
Anstd::inializer_listobject of the same type.
Example¶
C++
// vector_pro assign
#include <iostream>
#include "vector_pro.h"
/**
* Output:
* Size of first: 7
* Size of second: 5
* Size of third: 3
*/
int main ()
{
vector_pro<int> first;
vector_pro<int> second;
vector_pro<int> third;
first.assign (7,100); // 7 ints with a value of 100
iterator_pro<int> it;
it=first.begin()+1;
second.assign (it,first.end()-1); // the 5 central values of first
third.assign ({1, 2, 3}); // assigning from array.
std::cout << "Size of first: " << int (first.size()) << '\n';
std::cout << "Size of second: " << int (second.size()) << '\n';
std::cout << "Size of third: " << int (third.size()) << '\n';
return 0;
}
Complexity¶
Linear on initial and final sizes (destructions, constructions).