multimap 클래스

C++ 표준 라이브러리 multimap 클래스는 각 요소가 데이터 값과 정렬 키를 모두 포함하는 쌍인 컬렉션에서 데이터를 저장하고 검색하는 데 사용됩니다. 키 값은 고유할 필요가 없으며 데이터를 자동으로 정렬하는 데 사용됩니다. multimap 요소의 값은 연관된 키 값을 제외하고 직접적으로 변경할 수 있습니다. 대신, 이전 요소와 관련된 키 값을 삭제하고 새 요소와 연결된 새 키 값을 삽입해야 합니다.

구문

template <class Key,
    class Type,
    class Traits=less <Key>,
    class Allocator=allocator <pair  <const Key, Type>>>
class multimap;

매개 변수

Key
multimap에 저장되는 키 데이터 형식입니다.

Type
multimap에 저장되는 요소 데이터 형식입니다.

Traits
함수 개체를 제공하는 형식은 multimap 내에서의 상대적인 순서를 결정하는 정렬 키로 두 요소 값을 비교할 수 있습니다. 이진 조건자 less<Key>가 기본값입니다.

C++14에서는 형식 매개 변수가 없는 std::less<> 또는 std::greater<> 조건자를 지정하여 유형이 다른 조회를 사용하도록 설정할 수 있습니다. 자세한 내용은 연관 컨테이너의 유형이 다른 조회를 참조하세요.

Allocator
map의 메모리 할당 및 할당 취소에 대한 세부 정보를 캡슐화하는 저장된 할당자 개체를 나타내는 형식입니다. 이 인수는 선택 사항이며 기본값은 allocator<pair <const Key, Type> >입니다.

설명

C++ 표준 라이브러리 multimap 클래스의 특징은 다음과 같습니다.

  • 연관된 키 값을 기준으로 하며 요소 값의 효율적인 검색을 지원하는 가변 크기 컨테이너인 연관 컨테이너입니다.

  • 이는 해당 요소에 액세스할 수 있는 양방향 반복기를 제공하기 때문에 되돌릴 수 있습니다.

  • 해당 요소가 컨테이너 내에서 지정된 비교 함수에 따라 키 값을 기준으로 정렬되므로 정렬됩니다.

  • 하나의 키 값에 연결된 많은 요소 데이터 값이 있을 수 있도록 해당 요소에 고유 키가 필요하지 않기 때문에 여러 개입니다.

  • 요소의 데이터 값은 키 값과 구별되기 때문에 쌍 연관 컨테이너입니다.

  • 클래스 템플릿은 제공하는 기능이 일반적이고 요소 또는 키로 포함된 특정 데이터 형식과 독립적이기 때문입니다. 요소에 사용될 데이터 형식과 키는 대신 비교 함수 및 할당자와 함께 클래스 템플릿에서 매개 변수로 지정됩니다.

맵 클래스에서 제공하는 반복기는 양방향 반복기이지만 클래스 멤버는 함수를 사용 insert 하며 multimap 템플릿 매개 변수로 사용하는 버전이 약한 입력 반복기로 사용되며, 해당 기능 요구 사항은 양방향 반복기 클래스에서 보장하는 것보다 더 최소화됩니다. 다른 반복기 개념은 관련된 상세 기능별로 범주를 구성합니다. 각 반복기 개념은 고유한 요구 사항이 있으며 이러한 요구 사항을 적용하는 알고리즘은 해당 반복기 형식이 제공하는 요구 사항으로 가정을 제한해야 합니다. 입력 반복기를 역참조하여 몇 가지 개체를 참조하고 시퀀스의 다음 반복기로 증가되는 경우를 가정할 수 있습니다. 이는 최소한의 기능 모음이지만, 클래스 멤버 함수의 맥락에서 반복기 범위([First, Last))에 대해 설명하는 데에는 충분합니다.

컨테이너 형식은 일반적으로 애플리케이션에서 필요한 검색과 삽입의 형식을 기준으로 선택해야 합니다. 연관 컨테이너는 조회, 삽입 및 제거 작업에 최적화되어 있습니다. 이러한 작업을 명시적으로 지원하는 멤버 함수는 컨테이너의 요소 개수를 진수로 하는 로그값에 평균적으로 비례하는 시간 안에 수행하므로 효율적입니다. 요소를 삽입하면 반복기가 무효화되지 않으며 요소를 제거하면 제거된 요소를 가리켰던 반복기만 무효화됩니다.

multimap 애플리케이션에서 해당 키와 값을 연결 하는 조건을 충족 하는 경우 선택 하는 결합 컨테이너 여야 합니다. 이러한 유형의 구조체에 대한 모델은 단어가 항상 고유하게 정의되지 않은 정의와 관련된 문자열 값이 포함된 순서가 지정된 키 단어 목록입니다. 대신 키워드가 고유하게 정의되어 키가 고유한 경우, map이 적절한 컨테이너가 됩니다. 반면에, 단어의 목록만을 저장하는 경우에는 set이 올바른 컨테이너가 됩니다. 여러 단어의 발생이 허용된 multiset 경우 적절한 컨테이너 구조가 됩니다.

multimap 형식key_compare의 저장된 함수 개체를 호출하여 제어하는 시퀀스를 정렬합니다. 이 저장된 개체는 멤버 함수를 호출하여 액세스할 수 있는 비교 함수 key_comp입니다. 일반적으로, 이 순서를 정하려면 요소의 크기를 비교할 수 있어야 합니다. 즉, 제공된 어떤 두 요소에서 두 요소가 동일하거나(어떤 것도 다른 것보다 작지 않음) 하나가 다른 것보다 작음을 정할 수 있어야 합니다. 그러면 동일하지 않은 요소 사이에 정렬이 수행됩니다. 기술적으로 설명하면, 비교 함수는 표준 함수의 의미에서 엄밀히 약한 정렬을 수행하는 이진 조건자입니다. 이진 조건자는 f(x,y) 인수 개체 2 x 개와 y 반환 값 true 또는 false. 집합에 적용되는 순서는 이진 조건자가 비반응성, 대칭 및 전이적이고 등가가 전이적이면 엄격한 약한 순서입니다. 여기서 두 개체 xy 는 둘 다 f(x,y)f(y,x) 와 동일한 것으로 정의됩니다 false. 키 사이의 더 강력한 같음 조건이 동등 조건을 대체하는 경우, 정렬은 전체가 되고(모든 요소가 서로 상대적으로 정렬됨을 의미) 일치된 키는 서로 구분할 수 없게 됩니다.

C++14에서는 형식 매개 변수가 없는 std::less<> 또는 std::greater<> 조건자를 지정하여 유형이 다른 조회를 사용하도록 설정할 수 있습니다. 자세한 내용은 결합 컨테이너에서 다른 유형의 조회를 참조하세요.

멤버

생성자

생성자 Description
multimap 비어 있거나 다른 multimap의 전체 또는 일부의 복사본인 multimap을 생성합니다.

Typedef

형식 이름 설명
allocator_type allocator 개체의 multimap 클래스를 나타내는 형식입니다.
const_iterator const에 있는 multimap 요소를 읽을 수 있는 양방향 반복기를 제공하는 형식입니다.
const_pointer const에 있는 multimap 요소에 대한 포인터를 제공하는 형식입니다.
const_reference const 작업을 읽고 수행하기 위해 multimap에 저장된 const 요소에 대한 참조를 제공하는 형식입니다.
const_reverse_iterator const에 있는 multimap 요소를 읽을 수 있는 양방향 반복기를 제공하는 형식입니다.
difference_type 부호 있는 정수 형식은 반복기가 가리키는 요소 사이의 범위에 있는 multimap의 요소의 개수를 표현하는 데 사용할 수 있습니다.
iterator 동일한 multimap 안에서 요소를 참조하는 두 반복기 사이의 차이를 제공하는 형식입니다.
key_compare multimap의 두 요소간 상대적 순서를 결정하는 두 정렬 키를 비교할 수 있는 함수 개체를 제공하는 형식입니다.
key_type 의 각 요소를 multimap구성하는 정렬 키 개체를 설명하는 형식입니다.
mapped_type multimap 내에 저장된 데이터 형식을 나타내는 형식입니다.
pointer const에 있는 multimap 요소에 대한 포인터를 제공하는 형식입니다.
reference multimap 내에 저장된 요소에 대한 참조를 제공하는 형식입니다.
reverse_iterator 역순 multimap의 요소를 읽거나 수정할 수 있는 양방향 반복기를 제공하는 형식입니다.
size_type constmultimap 요소에 대한 포인터를 제공하는 부호 없는 정수 형식입니다.
value_type 두 요소를 정렬 키로 비교하여 multimap에서 상대적 순서를 결정할 수 있는 함수 개체를 제공하는 형식입니다.

멤버 함수

