다음을 통해 공유


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 삽입 된 값을 생성 하는 데 사용 됩니다.

단일 요소를 삽입 하는 동안 예외가 발생 해도 컨테이너는 변경 되지 않은 한 예외가 다시 throw 됩니다.여러 요소를 삽입 하는 중에 예외를 throw 하는 경우 컨테이너 안정적 이지만 알 수 없는 상태에 왼쪽과 예외가 다시 throw 됩니다.

예제

// 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>

네임 스페이스: 국방 표준

참고 항목

참조

<unordered_set>

unordered_multiset Class

기타 리소스

<unordered_set> 멤버