Udostępnij za pośrednictwem


multimap::insert

Wstawia element lub zakres elementów do Mapa wielokrotnego dopasowania.

iterator insert(
   const value_type& _Val
);
iterator insert(
   iterator _Where,
   const value_type& _Val
);
template<class InputIterator> 
   void insert(
      InputIterator _First,
      InputIterator _Last
   );
template<class ValTy>
   iterator insert(
      ValTy&& _Val
);
template<class ValTy>
   iterator insert(
      const_iterator _Where,
      ValTy&& _Val
);

Parametry

Parametr

Opis

_Val

Wartość elementu wstawiony Mapa wielokrotnego dopasowania, chyba że Mapa wielokrotnego dopasowania zawiera już tego elementu lub, bardziej ogólnie, element, którego klucz równoważnie porządkowania.

_Where

Wskazówki dotyczące miejsca, aby rozpocząć wyszukiwanie poprawne punkt wstawiania.

_First

Pozycja pierwszego elementu, które mają być kopiowane z mapy.

_Last

Pozycja tylko poza ostatni element do skopiowania z mapy.

Wartość zwracana

Wstawić funkcji elementów członkowskich zwraca iterację, który wskazuje miejsce, gdy nowy element został wstawiony Mapa wielokrotnego dopasowania.

Uwagi

Value_type elementu jest para, tak aby wartość elementu pary, z pierwszego składnika równego wartości klucza i drugi element równy wartości danych elementu.

Wstawiania może wystąpić w czasie stała amortized wersji Wskazówka Wstaw nie logarytmiczna przy, jeśli punkt wstawiania następuje bezpośrednio _Where.

Trzecią funkcję Członkowskie wstawia sekwencja wartości elementu do mapy odpowiadające każdemu elementowi adresowane przez iterację w zakresie [_First, _Last) określonego zestawu.

Funkcje składowe dwóch ostatnich, działają tak samo jako pierwsze dwa, z wyjątkiem _Val jest używana do skonstruowania wartości wstawione.

Przykład

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

int main( )
{
   using namespace std;
   multimap <int, int>::iterator m1_pIter, m2_pIter;

   multimap <int, int> m1, m2;
   typedef pair <int, int> Int_Pair;

   m1.insert ( Int_Pair ( 1, 10 ) );
   m1.insert ( Int_Pair ( 2, 20 ) );
   m1.insert ( Int_Pair ( 3, 30 ) );

   cout << "The original key values of m1 =";
   for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
      cout << " " << m1_pIter -> first;
   cout << "." << endl;

   cout << "The original mapped values of m1 =";
   for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
      cout << " " << m1_pIter -> second;
   cout << "." << endl;

   m1.insert ( Int_Pair ( 1, 10 ) );

   // The hint version of insert
   m1.insert( --m1.end( ), Int_Pair ( 4, 40 )  );

   cout << "After the insertions, the key values of m1 =";
   for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
      cout << " " << m1_pIter -> first;
   cout << "," << endl;

   cout << " and the mapped values of m1 =";
   for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
      cout << " " << m1_pIter -> second;
   cout << "." << endl;

   m2.insert ( Int_Pair ( 10, 100 ) );

   // The templatized version inserting a range
   m2.insert( ++m1.begin( ), --m1.end( ) );

   cout << "After the insertions, the key values of m2 =";
   for ( m2_pIter = m2.begin( ); m2_pIter != m2.end( ); m2_pIter++ )
      cout << " " << m2_pIter -> first;
   cout << "," << endl;

   cout << " and the mapped values of m2 =";
   for ( m2_pIter = m2.begin( ); m2_pIter != m2.end( ); m2_pIter++ )
      cout << " " << m2_pIter -> second;
   cout << "." << endl;

    // The templatized versions move constructing elements
    multimap<int, string> m3, m4;
    pair<int, string> is1(1, "a"), is2(2, "b");

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

    m4.insert(c4.begin(),move(is2));
    cout << "After the move insertion, m4 contains:" << endl
      << " " << m4.begin()->first
      << " => " << m4.begin()->second
      << endl;
}
  
  
  
  
  

Wymagania

Nagłówek: <map>

Obszar nazw: std

Zobacz też

Informacje

multimap Class

Standardowa biblioteka szablonu