multimap::emplace_hint
描述 (Description)
C ++函数std::multimap::emplace_hint()使用提示作为元素的位置在多图中插入一个新元素。
声明 (Declaration)
以下是std :: multimap :: emplace_hint()函数形式std :: map头的声明。
C++11
template <class... Args>
iterator emplace_hint (const_iterator position, Args&&... args);
参数 (Parameters)
position - 提示插入元素的位置。
args - 转发以构造新元素的参数。
返回值
返回新插入元素的迭代器。
异常 (Exceptions)
如果抛出异常,对容器没有影响。
时间复杂
对数即O(log n)
例子 (Example)
以下示例显示了std :: multimap :: emplace_hint()函数的用法。
#include <iostream>
#include <map>
using namespace std;
int main(void) {
multimap<char, int> m {
{'b', 2},
{'c', 3},
{'d', 4},
};
m.emplace_hint(m.begin(), 'a', 1);
m.emplace_hint(m.end(), 'e', 5);
cout << "Multimap contains following elements" << endl;
for (auto it = m.begin(); it != m.end(); ++it)
cout << it->first << " = " << it->second << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 -
Multimap contains following elements
a = 1
b = 2
c = 3
d = 4
e = 5