멤버 함수 설명
begin multimap의 첫 번째 요소를 주소 지정하는 반복기를 반환합니다.
cbegin 에서 const 첫 번째 요소의 주소를 지정하는 반복기를 반환합니다 multimap.
cend 에서 const 마지막 요소 multimap다음에 나오는 위치를 주소 지정하는 반복기를 반환합니다.
clear multimap의 모든 요소를 지웁니다.
containsC++20 에 지정된 키를 multimap가진 요소가 있는지 확인합니다.
count 키가 매개 변수로 지정된 키와 일치하는 multimap의 요소 수를 반환합니다.
crbegin 역방향 multimap요소 const 의 첫 번째 요소 주소를 지정하는 반복기를 반환합니다.
crend 역방향multimapconst 마지막 요소 다음에 나오는 위치를 해결하는 반복기를 반환합니다.
emplace 생성된 요소를 multimap에 삽입합니다.
emplace_hint 배치 힌트를 사용하여 생성된 요소를 multimap에 삽입합니다.
empty multimap가 비어 있는지 여부를 테스트합니다.
end multimap에서 마지막 요소 다음에 나오는 위치를 주소 지정하는 반복기를 반환합니다.
equal_range 요소의 키가 지정된 값과 일치하는 요소 범위를 찾습니다.
erase 지정된 위치에서 multimap의 요소 또는 요소의 범위를 제거하거나 지정된 키와 일치하는 요소를 제거합니다.
find 지정된 키와 같은 키를 가진 multimap 내 요소의 첫 번째 위치를 가리키는 반복기를 반환합니다.
get_allocator allocator을 생성하는 데 사용되는 multimap 개체의 복사본을 반환합니다.
insert multimap에 요소 또는 요소의 범위를 삽입합니다.
key_comp multimap에서 키를 정렬하기 위해 사용하는 비교 개체의 복사본을 검색합니다.
lower_bound multimap에서 지정된 키보다 같거나 큰 키를 가진 첫 번째 요소에 반복기를 반환합니다.
max_size multimap의 최대 길이를 반환합니다.
rbegin 역순 multimap에서 첫 번째 요소를 참조하는 반복기를 반환합니다.
rend 역순 multimap에서 마지막 요소 다음에 나오는 위치를 주소 지정하는 반복기를 반환합니다.
size multimap에 있는 요소 수를 반환합니다.
swap multimap의 요소를 교환합니다.
upper_bound multimap에서 지정된 키보다 큰 키를 가진 첫 번째 요소에 반복기를 반환합니다.
value_comp 멤버 함수는 키 값을 비교하여 multimap의 요소 순서를 결정하는 함수 개체를 반환합니다.
연산자 설명
operator= multimap의 요소를 다른 multimap의 복사본으로 대체합니다.

요구 사항

헤더<map>:

네임스페이스:std

(, ) 쌍은 형식pair의 개체로 multimap 저장됩니다. 쌍 클래스에는 자동으로 포함<map>되는 헤더<utility>가 필요합니다.

multimap::allocator_type

개체의 할당자 클래스를 multimap 나타내는 형식입니다.

typedef Allocator allocator_type;

예시

를 사용하는 예제는 예제 get_allocator 를 참조하세요 allocator_type.

multimap::begin

multimap의 첫 번째 요소를 주소 지정하는 반복기를 반환합니다.

const_iterator begin() const;

iterator begin();

Return Value

multimap요소 다음에 나오는 위치 또는 첫 번째 요소의 multimap 주소를 지정하는 양방향 반복기입니다.

예시

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

int main( )
{
   using namespace std;
   multimap <int, int> m1;

   multimap <int, int> :: iterator m1_Iter;
   multimap <int, int> :: const_iterator m1_cIter;
   typedef pair <int, int> Int_Pair;

   m1.insert ( Int_Pair ( 0, 0 ) );
   m1.insert ( Int_Pair ( 1, 1 ) );
   m1.insert ( Int_Pair ( 2, 4 ) );

   m1_cIter = m1.begin ( );
   cout << "The first element of m1 is " << m1_cIter -> first << endl;

   m1_Iter = m1.begin ( );
   m1.erase ( m1_Iter );

   // The following 2 lines would err as the iterator is const
   // m1_cIter = m1.begin ( );
   // m1.erase ( m1_cIter );

   m1_cIter = m1.begin( );
   cout << "First element of m1 is now " << m1_cIter -> first << endl;
}
The first element of m1 is 0
First element of m1 is now 1

multimap::cbegin

범위의 첫 번째 요소를 주소 지정하는 const 반복기를 반환합니다.

const_iterator cbegin() const;

Return Value

범위의 첫 번째 요소 또는 빈 범위의 끝 바로 다음 위치를 가리키는 const 양방향 액세스 반복기입니다(빈 범위의 경우 cbegin() == cend()).

설명

반환 값을 cbegin사용하면 범위의 요소를 수정할 수 없습니다.

begin() 멤버 함수 대신 이 멤버 함수를 사용하여 반환 값이 const_iterator임을 보장할 수 있습니다. 일반적으로 다음 예제와 같이 형식 추론 키워드(keyword) 함께 auto 사용됩니다. 이 예제에서는 Containerbegin()cbegin()를 지원하는 수정 가능(비const)한 컨테이너로 가정합니다.

auto i1 = Container.begin();
// i1 is Container<T>::iterator
auto i2 = Container.cbegin();

// i2 is Container<T>::const_iterator

multimap::cend

범위에서 마지막 요소 바로 다음의 위치를 주소 지정하는 const 반복기를 반환합니다.

const_iterator cend() const;

Return Value

범위 끝의 바로 다음을 가리키는 const 양방향 액세스 반복기입니다.

설명

cend는 반복기가 범위 끝을 통과했는지 여부를 테스트하는 데 사용됩니다.

end() 멤버 함수 대신 이 멤버 함수를 사용하여 반환 값이 const_iterator임을 보장할 수 있습니다. 일반적으로 다음 예제와 같이 형식 추론 키워드(keyword) 함께 auto 사용됩니다. 이 예제에서는 Containerend()cend()를 지원하는 수정 가능(비const)한 컨테이너로 가정합니다.

auto i1 = Container.end();
// i1 is Container<T>::iterator
auto i2 = Container.cend();

// i2 is Container<T>::const_iterator

반환된 cend 값은 역참조하면 안 됩니다.

multimap::clear

multimap의 모든 요소를 지웁니다.

void clear();

예시

다음 예제에서는 멤버 함수를 사용하는 방법을 multimap::clear 보여 줍니다.

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

int main( )
{
   using namespace std;
   multimap<int, int> m1;
   multimap<int, int>::size_type i;
   typedef pair<int, int> Int_Pair;

   m1.insert(Int_Pair(1, 1));
   m1.insert(Int_Pair(2, 4));

   i = m1.size();
   cout << "The size of the multimap is initially "
        << i << "." << endl;

   m1.clear();
   i = m1.size();
   cout << "The size of the multimap after clearing is "
        << i << "." << endl;
}
The size of the multimap is initially 2.
The size of the multimap after clearing is 0.

multimap::const_iterator

const에 있는 multimap 요소를 읽을 수 있는 양방향 반복기를 제공하는 형식입니다.

typedef implementation-defined const_iterator;

설명

형식 const_iterator 을 사용하여 요소의 값을 수정할 수 없습니다.

const_iterator 형식pair<const Key, Type>인 개체를 value_type가리키는 점으로 정의된 multimap 값입니다. 키의 값은 첫 번째 멤버 쌍을 통해 제공되며 매핑된 요소의 값은 쌍의 두 번째 멤버를 통해 제공됩니다.

요소에 대한 const_iteratorcIter 포인팅을 multimap역참조하려면 연산자를 -> 사용합니다.

요소에 대한 키 값에 액세스하려면 해당(*cIter).first되는 키를 사용합니다cIter->first. 요소에 대해 매핑된 데이텀의 값에 액세스하려면 해당(*cIter).second되는 를 사용합니다cIter->second.

예시

를 사용하는 예제는 예제 begin 를 참조하세요 const_iterator.

multimap::const_pointer

const에 있는 multimap 요소에 대한 포인터를 제공하는 형식입니다.

typedef typename allocator_type::const_pointer const_pointer;

설명

형식 const_pointer 을 사용하여 요소의 값을 수정할 수 없습니다.

대부분의 경우 개체의 iterator 요소 multimap 에 액세스하는 데 사용해야 합니다.

multimap::const_reference

const 작업을 읽고 수행하기 위해 multimap에 저장된 const 요소에 대한 참조를 제공하는 형식입니다.

typedef typename allocator_type::const_reference const_reference;

예시

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

int main( )
{
   using namespace std;
   multimap <int, int> m1;
   typedef pair <int, int> Int_Pair;

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

   // Declare and initialize a const_reference &Ref1
   // to the key of the first element
   const int &Ref1 = ( m1.begin( ) -> first );

   // The following line would cause an error because the
   // non-const_reference can't be used to access the key
   // int &Ref1 = ( m1.begin( ) -> first );

   cout << "The key of the first element in the multimap is "
        << Ref1 << "." << endl;

   // Declare and initialize a reference &Ref2
   // to the data value of the first element
   int &Ref2 = ( m1.begin( ) -> second );

   cout << "The data value of the first element in the multimap is "
        << Ref2 << "." << endl;
}
The key of the first element in the multimap is 1.
The data value of the first element in the multimap is 10.

multimap::const_reverse_iterator

const에 있는 multimap 요소를 읽을 수 있는 양방향 반복기를 제공하는 형식입니다.

typedef std::reverse_iterator<const_iterator> const_reverse_iterator;

설명

형식 const_reverse_iterator 은 요소의 값을 수정할 수 없으며 역방향으로 반복 multimap 하는 데 사용됩니다.

