次の方法で共有


multimap::emplace_hint

Inserts an element constructed in place into a map, with a placement hint.

template<class ValTy>
   pair<iterator, bool> emplace_hint(
      const_iterator _Where,
      ValTy&& _Val
);

Parameters

Parameter

Description

_Val

The value of an element to be inserted into the multimap Class unless the multimap already contains that element or, more generally, an element whose key is equivalently ordered.

_Where

A hint regarding the place to start searching for the correct point of insertion.

Return Value

The multimap::emplace member function returns a pair whose bool component returns true if an insertion was made and false if the map already contained an element whose key had an equivalent value in the ordering, and whose iterator component returns the address where a new element was inserted or where the element was already located.

To access the iterator component of a pair pr returned by this member function, use pr.first, and to dereference it, use *(pr.first). To access the bool component of a pair pr returned by this member function, use pr.second.

Remarks

The multimap::value_type of an element is a pair, so that the value of an element will be an ordered pair with the first component equal to the key value and the second component equal to the data value of the element.

Example

// multimap_emplace_hint.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
#include <string>

int main( ) {
    using namespace std;
    multimap<int, string> m1;
    pair<int, string> is1(1, "a");

    m1.emplace(m1.begin(), move(is1));
    cout << "After the emplace insertion, m1 contains:" << endl
      << " " << m1.begin()->first
      << " => " << m1.begin()->second
      << endl;
}

Output

After the emplace insertion, m1 contains:
 1 => a

Requirements

Header: <map>

Namespace: std

See Also

Reference

multimap Class

Standard Template Library

Other Resources

multimap Members