std::multimap<Key,T,Compare,Allocator>::emplace

Inserts a new element into the container constructed in-place with the given args.

# Declarations

template< class... Args >
iterator emplace( Args&&... args );

(since C++11)

# Parameters

# Return value

An iterator to the inserted element.

# Example

#include <iostream>
#include <string>
#include <utility>
#include <map>
 
int main()
{
    std::multimap<std::string, std::string> m;
 
    // uses pair's move constructor
    m.emplace(std::make_pair(std::string("a"), std::string("a")));
 
    // uses pair's converting move constructor
    m.emplace(std::make_pair("b", "abcd"));
 
    // uses pair's template constructor
    m.emplace("d", "ddd");
 
    // emplace with duplicate key 
    m.emplace("d", "DDD");
 
    // uses pair's piecewise constructor
    m.emplace(std::piecewise_construct,
              std::forward_as_tuple("c"),
              std::forward_as_tuple(10, 'c'));
 
    for (const auto& p : m)
        std::cout << p.first << " => " << p.second << '\n';
}

# See also