const_reverse_iterator 형식pair<const Key, Type>인 개체를 value_type가리키는 점으로 정의된 multimap 값입니다. 키의 값은 첫 번째 멤버 쌍을 통해 제공되며 매핑된 요소의 값은 쌍의 두 번째 멤버를 통해 제공됩니다.

multimap의 요소를 가리키는 const_reverse_iteratorcrIter를 역참조하려면 -> 연산자를 사용합니다.

요소에 대한 키 값에 액세스하려면 해당(*crIter).first되는 키를 사용합니다crIter->first. 요소에 대해 매핑된 데이텀의 값에 액세스하려면 해당(*crIter).first되는 를 사용합니다crIter->second.

예시

선언하고 사용하는 const_reverse_iterator방법에 대한 rend 예제는 예제를 참조하세요.

multimap::contains

에 지정된 키를 multimap가진 요소가 있는지 확인합니다.

bool contains(const Key& key) const;
template<class K> bool contains(const K& key) const;

매개 변수

K
키의 형식입니다.

key
찾을 요소의 키 값입니다.

Return Value

true 컨테이너에 요소가 있으면 이고, false 그렇지 않으면.

설명

contains() 는 C++20의 새로운 기능입니다. 이 옵션을 사용하려면 이상 컴파일러 옵션을 지정 /std:c++20 합니다.

template<class K> bool contains(const K& key) const 투명할 경우 key_compare 오버로드 확인에만 참여합니다. 자세한 내용은 결합 컨테이너의 이기종 조회를 참조 하세요 .

예시

// Requires /std:c++20 or /std:c++latest
#include <map>
#include <string>
#include <iostream>
#include <functional>

int main()
{
    std::multimap<int, bool> m = {{0, false}, {1, true}};

    std::cout << std::boolalpha; // so booleans show as 'true' or 'false'
    std::cout << m.contains(1) << '\n';
    std::cout << m.contains(2) << '\n';

    // call template function
    std::multimap<std::string, int, std::less<>> m2 = {{"ten", 10}, {"twenty", 20}, {"thirty", 30}};
    std::cout << m2.contains("ten");

    return 0;
}
true
false
true

multimap::count

키가 매개 변수 지정 키와 multimap 일치하는 요소의 수를 반환합니다.

size_type count(const Key& key) const;

매개 변수

key
multimap에서 일치하는지 확인할 요소의 키입니다.

Return Value

정렬 키가 매개 변수 키와 일치하는 요소가 있는 경우 해당 요소 수이고, multimap에 일치하는 키가 포함된 요소가 없는 경우 0입니다.

설명

멤버 함수는 다음 범위에 있는 요소 중에서

lower_bound(key), upper_bound(key)

키 값 key를 가진 요소의 수를 반환합니다.

예시

다음 예제에서는 multimap::count 멤버 함수의 사용을 보여 줍니다.

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

int main( )
{
    using namespace std;
    multimap<int, int> m1;
    multimap<int, int>::size_type i;
    typedef pair<int, int> Int_Pair;

    m1.insert(Int_Pair(1, 1));
    m1.insert(Int_Pair(2, 1));
    m1.insert(Int_Pair(1, 4));
    m1.insert(Int_Pair(2, 1));

    // Elements don't need to have unique keys in multimap,
    // so duplicates are allowed and counted
    i = m1.count(1);
    cout << "The number of elements in m1 with a sort key of 1 is: "
         << i << "." << endl;

    i = m1.count(2);
    cout << "The number of elements in m1 with a sort key of 2 is: "
         << i << "." << endl;

    i = m1.count(3);
    cout << "The number of elements in m1 with a sort key of 3 is: "
         << i << "." << endl;
}
The number of elements in m1 with a sort key of 1 is: 2.
The number of elements in m1 with a sort key of 2 is: 2.
The number of elements in m1 with a sort key of 3 is: 0.

multimap::crbegin

역방향 multimap요소 const 의 첫 번째 요소 주소를 지정하는 반복기를 반환합니다.

const_reverse_iterator crbegin() const;

Return Value

const 역방향에서 첫 번째 요소의 주소를 지정하거나 역multimap방향 multimap 요소의 마지막 요소 주소를 지정하는 역방향 양방향 반복기입니다.

설명

crbegin는 .와 함께 사용되는 것처럼 begin 역방향 multimap 으로 multimap사용됩니다.

반환 값 crbegin이 있는 경우 개체를 multimap 수정할 수 없습니다.

crbeginmultimap을 역방향으로 반복할 때 사용할 수 있습니다.

예시

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

int main( )
{
   using namespace std;
   multimap <int, int> m1;

   multimap <int, int> :: const_reverse_iterator m1_crIter;
   typedef pair <int, int> Int_Pair;

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

   m1_crIter = m1.crbegin( );
   cout << "The first element of the reversed multimap m1 is "
        << m1_crIter -> first << "." << endl;
}
The first element of the reversed multimap m1 is 3.

multimap::crend

역방향multimapconst 마지막 요소 다음에 나오는 위치를 해결하는 반복기를 반환합니다.

const_reverse_iterator crend() const;

Return Value

const 역방향 요소의 마지막 요소 다음에 오는 위치(역방향 요소의 첫 번째 요소 multimapmultimap앞에 있었던 위치)를 해결하는 역방향 양방향 반복기입니다.

설명

crend는 .와 함께 사용되는 것처럼 multimap::end 역방향 multimap 으로 multimap사용됩니다.

반환 값 crend이 있는 경우 개체를 multimap 수정할 수 없습니다.

crend를 사용하여 역방향 반복기가 multimap 끝에 도달했는지 여부를 테스트할 수 있습니다.

반환된 crend 값은 역참조하면 안 됩니다.

예시

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

int main( )
{
   using namespace std;
   multimap <int, int> m1;

   multimap <int, int> :: const_reverse_iterator m1_crIter;
   typedef pair <int, int> Int_Pair;

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

   m1_crIter = m1.crend( );
   m1_crIter--;
   cout << "The last element of the reversed multimap m1 is "
        << m1_crIter -> first << "." << endl;
}
The last element of the reversed multimap m1 is 1.

multimap::difference_type

부호 있는 정수 형식은 반복기가 가리키는 요소 사이의 범위에 있는 multimap의 요소의 개수를 표현하는 데 사용할 수 있습니다.

typedef typename allocator_type::difference_type difference_type;

설명

difference_type은 컨테이너의 반복기를 빼거나 더할 때 반환되는 형식입니다. 일반적으로 반복 difference_typefirst 사이의 [first, last) 범위의 요소 수를 나타내는 데 사용되며, 가리키는 first 요소와 last가리키는 요소의 범위(포함 안 last됨)를 포함합니다.

set과 같은 가역 컨테이너에서 지원하는 양방향 반복기의 클래스를 포함하는 입력 반복기의 요구 사항을 충족하는 모든 반복기에 사용할 수 있지만 difference_type 반복기 간의 빼기는 벡터와 같은 임의 액세스 컨테이너에서 제공하는 임의 액세스 반복기에서만 지원됩니다.

예시

// multimap_diff_type.cpp
// compile with: /EHsc
#include <iostream>
#include <map>
#include <algorithm>

int main( )
{
   using namespace std;
   multimap <int, int> m1;
   typedef pair <int, int> Int_Pair;

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

   // The following will insert as multimap keys are not unique
   m1.insert ( Int_Pair ( 2, 30 ) );

   multimap <int, int>::iterator m1_Iter, m1_bIter, m1_eIter;
   m1_bIter = m1.begin( );
   m1_eIter = m1.end( );

   // Count the number of elements in a multimap
   multimap <int, int>::difference_type  df_count = 0;
   m1_Iter = m1.begin( );
   while ( m1_Iter != m1_eIter )
   {
      df_count++;
      m1_Iter++;
   }

   cout << "The number of elements in the multimap m1 is: "
        << df_count << "." << endl;
}
The number of elements in the multimap m1 is: 4.

multimap::emplace

생성된 요소를 제 위치에 삽입합니다. 복사 또는 이동 작업은 수행되지 않습니다.

template <class... Args>
iterator emplace(Args&&... args);

매개 변수

args
에 삽입할 요소를 생성하기 위해 전달된 인수입니다 multimap.

Return Value

새로 삽입된 요소에 대한 반복기입니다.

설명

이 함수는 컨테이너 요소에 대한 참조는 무효화하지 않지만 컨테이너에 대한 모든 반복기는 무효화할 수 있습니다.

삽입하는 동안 예외가 throw되면 컨테이너는 변경되지 않고 예외가 다시 throw됩니다.

요소의 값이 value_type 키 값과 같고 두 번째 구성 요소가 요소의 데이터 값과 같은 순서가 지정된 쌍이 되도록 요소의 값은 쌍입니다.

예시

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

using namespace std;

template <typename M> void print(const M& m) {
    cout << m.size() << " elements: " << endl;

    for (const auto& p : m) {
        cout << "(" << p.first <<  "," << p.second << ") ";
    }

    cout << endl;
}

int main()
{
    multimap<string, string> m1;

    m1.emplace("Anna", "Accounting");
    m1.emplace("Bob", "Accounting");
    m1.emplace("Carmine", "Engineering");

    cout << "multimap modified, now contains ";
    print(m1);
    cout << endl;

    m1.emplace("Bob", "Engineering");

    cout << "multimap modified, now contains ";
    print(m1);
    cout << endl;
}

multimap::emplace_hint

