list::emplace

Inserts an element constructed in place into a list at a specified position.

void emplace_back( 
   iterator _Where, 
   Type&& _Val 
);

Parameters

Parameter

Description

_Where

The position in the target list Class where the first element is inserted.

_Val

The element added to the end of the list.

Remarks

If an exception is thrown, the list is left unaltered and the exception is rethrown.

Example

// list_emplace.cpp
// compile with: /EHsc
#include <list>
#include <iostream>
#include <string>

int main( ) 
{
   using namespace std;
   list <string> c2;
   string str("a");

   c2.emplace(c2.begin(), move( str ) );
   cout << "Moved first element: " << c2.back( ) << endl;
}
Moved first element: a

Requirements

Header: <list>

Namespace: std

See Also

Reference

list Class

Standard Template Library