Skip to content

vector_pro::operator=

C++
void operator= (const vector_pro<value_type>& another);
void operator= (vector_pro<value_type>&& another);
void operator= (const std::vector<value_type>& another);
void operator= (const std::initializer_list<value_type>& another);

Assign content

Assigns new contents to the container, replacing its current contents, and modifying its size accordingly.

  1. copy assignment
    Copies all the elements from another into the container.
  2. move assignment
    Moves all the elements from another into the container.
  3. std::vector assignment
    Copies all the elements from another into the container.
  4. initializer list assignment
    Copies all the elements from another into the container.

Parameters

  1. another
    Can be a std::vector , std::inializer_list or just another vector_pro.

Return value

*this .

Example

C++
// vector_pro::operator=
#include <iostream>
#include "vector_pro.h"

/**
 * Output:
 * Size of foo: 0
 * Size of bar: 3
 */

int main ()
{
  vector_pro<int> foo (3,0);
  vector_pro<int> bar (5,0);

  bar = foo;
  foo = vector_pro<int>();

  std::cout << "Size of foo: " << int(foo.size()) << '\n';
  std::cout << "Size of bar: " << int(bar.size()) << '\n';
  return 0;
}

Complexity

Linear in size.