배치 힌트를 사용하여 생성된 요소를 제 위치에 삽입합니다. 복사 또는 이동 작업은 수행되지 않습니다.

template <class... Args>
iterator emplace_hint(
    const_iterator where,
    Args&&... args);

매개 변수

args
에 삽입할 요소를 생성하기 위해 전달된 인수입니다 multimap.

where
올바른 삽입 지점 검색을 시작할 위치입니다. 이 지점이 where 바로 앞에 오면 로그 시간 대신 분할된 시간에 삽입할 수 있습니다.

Return Value

새로 삽입된 요소에 대한 반복기입니다.

설명

이 함수는 컨테이너 요소에 대한 참조는 무효화하지 않지만 컨테이너에 대한 모든 반복기는 무효화할 수 있습니다.

대입 중 예외가 throw되면 컨테이너의 상태가 수정되지 않습니다.

요소의 값이 value_type 키 값과 같고 두 번째 구성 요소가 요소의 데이터 값과 같은 순서가 지정된 쌍이 되도록 요소의 값은 쌍입니다.

코드 예제는 .를 참조하세요 map::emplace_hint.

multimap::empty

multimap가 비어 있는지 여부를 테스트합니다.

bool empty() const;

Return Value

true비어 multimap 있으면 이고, false 비어 있지 않으면 multimap

예시

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

int main( )
{
   using namespace std;
   multimap <int, int> m1, m2;

   typedef pair <int, int> Int_Pair;
   m1.insert ( Int_Pair ( 1, 1 ) );

   if ( m1.empty( ) )
      cout << "The multimap m1 is empty." << endl;
   else
      cout << "The multimap m1 is not empty." << endl;

   if ( m2.empty( ) )
      cout << "The multimap m2 is empty." << endl;
   else
      cout << "The multimap m2 is not empty." << endl;
}
The multimap m1 is not empty.
The multimap m2 is empty.

multimap::end

마지막 바로 다음 반복기를 반환합니다.

const_iterator end() const;

iterator end();

Return Value

마지막 바로 다음 반복기입니다. multimap이 비어 있으면 multimap::end() == multimap::begin()입니다.

설명

end 반복기가 해당 끝을 multimap통과했는지 여부를 테스트하는 데 사용됩니다.

반환된 end 값은 역참조하면 안 됩니다.

코드 예제는 .를 참조하세요 multimap::find.

multimap::equal_range

요소의 키가 지정된 값과 일치하는 요소 범위를 찾습니다.

pair <const_iterator, const_iterator> equal_range (const Key& key) const;

pair <iterator, iterator> equal_range (const Key& key);

매개 변수

key
검색할 요소 multimap 의 정렬 키와 비교할 인수 키입니다.

Return Value

첫 번째는 키이고 두 번째는 lower_bound 키의 반복기 쌍입니다 upper_bound .

멤버 함수에서 반환된 쌍 pr 의 첫 번째 반복기에 액세스하려면 하한 반복기를 *(pr.first)사용하고 pr.first 역참조합니다. 멤버 함수에서 반환된 쌍 pr 의 두 번째 반복기에 액세스하려면 상한 반복기를 *(pr.second)사용하고 pr.second 역참조합니다.

예시

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

int main( )
{
   using namespace std;
   typedef multimap <int, int, less<int> > IntMMap;
   IntMMap m1;
   multimap <int, int> :: const_iterator m1_RcIter;
   typedef pair <int, int> Int_Pair;

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

   pair <IntMMap::const_iterator, IntMMap::const_iterator> p1, p2;
   p1 = m1.equal_range( 2 );

   cout << "The lower bound of the element with "
        << "a key of 2 in the multimap m1 is: "
        << p1.first -> second << "." << endl;

   cout << "The upper bound of the element with "
        << "a key of 2 in the multimap m1 is: "
        << p1.second -> second << "." << endl;

   // Compare the upper_bound called directly
   m1_RcIter = m1.upper_bound( 2 );

   cout << "A direct call of upper_bound( 2 ) gives "
        << m1_RcIter -> second << "," << endl
        << "matching the 2nd element of the pair "
        << "returned by equal_range( 2 )." << endl;

   p2 = m1.equal_range( 4 );

   // If no match is found for the key,
   // both elements of the pair return end( )
   if ( ( p2.first == m1.end( ) ) && ( p2.second == m1.end( ) ) )
      cout << "The multimap m1 doesn't have an element "
           << "with a key less than 4." << endl;
   else
      cout << "The element of multimap m1 with a key >= 40 is: "
           << p1.first -> first << "." << endl;
}
The lower bound of the element with a key of 2 in the multimap m1 is: 20.
The upper bound of the element with a key of 2 in the multimap m1 is: 30.
A direct call of upper_bound( 2 ) gives 30,
matching the 2nd element of the pair returned by equal_range( 2 ).
The multimap m1 doesn't have an element with a key less than 4.

multimap::erase

지정된 위치에서 multimap의 요소 또는 요소의 범위를 제거하거나 지정된 키와 일치하는 요소를 제거합니다.

iterator erase(
    const_iterator Where);

iterator erase(
    const_iterator First,
    const_iterator Last);

size_type erase(
    const key_type& Key);

매개 변수

Where
제거할 요소의 위치입니다.

First
제거할 첫 번째 요소의 위치입니다.

Last
제거할 마지막 요소 바로 다음 위치입니다.

Key
제거할 요소의 키입니다.

Return Value

처음 두 멤버 함수의 경우 제거된 요소 뒤에 남은 첫 번째 요소 또는 이러한 요소가 없을 경우 map의 끝에 있는 요소를 지정하는 양방향 반복기입니다.

세 번째 멤버 함수의 multimap경우 .

설명

코드 예제는 .를 참조하세요 map::erase.

multimap::find

지정된 키에 해당하는 키가 있는 요소 multimap 의 첫 번째 위치를 참조하는 반복기를 반환합니다.

iterator find(const Key& key);

const_iterator find(const Key& key) const;

매개 변수

key
검색할 요소 multimap 의 정렬 키와 일치시킬 키 값입니다.

Return Value

지정된 키를 가진 요소의 위치를 참조하는 반복기이거나 키와 일치하는 항목이 없는 경우 (multimap::end())의 multimap 마지막 요소 다음에 나오는 위치입니다.

설명

멤버 함수는 정렬 키가 비교 가능성보다 작은 관계를 기반으로 정렬을 유도하는 이진 조건자의 인수 키와 동일한 요소를 multimap 참조하는 반복기를 반환합니다.

반환 값 find 이 할당 const_iterator된 경우 개체를 multimap 수정할 수 없습니다. 반환 값 find 이 할당된 경우 개체를 iteratormultimap 수정할 수 있습니다.

예시

// compile with: /EHsc /W4 /MTd
#include <map>
#include <iostream>
#include <vector>
#include <string>
#include <utility>  // make_pair()

using namespace std;

template <typename A, typename B> void print_elem(const pair<A, B>& p) {
    cout << "(" << p.first << ", " << p.second << ") ";
}

template <typename T> void print_collection(const T& t) {
    cout << t.size() << " elements: ";

    for (const auto& p : t) {
        print_elem(p);
    }
    cout << endl;
}

template <typename C, class T> void findit(const C& c, T val) {
    cout << "Trying find() on value " << val << endl;
    auto result = c.find(val);
    if (result != c.end()) {
        cout << "Element found: "; print_elem(*result); cout << endl;
    } else {
        cout << "Element not found." << endl;
    }
}

int main()
{
    multimap<int, string> m1({ { 40, "Zr" }, { 45, "Rh" } });
    cout << "The starting multimap m1 is (key, value):" << endl;
    print_collection(m1);

    vector<pair<int, string>> v;
    v.push_back(make_pair(43, "Tc"));
    v.push_back(make_pair(41, "Nb"));
    v.push_back(make_pair(46, "Pd"));
    v.push_back(make_pair(42, "Mo"));
    v.push_back(make_pair(44, "Ru"));
    v.push_back(make_pair(44, "Ru")); // attempt a duplicate

    cout << "Inserting the following vector data into m1:" << endl;
    print_collection(v);

    m1.insert(v.begin(), v.end());

    cout << "The modified multimap m1 is (key, value):" << endl;
    print_collection(m1);
    cout << endl;
    findit(m1, 45);
    findit(m1, 6);
}

multimap::get_allocator

를 생성하는 데 사용되는 할당자 개체의 복사본을 반환합니다 multimap.

allocator_type get_allocator() const;

Return Value

에서 사용하는 할당자입니다 multimap.

설명

클래스의 할당자는 클래스가 multimap 스토리지를 관리하는 방법을 지정합니다. C++ 표준 라이브러리 컨테이너 클래스와 함께 제공되는 기본 할당자를 사용하면 대부분의 프로그래밍 요구 사항을 충족할 수 있습니다. 할당자 클래스를 직접 작성하고 사용하는 방법에 대해서는 고급 C++ 항목에서 다룹니다.

예시

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

