Skip to content

vector_pro::emplace

C++
size_type emplace_back(const value_type& val);

Construct and insert element at the end

Inserts a new element at the end of the vector, right after its current last element.

A similar member function exists, vector_pro::push_back , which either copies or moves an existing object into the container.

Parameters

  1. val
    Value of the new element.

Return value

none

Example

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

/**
 * Output:
 * myvector contains: 10 20 30 100 200
 */

int main ()
{
  vector_pro<int> myvector = {10,20,30};

  myvector.emplace_back (100);
  myvector.emplace_back (200);

  std::cout << "myvector contains:";
  for (auto& x: myvector)
    std::cout << ' ' << x;
  std::cout << '\n';

  return 0;
}

Complexity

Constant (amortized time, reallocation may happen).