다음을 통해 공유


hash_map::insert (STL/CLR)

요소를 추가합니다.

    cliext::pair<iterator, bool> insert(value_type val);
    iterator insert(iterator where, value_type val);
    template<typename InIter>
        void insert(InIter first, InIter last);
    void insert(System::Collections::Generic::IEnumerable<value_type>^ right);

매개 변수

  • 첫 번째
    삽입할 범위의 시작 부분입니다.

  • last
    삽입 범위 끝입니다.

  • right
    삽입할 열거형입니다.

  • val 함수
    삽입할 키 값입니다.

  • where
    (힌트에만 해당)를 삽입 하려면 컨테이너에 위치 합니다.

설명

각 멤버 함수는 나머지 피연산자를 통해 지정 된 시퀀스를 삽입 합니다.

멤버 함수는 첫 번째 노력 값 가진 요소를 삽입 하려면 val, 한 쌍의 값을 반환 하 고 X.경우 X.second 는 X.first ; 새로 삽입 된 요소를 지정 합니다. 그렇지 않으면 X.first 요소에 해당 하는 지정 순서는 이미 존재 하 고 새 요소를 삽입 합니다.이 단일 요소를 삽입할 수 있습니다.

요소 값을 삽입 하는 두 번째 멤버 함수 val사용 하 여 where (성능 향상을 위해)을 힌트로 새로 삽입 된 요소를 지정 하는 반복기를 반환 합니다.아시다시피 요소에 인접 한 일 수 있는 단일 요소를 삽입 하려면 사용 합니다.

셋째 멤버 함수 시퀀스 삽입 [first, last).다른 시퀀스를 복사 하는 0 개 이상의 요소를 삽입 하려면 사용 합니다.

순서 지정을 삽입 하는 네 번째 멤버 함수는 right.이 열거형에서 설명 하는 시퀀스를 삽입할 수 있습니다.

각 요소 삽입 요소 수의 밑에 비례 제어 되는 시퀀스에 걸립니다.하지만 삽입 amortized 상수 시간에 삽입점에 인접 하는 요소를 지정 하는 힌트를 제공 발생할 수 있습니다.

예제

// cliext_hash_map_insert.cpp 
// compile with: /clr 
#include <cliext/hash_map> 
 
typedef cliext::hash_map<wchar_t, int> Myhash_map; 
typedef Myhash_map::pair_iter_bool Pairib; 
int main() 
    { 
    Myhash_map c1; 
    c1.insert(Myhash_map::make_value(L'a', 1)); 
    c1.insert(Myhash_map::make_value(L'b', 2)); 
    c1.insert(Myhash_map::make_value(L'c', 3)); 
 
// display contents " [a 1] [b 2] [c 3]" 
    for each (Myhash_map::value_type elem in c1) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// insert a single value, unique and duplicate 
    Pairib pair1 = 
        c1.insert(Myhash_map::make_value(L'x', 24)); 
    System::Console::WriteLine("insert([L'x' 24]) = [{0} {1}] {2}", 
        pair1.first->first, pair1.first->second, pair1.second); 
 
    pair1 = c1.insert(Myhash_map::make_value(L'b', 2)); 
    System::Console::WriteLine("insert([L'b' 2]) = [{0} {1}] {2}", 
        pair1.first->first, pair1.first->second, pair1.second); 
 
    for each (Myhash_map::value_type elem in c1) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// insert a single value with hint 
    Myhash_map::iterator it = 
        c1.insert(c1.begin(), Myhash_map::make_value(L'y', 25)); 
    System::Console::WriteLine("insert(begin(), [L'y' 25]) = [{0} {1}]", 
        it->first, it->second); 
    for each (Myhash_map::value_type elem in c1) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// insert an iterator range 
    Myhash_map c2; 
    it = c1.end(); 
    c2.insert(c1.begin(), --it); 
    for each (Myhash_map::value_type elem in c2) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// insert an enumeration 
    Myhash_map c3; 
    c3.insert(   // NOTE: cast is not needed 
        (System::Collections::Generic:: 
            IEnumerable<Myhash_map::value_type>^)%c1); 
    for each (Myhash_map::value_type elem in c3) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
    return (0); 
    } 
 
  

요구 사항

헤더: < cliext/hash_map >

네임 스페이스: cliext

참고 항목

참조

hash_map (STL/CLR)