unordered_multiset::insert

添加元素。

iterator insert(const value_type& val);
iterator insert(iterator where, const value_type& val);
template<class InIt>
    void insert(InIt first, InIt last);
template<class ValTy>
    iterator insert(ValTy&& val);
template<class ValTy>
    iterator insert(const_iterator where, ValTy&& val);

参数

Parameter

说明

InIt

迭代器类型。

ValTy

就地构造函数参数类型。

first

范围开头插入的。

last

范围的末尾插入的。

val

要插入的值。

where

在插入 (仅提示的容器)。

备注

第一个成员函数插入元素 val 在控件序列,然后返回指定为插入的元素的迭代器。 ,在搜索的控件序列中的起始位置插入点,第二个成员函数返回 insert(val),使用 where 。 (插入某些可能更快,可能会发生,如果插入点紧邻或遵循 where。)

元素顺序值的第三个成员函数插入,每 where 的范围内 [first, last),通过调用 insert(*where)。

最后两个成员函数的行为与前两个相同,不同之处在于, val 用于构造该插入的值。

如果在单个元素的插入时引发,容器未更改,并且异常来重新引发。 如果在多个组件的插入时引发,容器在稳定左侧,但未指定的状态和异常来重新引发。

示例

// std_tr1__unordered_set__unordered_multiset_insert.cpp 
// compile with: /EHsc 
#include <unordered_set> 
#include <iostream>
#include <string> 
 
typedef std::unordered_multiset<char> Myset; 
int main() 
    { 
    Myset c1; 
 
    c1.insert('a'); 
    c1.insert('b'); 
    c1.insert('c'); 
 
// display contents " [c] [b] [a]" 
    for (Myset::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " [" << *it << "]"; 
    std::cout << std::endl; 
 
// insert with hint and reinspect 
    Myset::iterator it2 = c1.insert(c1.begin(), 'd'); 
    for (Myset::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " [" << *it << "]"; 
    std::cout << std::endl; 
 
// insert range and inspect 
    Myset c2; 
 
    c2.insert(c1.begin(), c1.end()); 
    for (Myset::const_iterator it = c2.begin(); 
        it != c2.end(); ++it) 
        std::cout << " [" << *it << "]"; 
    std::cout << std::endl; 
 
// insert new and duplicate, and reinspect 
    c1.insert('e'); 
    c1.insert('a'); 
    for (Myset::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " [" << *it << "]"; 
    std::cout << std::endl; 
 
// The templatized versions move constructing elements
    unordered_multiset< string> c3, c4;
    string str1("a"), str2("b");

    c3.insert(move(is1));
    cout << "After the move insertion, c3 contains: "
        << *c3.begin() << endl;

    c4.insert(c4.begin(), move(is2));
    cout << "After the move insertion, c4 contains: "
        << *c4.begin() << endl;

    return (0); 
    } 
 
  

要求

**标题:**unordered_set

命名空间: std

请参见

参考

<unordered_set>

unordered_multiset Class

其他资源

unordered_set 成员