int main( )
{
   using namespace std;
   multimap <int, int>::allocator_type m1_Alloc;
   multimap <int, int>::allocator_type m2_Alloc;
   multimap <int, double>::allocator_type m3_Alloc;
   multimap <int, int>::allocator_type m4_Alloc;

   // The following lines declare objects
   // that use the default allocator.
   multimap <int, int> m1;
   multimap <int, int, allocator<int> > m2;
   multimap <int, double, allocator<double> > m3;

   m1_Alloc = m1.get_allocator( );
   m2_Alloc = m2.get_allocator( );
   m3_Alloc = m3.get_allocator( );

   cout << "The number of integers that can be allocated"
        << endl << "before free memory is exhausted: "
        << m2.max_size( ) << ".\n" << endl;

   cout << "The number of doubles that can be allocated"
        << endl << "before free memory is exhausted: "
        << m3.max_size( ) <<  ".\n" << endl;

   // The following line creates a multimap m4
   // with the allocator of multimap m1.
   map <int, int> m4( less<int>( ), m1_Alloc );

   m4_Alloc = m4.get_allocator( );

   // Two allocators are interchangeable if
   // storage allocated from each can be
   // deallocated via the other
   if( m1_Alloc == m4_Alloc )
   {
      cout << "The allocators are interchangeable."
           << endl;
   }
   else
   {
      cout << "The allocators are not interchangeable."
           << endl;
   }
}

multimap::insert

multimap에 요소 또는 요소의 범위를 삽입합니다.

// (1) single element
pair<iterator, bool> insert(
    const value_type& Val);

// (2) single element, perfect forwarded
template <class ValTy>
pair<iterator, bool>
insert(
    ValTy&& Val);

// (3) single element with hint
iterator insert(
    const_iterator Where,
    const value_type& Val);

// (4) single element, perfect forwarded, with hint
template <class ValTy>
iterator insert(
    const_iterator Where,
    ValTy&& Val);

// (5) range
template <class InputIterator>
void insert(
    InputIterator First,
    InputIterator Last);

// (6) initializer list
void insert(
    initializer_list<value_type>
IList);

매개 변수

Val
에 삽입할 요소의 값입니다 multimap.

Where
올바른 삽입 지점 검색을 시작할 위치입니다. 이 지점이 Where 바로 앞에 오면 로그 시간 대신 분할된 시간에 삽입할 수 있습니다.

ValTy
맵에서 요소를 value_type생성하는 데 사용할 수 있는 인수 형식을 지정하고 인수로 완벽하게 전달되는 Val 템플릿 매개 변수입니다.

First
복사할 첫 번째 요소의 위치입니다.

Last
복사할 마지막 요소 바로 다음 위치입니다.

InputIterator
개체를 생성하는 value_type 데 사용할 수 있는 형식의 input 요소를 가리키는 반복기의 요구 사항을 충족하는 템플릿 함수 인수입니다.

IList
initializer_list 요소를 복사할 원본입니다.

Return Value

