Share via


vector::emplace_back

Adds an element constructed in place to the end of the vector.

template <class... Types>
    void emplace_back(
        Types&&... _Args);

Parameters

Parameter

Description

_Args

Constructor arguments. The function infers which constructor overload to invoke based on the arguments provided.

Remarks

When possible, use emplace to avoid the copy operation that occurs when you initialize an object obj and then call push_back(obj).

Example

#include <vector>
struct obj
{
   obj(int, double) {}
};

int main()
{
   std::vector<obj> v;
   v.emplace_back(1, 3.14); // obj in created in place in the vector
}

Requirements

Header: <vector>

Namespace: std

See Also

Reference

vector Class

Standard Template Library