단일 요소 삽입 멤버 함수((1) 및 (2)는 새 요소가 삽입된 위치로 multimap반복기를 반환합니다.

단일 요소-힌트 멤버 함수((3) 및 (4)는 새 요소가 삽입된 multimap위치를 가리키는 반복기를 반환합니다.

설명

이 함수는 어떠한 포인터 또는 참조를 무효화하지 않지만 컨테이너에 대한 모든 반복기를 무효화할 수 있습니다.

요소를 한 개만 삽입하는 중 예외가 throw되면 컨테이너의 상태가 수정되지 않습니다. 여러 요소를 삽입하는 중 예외가 throw되면 컨테이너는 지정되지 않았으나 유효한 상태로 남아 있습니다.

value_type 컨테이너의 형식 정의는 컨테이너에 속하는 typedef이며 맵 multimap<K, V>::value_type 의 경우 다음과 같습니다pair<const K, V>. 요소의 값은 첫 번째 구성 요소가 키 값과 동일하고 두 번째 구성 요소는 요소의 데이터 값과 동일한 정렬된 쌍입니다.

범위 멤버 함수(5)는 범위의 반복기[First, Last)에서 multimap 주소가 지정된 각 요소에 해당하는 요소 값의 시퀀스를 삽입하므로 Last 삽입되지 않습니다. 컨테이너 멤버 함수 end()는 컨테이너의 마지막 요소 바로 뒤에 있는 위치를 참조합니다. 예를 들어 m.insert(v.begin(), v.end()); 문은 v의 모든 요소를 m에 삽입합니다.

이니셜라이저 목록 멤버 함수(6)는 요소를 맵에 복사하는 데 사용합니다 initializer_list .

생성된 요소를 삽입하는 경우(즉, 복사 또는 이동 작업이 수행되지 않음) 참조 multimap::emplace 하세요 multimap::emplace_hint.

예시

// multimap_insert.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
#include <string>
#include <vector>
#include <utility>  // make_pair()

using namespace std;

template <typename M> void print(const M& m) {
    cout << m.size() << " elements: ";

    for (const auto& p : m) {
        cout << "(" << p.first << ", " << p.second << ") ";
    }

    cout << endl;
}

int main()
{
    // insert single values
    multimap<int, int> m1;
    // call insert(const value_type&) version
    m1.insert({ 1, 10 });
    // call insert(ValTy&&) version
    m1.insert(make_pair(2, 20));

    cout << "The original key and mapped values of m1 are:" << endl;
    print(m1);

    // intentionally attempt a duplicate, single element
    m1.insert(make_pair(1, 111));

    cout << "The modified key and mapped values of m1 are:" << endl;
    print(m1);

    // single element, with hint
    m1.insert(m1.end(), make_pair(3, 30));
    cout << "The modified key and mapped values of m1 are:" << endl;
    print(m1);
    cout << endl;

    // The templatized version inserting a jumbled range
    multimap<int, int> m2;
    vector<pair<int, int>> v;
    v.push_back(make_pair(43, 294));
    v.push_back(make_pair(41, 262));
    v.push_back(make_pair(45, 330));
    v.push_back(make_pair(42, 277));
    v.push_back(make_pair(44, 311));

    cout << "Inserting the following vector data into m2:" << endl;
    print(v);

    m2.insert(v.begin(), v.end());

    cout << "The modified key and mapped values of m2 are:" << endl;
    print(m2);
    cout << endl;

    // The templatized versions move-constructing elements
    multimap<int, string>  m3;
    pair<int, string> ip1(475, "blue"), ip2(510, "green");

    // single element
    m3.insert(move(ip1));
    cout << "After the first move insertion, m3 contains:" << endl;
    print(m3);

    // single element with hint
    m3.insert(m3.end(), move(ip2));
    cout << "After the second move insertion, m3 contains:" << endl;
    print(m3);
    cout << endl;

    multimap<int, int> m4;
    // Insert the elements from an initializer_list
    m4.insert({ { 4, 44 }, { 2, 22 }, { 3, 33 }, { 1, 11 }, { 5, 55 } });
    cout << "After initializer_list insertion, m4 contains:" << endl;
    print(m4);
    cout << endl;
}

multimap::iterator

multimap에 있는 모든 요소를 읽거나 수정할 수 있는 양방향 반복기를 제공하는 형식입니다.

typedef implementation-defined iterator;

설명

iterator 형식pair<const Key, Type>인 개체를 value_type가리키는 점으로 정의된 multimap 값입니다. 키의 값은 첫 번째 멤버 쌍을 통해 제공되며 매핑된 요소의 값은 쌍의 두 번째 멤버를 통해 제공됩니다.

요소에 대한 iteratorIter 포인팅 multimap을 역참조하려면 연산자를 -> 사용합니다.

요소에 대한 키 값에 액세스하려면 해당(*Iter).first되는 키를 사용합니다Iter->first. 요소에 대해 매핑된 데이텀의 값에 액세스하려면 해당(*Iter).second되는 를 사용합니다Iter->second.

형식 iterator 을 사용하여 요소의 값을 수정할 수 있습니다.

예시

선언하고 사용하는 iterator방법에 대한 begin 예제는 예제를 참조하세요.

multimap::key_comp

multimap에서 키를 정렬하기 위해 사용하는 비교 개체의 복사본을 검색합니다.

key_compare key_comp() const;

Return Value

요소의 순서를 multimap 지정하는 데 사용하는 함수 개체를 반환합니다.

설명

저장된 개체는 멤버 함수

bool operator( const Key& x, const Key& y);

은 정렬 순서에서 엄격하게 앞에 오 yx true를 반환합니다.

예시

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

int main( )
{
   using namespace std;

   multimap <int, int, less<int> > m1;
   multimap <int, int, less<int> >::key_compare kc1 = m1.key_comp( ) ;
   bool result1 = kc1( 2, 3 ) ;
   if( result1 == true )
   {
      cout << "kc1( 2,3 ) returns value of true, "
           << "where kc1 is the function object of m1."
           << endl;
   }
   else
   {
      cout << "kc1( 2,3 ) returns value of false "
           << "where kc1 is the function object of m1."
           << endl;
   }

   multimap <int, int, greater<int> > m2;
   multimap <int, int, greater<int> >::key_compare kc2 = m2.key_comp( );
   bool result2 = kc2( 2, 3 ) ;
   if( result2 == true )
   {
      cout << "kc2( 2,3 ) returns value of true, "
           << "where kc2 is the function object of m2."
           << endl;
   }
   else
   {
      cout << "kc2( 2,3 ) returns value of false, "
           << "where kc2 is the function object of m2."
           << endl;
   }
}
kc1( 2,3 ) returns value of true, where kc1 is the function object of m1.
kc2( 2,3 ) returns value of false, where kc2 is the function object of m2.

multimap::key_compare

multimap의 두 요소간 상대적 순서를 결정하는 두 정렬 키를 비교할 수 있는 함수 개체를 제공하는 형식입니다.

typedef Traits key_compare;

설명

key_compare은 템플릿 매개 변수 Traits의 동의어입니다.

자세한 Traits내용은 클래스 항목을 참조 multimap 하세요 .

예시

선언하고 사용하는 key_compare방법에 대한 key_comp 예제는 예제를 참조하세요.

multimap::key_type

multimap의 각 요소를 구성하는 정렬 키 개체를 설명하는 형식입니다.

typedef Key key_type;

설명

key_type은 템플릿 매개 변수 Key의 동의어입니다.

자세한 Key내용은 수업 항목의 설명 섹션을 multimap 참조하세요 .

예시

선언하고 사용하는 key_type방법에 대한 value_type 예제는 예제를 참조하세요.

multimap::lower_bound

multimap에서 지정된 키보다 같거나 큰 키를 가진 첫 번째 요소에 반복기를 반환합니다.

iterator lower_bound(const Key& key);

const_iterator lower_bound(const Key& key) const;

매개 변수

key
검색할 요소 multimap 의 정렬 키와 비교할 인수 키입니다.

Return Value

인수 키와 같거나 const_iterator 큰 키를 사용하여 요소 multimap 의 위치를 주소 지정하거나 키에 대한 일치 항목이 없는 경우 마지막 요소 multimap 다음에 나오는 위치를 처리하는 반복기입니다.

반환 값 lower_bound 이 할당 const_iterator된 경우 개체를 multimap 수정할 수 없습니다. 반환 값 lower_bound 이 반복기에 할당된 경우 개체를 multimap 수정할 수 있습니다.

예시

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

int main( )
{
   using namespace std;
   multimap <int, int> m1;
   multimap <int, int> :: const_iterator m1_AcIter, m1_RcIter;
   typedef pair <int, int> Int_Pair;

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

   m1_RcIter = m1.lower_bound( 2 );
   cout << "The element of multimap m1 with a key of 2 is: "
        << m1_RcIter -> second << "." << endl;

   m1_RcIter = m1.lower_bound( 3 );
   cout << "The first element of multimap m1 with a key of 3 is: "
        << m1_RcIter -> second << "." << endl;

   // If no match is found for the key, end( ) is returned
   m1_RcIter = m1.lower_bound( 4 );

   if ( m1_RcIter == m1.end( ) )
      cout << "The multimap m1 doesn't have an element "
              << "with a key of 4." << endl;
   else
      cout << "The element of multimap m1 with a key of 4 is: "
                << m1_RcIter -> second << "." << endl;

   // The element at a specific location in the multimap can be
   // found using a dereferenced iterator addressing the location
   m1_AcIter = m1.end( );
   m1_AcIter--;
   m1_RcIter = m1.lower_bound( m1_AcIter -> first );
   cout << "The first element of m1 with a key matching\n"
        << "that of the last element is: "
        << m1_RcIter -> second << "." << endl;

   // Note that the first element with a key equal to
   // the key of the last element is not the last element
   if ( m1_RcIter == --m1.end( ) )
      cout << "This is the last element of multimap m1."
           << endl;
   else
      cout << "This is not the last element of multimap m1."
           << endl;
}
The element of multimap m1 with a key of 2 is: 20.
The first element of multimap m1 with a key of 3 is: 20.
The multimap m1 doesn't have an element with a key of 4.
The first element of m1 with a key matching
that of the last element is: 20.
This is not the last element of multimap m1.

multimap::mapped_type

multimap 내에 저장된 데이터 형식을 나타내는 형식입니다.

typedef Type mapped_type;

설명

mapped_type은 템플릿 매개 변수 Type의 동의어입니다.

자세한 Type내용은 클래스 항목을 참조 multimap 하세요 .

예시

선언하고 사용하는 key_type방법에 대한 value_type 예제는 예제를 참조하세요.

multimap::max_size

multimap의 최대 길이를 반환합니다.

size_type max_size() const;

Return Value

가능한 최대 길이입니다 multimap.

예시

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

int main( )
{
   using namespace std;
   multimap <int, int> m1;
   multimap <int, int> :: size_type i;

   i = m1.max_size( );
   cout << "The maximum possible length "
        << "of the multimap is " << i << "." << endl;
}

multimap::multimap

비어 있거나 다른 multimap의 전체 또는 일부의 복사본인 multimap을 생성합니다.

multimap();

explicit multimap(
    const Traits& Comp);

multimap(
    const Traits& Comp,
    const Allocator& Al);

map(
    const multimap& Right);

multimap(
    multimap&& Right);

multimap(
    initializer_list<value_type> IList);

multimap(
    initializer_list<value_type> IList,
    const Compare& Comp);

multimap(
    initializer_list<value_type> IList,
    const Compare& Comp,
    const Allocator& Al);

template <class InputIterator>
multimap(
    InputIterator First,
    InputIterator Last);

template <class InputIterator>
multimap(
    InputIterator First,
    InputIterator Last,
    const Traits& Comp);

template <class InputIterator>
multimap(
    InputIterator First,
    InputIterator Last,
    const Traits& Comp,
    const Allocator& Al);

매개 변수

Al
이 multimap 개체에 사용할 스토리지 할당자 클래스로, 기본값은 Allocator입니다.

Comp
map의 요소 순서를 지정하는 데 사용되는 constTraits 형식의 비교 함수로, 기본값은 Traits입니다.

Right
생성된 set을 복사할 map입니다.

First
복사할 요소의 범위에서 첫 번째 요소의 위치입니다.

Last
복사할 요소의 범위를 벗어나는 첫 번째 요소의 위치입니다.

IList
요소를 복사할 원본 initializer_list입니다.

설명

모든 생성자는 메모리 스토리지 multimap 를 관리하고 나중에 호출 get_allocator하여 반환할 수 있는 할당자 개체의 형식을 저장합니다. allocator 매개 변수는 대체 할당자를 대체하는 데 사용되는 전처리 매크로 및 클래스 선언에서 생략되는 경우가 많습니다.

모든 생성자는 해당 생성자를 초기화합니다 multimap.

모든 생성자는 키 간에 순서를 설정하는 데 사용되며 나중에 호출key_comp하여 반환할 수 있는 형식 Traitsmultimap 함수 개체를 저장합니다.

처음 세 생성자는 빈 이니셜 multimap을 지정하고, 두 번째 생성자는 요소의 순서를 설정하는 데 사용할 비교 함수(Comp) 형식을 지정하고, 세 번째 생성자는 사용할 할당자 형식(Al)을 명시적으로 지정합니다. explicit 키워드를 사용하는 경우 특정 종류의 자동 형식 변환이 수행되지 않습니다.

네 번째 생성자는 .의 복사본을 multimapRight지정합니다.

다섯 번째 생성자는 오른쪽으로 이동하여 복사본을 multimap 지정합니다.

6번째, 7번째 및 8번째 생성자는 의 멤버를 복사합니다 initializer_list.

다음 세 생성자는 map의 범위 [First, Last)를 복사하여, Traits 클래스 및 할당자의 비교 함수 형식을 지정할 때 명시도가 향상됩니다.

예시

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

int main()
{
    using namespace std;
    typedef pair <int, int> Int_Pair;

    // Create an empty multimap m0 of key type integer
    multimap <int, int> m0;

    // Create an empty multimap m1 with the key comparison
    // function of less than, then insert 4 elements
    multimap <int, int, less<int> > m1;
    m1.insert(Int_Pair(1, 10));
    m1.insert(Int_Pair(2, 20));
    m1.insert(Int_Pair(3, 30));
    m1.insert(Int_Pair(4, 40));

    // Create an empty multimap m2 with the key comparison
    // function of greater than, then insert 2 elements
    multimap <int, int, less<int> > m2;
    m2.insert(Int_Pair(1, 10));
    m2.insert(Int_Pair(2, 20));

    // Create a multimap m3 with the
    // allocator of multimap m1
    multimap <int, int>::allocator_type m1_Alloc;
    m1_Alloc = m1.get_allocator();
    multimap <int, int> m3(less<int>(), m1_Alloc);
    m3.insert(Int_Pair(3, 30));

    // Create a copy, multimap m4, of multimap m1
    multimap <int, int> m4(m1);

    // Create a multimap m5 by copying the range m1[ first,  last)
    multimap <int, int>::const_iterator m1_bcIter, m1_ecIter;
    m1_bcIter = m1.begin();
    m1_ecIter = m1.begin();
    m1_ecIter++;
    m1_ecIter++;
    multimap <int, int> m5(m1_bcIter, m1_ecIter);

    // Create a multimap m6 by copying the range m4[ first,  last)
    // and with the allocator of multimap m2
    multimap <int, int>::allocator_type m2_Alloc;
    m2_Alloc = m2.get_allocator();
    multimap <int, int> m6(m4.begin(), ++m4.begin(), less<int>(), m2_Alloc);

    cout << "m1 =";
    for (auto i : m1)
        cout << i.first << " " << i.second << ", ";
    cout << endl;

    cout << "m2 =";
    for (auto i : m2)
        cout << i.first << " " << i.second << ", ";
    cout << endl;

    cout << "m3 =";
    for (auto i : m3)
        cout << i.first << " " << i.second << ", ";
    cout << endl;

    cout << "m4 =";
    for (auto i : m4)
        cout << i.first << " " << i.second << ", ";
    cout << endl;

    cout << "m5 =";
    for (auto i : m5)
        cout << i.first << " " << i.second << ", ";
    cout << endl;

    cout << "m6 =";
    for (auto i : m6)
        cout << i.first << " " << i.second << ", ";
    cout << endl;

    // Create a multimap m8 by copying in an initializer_list
    multimap<int, int> m8{ { { 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 4 } } };
    cout << "m8: = ";
    for (auto i : m8)
        cout << i.first << " " << i.second << ", ";
    cout << endl;

    // Create a multimap m9 with an initializer_list and a comparator
    multimap<int, int> m9({ { 5, 5 }, { 6, 6 }, { 7, 7 }, { 8, 8 } }, less<int>());
    cout << "m9: = ";
    for (auto i : m9)
        cout << i.first << " " << i.second << ", ";
    cout << endl;

    // Create a multimap m10 with an initializer_list, a comparator, and an allocator
    multimap<int, int> m10({ { 9, 9 }, { 10, 10 }, { 11, 11 }, { 12, 12 } }, less<int>(), m9.get_allocator());
    cout << "m10: = ";
    for (auto i : m10)
        cout << i.first << " " << i.second << ", ";
    cout << endl;

}

multimap::operator=

multimap의 요소를 다른 multimap의 복사본으로 대체합니다.

multimap& operator=(const multimap& right);

multimap& operator=(multimap&& right);

매개 변수

right
multimap 복사되는 항목입니다 multimap.

설명

multimapoperator=에서 기존 요소를 지운 후에 right의 내용을 multimap로 복사하거나 이동합니다.

예시

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

int main( )
   {
   using namespace std;
   multimap<int, int> v1, v2, v3;
   multimap<int, int>::iterator iter;

   v1.insert(pair<int, int>(1, 10));

   cout << "v1 = " ;
   for (iter = v1.begin(); iter != v1.end(); iter++)
      cout << iter->second << " ";
   cout << endl;

   v2 = v1;
   cout << "v2 = ";
   for (iter = v2.begin(); iter != v2.end(); iter++)
      cout << iter->second << " ";
   cout << endl;

// move v1 into v2
   v2.clear();
   v2 = move(v1);
   cout << "v2 = ";
   for (iter = v2.begin(); iter != v2.end(); iter++)
      cout << iter->second << " ";
   cout << endl;
   }

multimap::pointer

multimap의 요소에 대한 포인터를 제공하는 형식입니다.

typedef typename allocator_type::pointer pointer;

설명

형식 pointer 을 사용하여 요소의 값을 수정할 수 있습니다.

대부분의 경우 개체의 iterator 요소 multimap 에 액세스하는 데 사용해야 합니다.

multimap::rbegin

역순 multimap에서 첫 번째 요소를 참조하는 반복기를 반환합니다.

const_reverse_iterator rbegin() const;

reverse_iterator rbegin();

Return Value

역방향에서 첫 번째 요소의 주소를 지정하거나 역multimap방향 multimap 요소의 마지막 요소 주소를 지정하는 역방향 양방향 반복기입니다.

설명

rbegin는 .와 함께 사용되는 것처럼 begin 역방향 multimap 으로 multimap사용됩니다.

반환 값 rbegin 이 a const_reverse_iterator에 할당된 경우 개체를 multimap 수정할 수 없습니다. 반환 값 rbegin 이 a reverse_iterator에 할당된 경우 개체를 multimap 수정할 수 있습니다.

rbeginmultimap을 역방향으로 반복할 때 사용할 수 있습니다.

예시

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

int main( )
{
   using namespace std;
   multimap <int, int> m1;

   multimap <int, int> :: iterator m1_Iter;
   multimap <int, int> :: reverse_iterator m1_rIter;
   multimap <int, int> :: const_reverse_iterator m1_crIter;
   typedef pair <int, int> Int_Pair;

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

   m1_rIter = m1.rbegin( );
   cout << "The first element of the reversed multimap m1 is "
        << m1_rIter -> first << "." << endl;

   // begin can be used to start an iteration
   // through a multimap in a forward order
   cout << "The multimap is: ";
   for ( m1_Iter = m1.begin( ) ; m1_Iter != m1.end( ); m1_Iter++)
      cout << m1_Iter -> first << " ";
      cout << "." << endl;

   // rbegin can be used to start an iteration
   // through a multimap in a reverse order
   cout << "The reversed multimap is: ";
   for ( m1_rIter = m1.rbegin( ) ; m1_rIter != m1.rend( ); m1_rIter++)
      cout << m1_rIter -> first << " ";
      cout << "." << endl;

   // A multimap element can be erased by dereferencing its key
   m1_rIter = m1.rbegin( );
   m1.erase ( m1_rIter -> first );

   m1_rIter = m1.rbegin( );
   cout << "After the erasure, the first element "
        << "in the reversed multimap is "
        << m1_rIter -> first << "." << endl;
}
The first element of the reversed multimap m1 is 3.
The multimap is: 1 2 3 .
The reversed multimap is: 3 2 1 .
After the erasure, the first element in the reversed multimap is 2.

multimap::reference

multimap 내에 저장된 요소에 대한 참조를 제공하는 형식입니다.

typedef typename allocator_type::reference reference;

예시

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

int main( )
{
   using namespace std;
   multimap <int, int> m1;
   typedef pair <int, int> Int_Pair;

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

   // Declare and initialize a const_reference &Ref1
   // to the key of the first element
   const int &Ref1 = ( m1.begin( ) -> first );

   // The following line would cause an error because the
   // non-const_reference can't be used to access the key
   // int &Ref1 = ( m1.begin( ) -> first );

   cout << "The key of first element in the multimap is "
        << Ref1 << "." << endl;

   // Declare and initialize a reference &Ref2
   // to the data value of the first element
   int &Ref2 = ( m1.begin( ) -> second );

   cout << "The data value of first element in the multimap is "
        << Ref2 << "." << endl;

   // The non-const_reference can be used to modify the
   // data value of the first element
   Ref2 = Ref2 + 5;
   cout << "The modified data value of first element is "
        << Ref2 << "." << endl;
}
The key of first element in the multimap is 1.
The data value of first element in the multimap is 10.
The modified data value of first element is 15.

multimap::rend

역순 multimap에서 마지막 요소 다음에 나오는 위치를 주소 지정하는 반복기를 반환합니다.

const_reverse_iterator rend() const;

reverse_iterator rend();

Return Value

역방향 요소의 마지막 요소 다음에 오는 위치(역방향 요소의 첫 번째 요소 multimapmultimap앞에 있었던 위치)를 해결하는 역방향 양방향 반복기입니다.

설명

rend는 .와 함께 사용되는 것처럼 end 역방향 multimap 으로 multimap사용됩니다.

반환 값 rend 이 a const_reverse_iterator에 할당된 경우 개체를 multimap 수정할 수 없습니다. 반환 값 rend 이 a reverse_iterator에 할당된 경우 개체를 multimap 수정할 수 있습니다.

rend 를 사용하여 역방향 반복기가 해당 반복기의 끝에 도달했는지 여부를 테스트할 수 있습니다 multimap.

반환된 rend 값은 역참조하면 안 됩니다.

예시

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

int main( )
{
   using namespace std;
   multimap <int, int> m1;

   multimap <int, int> :: iterator m1_Iter;
   multimap <int, int> :: reverse_iterator m1_rIter;
   multimap <int, int> :: const_reverse_iterator m1_crIter;
   typedef pair <int, int> Int_Pair;

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

   m1_rIter = m1.rend( );
   m1_rIter--;
   cout << "The last element of the reversed multimap m1 is "
        << m1_rIter -> first << "." << endl;

   // begin can be used to start an iteration
   // through a multimap in a forward order
   cout << "The multimap is: ";
   for ( m1_Iter = m1.begin( ) ; m1_Iter != m1.end( ); m1_Iter++)
      cout << m1_Iter -> first << " ";
      cout << "." << endl;

   // rbegin can be used to start an iteration
   // through a multimap in a reverse order
   cout << "The reversed multimap is: ";
   for ( m1_rIter = m1.rbegin( ) ; m1_rIter != m1.rend( ); m1_rIter++)
      cout << m1_rIter -> first << " ";
      cout << "." << endl;

   // A multimap element can be erased by dereferencing to its key
   m1_rIter = --m1.rend( );
   m1.erase ( m1_rIter -> first );

   m1_rIter = m1.rend( );
   m1_rIter--;
   cout << "After the erasure, the last element "
        << "in the reversed multimap is "
        << m1_rIter -> first << "." << endl;
}
The last element of the reversed multimap m1 is 1.
The multimap is: 1 2 3 .
The reversed multimap is: 3 2 1 .
After the erasure, the last element in the reversed multimap is 2.

multimap::reverse_iterator

역순 multimap의 요소를 읽거나 수정할 수 있는 양방향 반복기를 제공하는 형식입니다.

typedef std::reverse_iterator<iterator> reverse_iterator;

설명

형식 reverse_iterator 은 역방향으로 반복하는 multimap 데 사용됩니다.

reverse_iterator 형식pair<const Key, Type>인 개체를 value_type가리키는 점으로 정의된 multimap 값입니다. 키의 값은 첫 번째 멤버 쌍을 통해 제공되며 매핑된 요소의 값은 쌍의 두 번째 멤버를 통해 제공됩니다.

요소에 대한 reverse_iteratorrIter 포인팅을 multimap역참조하려면 연산자를 -> 사용합니다.

요소에 대한 키 값에 액세스하려면 해당(*rIter).first되는 키를 사용합니다rIter->first. 요소에 대해 매핑된 데이텀의 값에 액세스하려면 해당(*rIter).second되는 를 사용합니다rIter->second.

예시

선언하고 사용하는 reverse_iterator방법에 대한 rbegin 예제는 예제를 참조하세요.

multimap::size

multimap에 있는 요소 수를 반환합니다.

size_type size() const;

Return Value

의 현재 길이입니다 multimap.

예시

다음 예제에서는 멤버 함수를 사용하는 방법을 multimap::size 보여 줍니다.

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

int main()
{
    using namespace std;
    multimap<int, int> m1, m2;
    multimap<int, int>::size_type i;
    typedef pair<int, int> Int_Pair;

    m1.insert(Int_Pair(1, 1));
    i = m1.size();
    cout << "The multimap length is " << i << "." << endl;

    m1.insert(Int_Pair(2, 4));
    i = m1.size();
    cout << "The multimap length is now " << i << "." << endl;
}
The multimap length is 1.
The multimap length is now 2.

multimap::size_type

에 있는 요소 수를 계산하는 부호 없는 정수 형식입니다 multimap.

typedef typename allocator_type::size_type size_type;

예시

선언 및 사용 방법의 예제는 예제 size 를 참조하세요. size_type

multimap::swap

multimap의 요소를 교환합니다.

void swap(
    multimap<Key, Type, Traits, Allocator>& right);

매개 변수

right
multimap 교환할 요소를 제공하거나 multimap 해당 요소를 해당 요소와 multimapleft교환할 요소입니다.

설명

멤버 함수는 요소가 교환되는 두 multimap개의 요소를 지정하는 참조, 포인터 또는 반복기를 무효화하지 않습니다.

예시

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

int main( )
{
   using namespace std;
   multimap <int, int> m1, m2, m3;
   multimap <int, int>::iterator m1_Iter;
   typedef pair <int, int> Int_Pair;

   m1.insert ( Int_Pair ( 1, 10 ) );
   m1.insert ( Int_Pair ( 2, 20 ) );
   m1.insert ( Int_Pair ( 3, 30 ) );
   m2.insert ( Int_Pair ( 10, 100 ) );
   m2.insert ( Int_Pair ( 20, 200 ) );
   m3.insert ( Int_Pair ( 30, 300 ) );

   cout << "The original multimap m1 is:";
   for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )
      cout << " " << m1_Iter -> second;
   cout   << "." << endl;

   // This is the member function version of swap
   m1.swap( m2 );

   cout << "After swapping with m2, multimap m1 is:";
   for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )
      cout << " " << m1_Iter -> second;
   cout  << "." << endl;

   // This is the specialized template version of swap
   swap( m1, m3 );

   cout << "After swapping with m3, multimap m1 is:";
   for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )
      cout << " " << m1_Iter -> second;
   cout   << "." << endl;
}
The original multimap m1 is: 10 20 30.
After swapping with m2, multimap m1 is: 100 200.
After swapping with m3, multimap m1 is: 300.

multimap::upper_bound

iterator 지정된 키보다 큰 키를 사용하여 해당 요소의 첫 번째 요소를 multimap 반환합니다.

iterator upper_bound(const Key& key);

const_iterator upper_bound(const Key& key) const;

매개 변수

key
검색할 요소 multimap 의 정렬 키와 비교할 인수 키입니다.

Return Value

iterator 인수 키보다 큰 키를 사용하거나 const_iterator 키에 multimap 대한 일치 항목이 없는 경우 마지막 요소 다음에 나오는 위치의 주소를 지정하는 요소의 multimap 위치를 지정합니다.

반환 값이 할당 const_iterator된 경우 개체를 multimap 수정할 수 없습니다. 반환 값이 할당 iterator된 경우 개체를 multimap 수정할 수 있습니다.

예시

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

int main( )
{
   using namespace std;
   multimap <int, int> m1;
   multimap <int, int> :: const_iterator m1_AcIter, m1_RcIter;
   typedef pair <int, int> Int_Pair;

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

   m1_RcIter = m1.upper_bound( 1 );
   cout << "The 1st element of multimap m1 with "
        << "a key greater than 1 is: "
        << m1_RcIter -> second << "." << endl;

   m1_RcIter = m1.upper_bound( 2 );
   cout << "The first element of multimap m1 with a key "
        << " greater than 2 is: "
        << m1_RcIter -> second << "." << endl;

   // If no match is found for the key, end( ) is returned
   m1_RcIter = m1.lower_bound( 4 );

   if ( m1_RcIter == m1.end( ) )
      cout << "The multimap m1 doesn't have an element "
           << "with a key of 4." << endl;
   else
      cout << "The element of multimap m1 with a key of 4 is: "
           << m1_RcIter -> second << "." << endl;

   // The element at a specific location in the multimap can be
   // found using a dereferenced iterator addressing the location
   m1_AcIter = m1.begin( );
   m1_RcIter = m1.upper_bound( m1_AcIter -> first );
   cout << "The first element of m1 with a key greater than\n"
        << "that of the initial element of m1 is: "
        << m1_RcIter -> second << "." << endl;
}
The 1st element of multimap m1 with a key greater than 1 is: 20.
The first element of multimap m1 with a key  greater than 2 is: 30.
The multimap m1 doesn't have an element with a key of 4.
The first element of m1 with a key greater than
that of the initial element of m1 is: 20.

multimap::value_comp

멤버 함수는 키 값을 비교하여 multimap의 요소 순서를 결정하는 함수 개체를 반환합니다.

value_compare value_comp() const;

Return Value

요소의 순서를 multimap 지정하는 데 사용하는 비교 함수 개체를 반환합니다.

설명

multimap경우 두 요소가 e2(k2, d2)e1(k1, d1) 형식value_type의 개체이고 형식의 키이며 k2 형식 key_type 의 데이터인 위치 k1d1d2 해당 형식 m.value_comp(e1, e2)mapped_type의 데이터인 경우와 동일합니다m.key_comp(k1, k2).m

예시

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

int main( )
{
   using namespace std;

   multimap <int, int, less<int> > m1;
   multimap <int, int, less<int> >::value_compare vc1 = m1.value_comp( );
   multimap<int,int>::iterator Iter1, Iter2;

   Iter1= m1.insert ( multimap <int, int> :: value_type ( 1, 10 ) );
   Iter2= m1.insert ( multimap <int, int> :: value_type ( 2, 5 ) );

   if( vc1( *Iter1, *Iter2 ) == true )
   {
      cout << "The element ( 1,10 ) precedes the element ( 2,5 )."
           << endl;
   }
   else
   {
      cout << "The element ( 1,10 ) does "
           << "not precede the element ( 2,5 )."
           << endl;
   }

   if( vc1( *Iter2, *Iter1 ) == true )
   {
      cout << "The element ( 2,5 ) precedes the element ( 1,10 )."
           << endl;
   }
   else
   {
      cout << "The element ( 2,5 ) does "
           << "not precede the element ( 1,10 )."
           << endl;
   }
}
The element ( 1,10 ) precedes the element ( 2,5 ).
The element ( 2,5 ) does not precede the element ( 1,10 ).

multimap::value_type

map에 있는 요소로 저장된 개체의 형식을 나타내는 형식입니다.

typedef pair<const Key, Type> value_type;

예시

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

int main( )
{
   using namespace std;
   typedef pair <const int, int> cInt2Int;
   multimap <int, int> m1;
   multimap <int, int> :: key_type key1;
   multimap <int, int> :: mapped_type mapped1;
   multimap <int, int> :: value_type value1;
   multimap <int, int> :: iterator pIter;

   // value_type can be used to pass the correct type
   // explicitly to avoid implicit type conversion
   m1.insert ( multimap <int, int> :: value_type ( 1, 10 ) );

   // Compare another way to insert objects into a hash_multimap
   m1.insert ( cInt2Int ( 2, 20 ) );

   // Initializing key1 and mapped1
   key1 = ( m1.begin( ) -> first );
   mapped1 = ( m1.begin( ) -> second );

   cout << "The key of first element in the multimap is "
        << key1 << "." << endl;

   cout << "The data value of first element in the multimap is "
        << mapped1 << "." << endl;

   // The following line would cause an error because
   // the value_type is not assignable
   // value1 = cInt2Int ( 4, 40 );

   cout  << "The keys of the mapped elements are:";
   for ( pIter = m1.begin( ) ; pIter != m1.end( ) ; pIter++ )
      cout << " " << pIter -> first;
   cout << "." << endl;

   cout  << "The values of the mapped elements are:";
   for ( pIter = m1.begin( ) ; pIter != m1.end( ) ; pIter++ )
      cout << " " << pIter -> second;
   cout << "." << endl;
}
The key of first element in the multimap is 1.
The data value of first element in the multimap is 10.
The keys of the mapped elements are: 1 2.
The values of the mapped elements are: 10 20.

참고 항목

컨테이너
C++ 표준 라이브러리의 스레드 보안
C++ 표준 라이브러리 참조