multiset 클래스

C++ 표준 라이브러리 multiset 클래스는 포함된 요소값이 고유할 필요가 없고 데이터가 자동 정렬되는 기준인 키 값으로 사용된 컬렉션의 데이터를 저장 및 검색하는 데 사용됩니다. 요소 multiset 의 키 값은 직접 변경되지 않을 수 있습니다. 대신, 이전 값을 삭제하고 새 값의 요소를 삽입해야 합니다.

구문

template <class Key, class Compare =less <Key>, class Allocator =allocator <Key>>
class multiset

매개 변수

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

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

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

Allocator
메모리 할당 및 할당 취소에 대한 multiset세부 정보를 캡슐화하는 저장된 할당자 개체를 나타내는 형식입니다. 기본값은 allocator<Key>입니다.

설명

C++ 표준 라이브러리 multiset 클래스는 다음과 같습니다.

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

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

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

  • 하나의 키 값에 연결된 많은 요소 값을 가질 수 있도록 해당 요소에 고유 키가 필요하지 않음을 나타내는 여러 값이 있습니다.

  • 해당 요소 값은 키 값과 구별되므로 간단한 연관 컨테이너입니다.

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

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

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

multiset 애플리케이션에서 해당 키와 값을 연결 하는 조건이 충족 되는 경우 선택 하는 결합 컨테이너 여야 합니다. 요소는 multiset 여러 개의 항목일 수 있으며 자체 정렬 키로 사용할 수 있으므로 키가 고유하지 않습니다. 이 형식의 구조에 대한 모델은 정렬된 목록입니다. 예를 들어, 단어 내의 단어가 두 번 이상 나타날 수 있습니다. 단어가 여러 번 나타날 수 있도록 허용되지 않은 경우 set가 적절한 컨테이너 구조입니다. 고유 키 단어 목록에 고유 정의가 연결된 경우 이 데이터를 포함하기 위한 적절한 구조는 map입니다. 대신 정의가 고유 multimap 하지 않은 경우 선택한 컨테이너가 됩니다.

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

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

생성자

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

Typedef

형식 이름 설명
allocator_type allocator 개체에 대한 multiset 클래스의 typedef
const_iterator constmultiset 요소를 읽을 수 있는 양방향 반복기에 대한 typedef
const_pointer constmultiset 요소를 가리키는 포인터에 대한 typedef
const_reference 읽기 및 작업 수행 const 을 위해 const 저장된 요소에 대한 참조에 multiset 대한 typedef입니다.
const_reverse_iterator constmultiset 요소를 읽을 수 있는 양방향 반복기에 대한 typedef
difference_type 반복기가 가리키는 요소 사이의 범위에 있는 multiset의 요소 개수에 대한 부호 있는 정수 typedef
iterator multiset의 모든 요소를 읽거나 수정할 수 있는 양방향 반복기에 대한 typedef
key_compare multiset의 두 요소간 상대적 순서를 결정하는 두 키를 비교할 수 있는 함수 개체에 대한 typedef
key_type multiset의 두 요소간 상대적 순서를 결정하는 두 정렬 키를 비교할 수 있는 함수 개체에 대한 typedef
pointer multiset의 요소를 가리키는 포인터에 대한 typedef
reference multiset에 저장된 요소에 대한 참조의 typedef
reverse_iterator 역순 multiset의 요소를 읽거나 수정할 수 있는 양방향 반복기에 대한 typedef
size_type multiset에서 요소 수를 표현할 수 있는 부호 없는 정수 형식입니다.
value_compare 두 요소를 정렬 키로 비교하여 multiset에서 상대적 순서를 결정할 수 있는 함수 개체의 typedef
value_type 해당 용량 내 multiset 요소로 저장된 개체를 값으로 설명하는 typedef

멤버 함수

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

연산자

연산자 설명
operator= multiset의 요소를 다른 multiset의 복사본으로 대체합니다.

요구 사항

헤더<set>:

네임스페이스:std

multiset::allocator_type

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

typedef Allocator allocator_type;

설명

allocator_type은 템플릿 매개 변수 Allocator의 동의어입니다.

Allocator에 대한 자세한 내용은 multiset 클래스 항목의 설명 섹션을 참조하세요.

예시

다음 예제 get_allocator 를 참조하세요. allocator_type

multiset::begin

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

const_iterator begin() const;

iterator begin();

Return Value

빈 다중 집합 뒤에 있는 위치 또는 첫 번째 요소의 multiset 주소를 지정하는 양방향 반복기입니다.

예시

// multiset_begin.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> ms1;
   multiset <int>::iterator ms1_Iter;
   multiset <int>::const_iterator ms1_cIter;

   ms1.insert( 1 );
   ms1.insert( 2 );
   ms1.insert( 3 );

   ms1_Iter = ms1.begin( );
   cout << "The first element of ms1 is " << *ms1_Iter << endl;

   ms1_Iter = ms1.begin( );
   ms1.erase( ms1_Iter );

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

   ms1_cIter = ms1.begin( );
   cout << "The first element of ms1 is now " << *ms1_cIter << endl;
}
The first element of ms1 is 1
The first element of ms1 is now 2

multiset::cbegin

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

const_iterator cbegin() const;

Return Value

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

설명

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

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

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

// i2 is Container<T>::const_iterator

multiset::cend

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

const_iterator cend() const;

Return Value

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

설명

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

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

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

// i2 is Container<T>::const_iterator

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

multiset::clear

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

void clear();

예시

// multiset_clear.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> ms1;

   ms1.insert( 1 );
   ms1.insert( 2 );

   cout << "The size of the multiset is initially "
        << ms1.size( ) << "." << endl;

   ms1.clear( );
   cout << "The size of the multiset after clearing is "
        << ms1.size( ) << "." << endl;
}
The size of the multiset is initially 2.
The size of the multiset after clearing is 0.

multiset::const_iterator

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

typedef implementation-defined const_iterator;

설명

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

예시

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

multiset::const_pointer

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

typedef typename allocator_type::const_pointer const_pointer;

설명

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

대부분의 경우 반복기를 사용하여 개체의 요소에 multiset 액세스해야 합니다.

multiset::const_reference

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

typedef typename allocator_type::const_reference const_reference;

예시

// multiset_const_ref.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> ms1;

   ms1.insert( 10 );
   ms1.insert( 20 );

   // Declare and initialize a const_reference &Ref1
   // to the 1st element
   const int &Ref1 = *ms1.begin( );

   cout << "The first element in the multiset is "
        << Ref1 << "." << endl;

   // The following line would cause an error because the
   // const_reference can't be used to modify the multiset
   // Ref1 = Ref1 + 5;
}
The first element in the multiset is 10.

multiset::const_reverse_iterator

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

typedef std::reverse_iterator<const_iterator> const_reverse_iterator;

설명

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

예시

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

multiset::contains

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

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 <set>
#include <iostream>

int main()
{
    std::multiset<int> theMultiSet = {1, 2};

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

    return 0;
}
true
false

multiset::count

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

size_type count(const Key& key) const;

매개 변수

key
에서 일치 multiset시킬 요소의 키입니다.

Return Value

정렬 키가 매개 변수 키와 일치하는 요소 multiset 의 수입니다.

설명

구성원 함수는 다음 범위에 있는 요소 수 x를 반환합니다.

[ lower_bound(key), upper_bound(key) )

예시

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

// multiset_count.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main()
{
    using namespace std;
    multiset<int> ms1;
    multiset<int>::size_type i;

    ms1.insert(1);
    ms1.insert(1);
    ms1.insert(2);

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

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

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

multiset::crbegin

반전된 multiset에서 첫 번째 요소를 주소 지정하는 상수 반복기를 반환합니다.

const_reverse_iterator crbegin() const;

Return Value

반전된 multiset의 첫 번째 요소에 대한 주소를 지정하거나, 반전 해제된 multiset의 마지막 요소에 대한 주소를 지정하는 상수 역방향 양방향 반복기입니다.

설명

crbegin 는 시작이 .와 함께 사용되는 것처럼 역방향 다중 집합과 함께 multiset사용됩니다.

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

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

예시

// multiset_crbegin.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> ms1;
   multiset <int>::const_reverse_iterator ms1_crIter;

   ms1.insert( 10 );
   ms1.insert( 20 );
   ms1.insert( 30 );

   ms1_crIter = ms1.crbegin( );
   cout << "The first element in the reversed multiset is "
        << *ms1_crIter << "." << endl;
}
The first element in the reversed multiset is 30.

multiset::crend

역방향 multiset에서 마지막 요소 다음에 나오는 위치의 주소를 지정하는 상수 반복기를 반환합니다.

const_reverse_iterator crend() const;

Return Value

역방향 multiset에서 마지막 요소 다음의 위치(정방향 multiset의 첫 번째 요소 앞의 위치) 주소를 지정하는 const 역방향 양방향 반복기입니다.

설명

crend 는 .와 함께 사용되는 것처럼 end 역방향 다중 집합과 함께 multiset사용됩니다.

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

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

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

예시

// multiset_crend.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main() {
   using namespace std;
   multiset <int> ms1;
   multiset <int>::const_reverse_iterator ms1_crIter;

   ms1.insert( 10 );
   ms1.insert( 20 );
   ms1.insert( 30 );

   ms1_crIter = ms1.crend( ) ;
   ms1_crIter--;
   cout << "The last element in the reversed multiset is "
        << *ms1_crIter << "." << endl;
}

multiset::difference_type

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

typedef typename allocator_type::difference_type difference_type;

설명

difference_type은 컨테이너의 반복기를 빼거나 더할 때 반환되는 형식입니다. difference_type은 일반적으로 firstlast 반복기 사이의 [ first, last) 범위 내 요소 수를 나타내는 데 사용됩니다. 여기에는 first가 가리키는 요소와 last가 가리키는 요소까지의 요소 범위가 포함됩니다(마지막 요소는 포함되지 않음).

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

예시

// multiset_diff_type.cpp
// compile with: /EHsc
#include <iostream>
#include <set>
#include <algorithm>

int main( )
{
   using namespace std;

   multiset <int> ms1;
   multiset <int>::iterator ms1_Iter, ms1_bIter, ms1_eIter;

   ms1.insert( 20 );
   ms1.insert( 10 );
   ms1.insert( 20 );

   ms1_bIter = ms1.begin( );
   ms1_eIter = ms1.end( );

   multiset <int>::difference_type   df_typ5, df_typ10, df_typ20;

   df_typ5 = count( ms1_bIter, ms1_eIter, 5 );
   df_typ10 = count( ms1_bIter, ms1_eIter, 10 );
   df_typ20 = count( ms1_bIter, ms1_eIter, 20 );

   // The keys, and hence the elements, of a multiset aren't unique
   cout << "The number '5' occurs " << df_typ5
        << " times in multiset ms1.\n";
   cout << "The number '10' occurs " << df_typ10
        << " times in multiset ms1.\n";
   cout << "The number '20' occurs " << df_typ20
        << " times in multiset ms1.\n";

   // Count the number of elements in a multiset
   multiset <int>::difference_type  df_count = 0;
   ms1_Iter = ms1.begin( );
   while ( ms1_Iter != ms1_eIter)
   {
      df_count++;
      ms1_Iter++;
   }

   cout << "The number of elements in the multiset ms1 is: "
        << df_count << "." << endl;
}
The number '5' occurs 0 times in multiset ms1.
The number '10' occurs 1 times in multiset ms1.
The number '20' occurs 2 times in multiset ms1.
The number of elements in the multiset ms1 is: 3.

multiset::emplace

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

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

매개 변수

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

Return Value

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

설명

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

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

예시

// multiset_emplace.cpp
// compile with: /EHsc
#include <set>
#include <string>
#include <iostream>

using namespace std;

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

    for (const auto& p : s) {
        cout << "(" << p << ") ";
    }

    cout << endl;
}

int main()
{
    multiset<string> s1;

    s1.emplace("Anna");
    s1.emplace("Bob");
    s1.emplace("Carmine");

    cout << "multiset modified, now contains ";
    print(s1);
    cout << endl;

    s1.emplace("Bob");

    cout << "multiset modified, now contains ";
    print(s1);
    cout << endl;
}

multiset::emplace_hint

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

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

매개 변수

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

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

Return Value

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

설명

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

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

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

multiset::empty

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

bool empty() const;

Return Value

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

예시

// multiset_empty.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main()
{
   using namespace std;
   multiset <int> ms1, ms2;
   ms1.insert ( 1 );

   if ( ms1.empty( ) )
      cout << "The multiset ms1 is empty." << endl;
   else
      cout << "The multiset ms1 is not empty." << endl;

   if ( ms2.empty( ) )
      cout << "The multiset ms2 is empty." << endl;
   else
      cout << "The multiset ms2 is not empty." << endl;
}
The multiset ms1 is not empty.
The multiset ms2 is empty.

multiset::end

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

const_iterator end() const;

iterator end();

Return Value

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

설명

end 는 반복기가 다중 집합의 끝을 통과했는지 여부를 테스트하는 데 사용됩니다.

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

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

multiset::equal_range

지정된 키보다 더 큰 키를 가진 multiset의 첫 번째 요소와 지정된 키보다 더 크거나 같은 키를 가진 multiset의 첫 번째 요소에 반복기의 쌍을 각각 반환합니다.

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

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

매개 변수

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

Return Value

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

구성원 함수가 반환하는 pr 쌍의 첫 번째 반복기에 액세스하려면 pr. first하한 반복기를 역참조하려면 *( pr. first)를 사용합니다. 구성원 함수가 반환하는 pr 쌍의 두 번째 반복기에 액세스하려면 pr. second상한 반복기를 역참조하려면 *( pr. second)를 사용합니다.

예시

// multiset_equal_range.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   typedef multiset<int, less<int> > IntSet;
   IntSet ms1;
   multiset <int> :: const_iterator ms1_RcIter;

   ms1.insert( 10 );
   ms1.insert( 20 );
   ms1.insert( 30 );

   pair <IntSet::const_iterator, IntSet::const_iterator> p1, p2;
   p1 = ms1.equal_range( 20 );

   cout << "The upper bound of the element with "
        << "a key of 20 in the multiset ms1 is: "
        << *( p1.second ) << "." << endl;

   cout << "The lower bound of the element with "
        << "a key of 20 in the multiset ms1 is: "
        << *( p1.first ) << "." << endl;

   // Compare the upper_bound called directly
   ms1_RcIter = ms1.upper_bound( 20 );
   cout << "A direct call of upper_bound( 20 ) gives "
        << *ms1_RcIter << "," << endl
        << "matching the 2nd element of the pair"
        << " returned by equal_range( 20 )." << endl;

   p2 = ms1.equal_range( 40 );

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

multiset::erase

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

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

처음 두 멤버 함수의 경우 첫 번째 요소를 다시 지정하는 양방향 반복기기본 제거된 요소를 벗어나거나 해당 요소가 없는 경우 끝 요소 multiset 입니다.

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

설명

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

multiset::find

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

iterator find(const Key& key);

const_iterator find(const Key& key) const;

매개 변수

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

Return Value

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

설명

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

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

예시

// compile with: /EHsc /W4 /MTd
#include <set>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

template <typename T> void print_elem(const T& t) {
    cout << "(" << t << ") ";
}

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()
{
    multiset<int> s1({ 40, 45 });
    cout << "The starting multiset s1 is: " << endl;
    print_collection(s1);

    vector<int> v;
    v.push_back(43);
    v.push_back(41);
    v.push_back(46);
    v.push_back(42);
    v.push_back(44);
    v.push_back(44); // attempt a duplicate

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

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

    cout << "The modified multiset s1 is: " << endl;
    print_collection(s1);
    cout << endl;
    findit(s1, 45);
    findit(s1, 6);
}

multiset::get_allocator

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

allocator_type get_allocator() const;

Return Value

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

설명

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

예시

// multiset_get_allocator.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int>::allocator_type ms1_Alloc;
   multiset <int>::allocator_type ms2_Alloc;
   multiset <double>::allocator_type ms3_Alloc;
   multiset <int>::allocator_type ms4_Alloc;

   // The following lines declare objects
   // that use the default allocator.
   multiset <int> ms1;
   multiset <int, allocator<int> > ms2;
   multiset <double, allocator<double> > ms3;

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

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

   // The following lines create a multiset ms4
   // with the allocator of multiset ms1
   ms1_Alloc = ms1.get_allocator( );
   multiset <int> ms4( less<int>( ), ms1_Alloc );
   ms4_Alloc = ms4.get_allocator( );

   // Two allocators are interchangeable if
   // storage allocated from each can be
   // deallocated with the other
   if( ms1_Alloc == ms4_Alloc )
   {
      cout << "Allocators are interchangeable."
           << endl;
   }
   else
   {
      cout << "Allocators are not interchangeable."
           << endl;
   }
}

multiset::insert

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

// (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
에 삽입할 요소의 값입니다 multiset.

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

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

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

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

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

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

Return Value

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

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

설명

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

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

value_type 컨테이너의 형식은 컨테이너에 속하는 typedef이며 집합 multiset<V>::value_type 의 경우 형식const V입니다.

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

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

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

예시

// multiset_insert.cpp
// compile with: /EHsc
#include <set>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

    for (const auto& p : s) {
        cout << "(" << p << ") ";
    }

    cout << endl;
}

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

    cout << "The original multiset values of s1 are:" << endl;
    print(s1);

    // intentionally attempt a duplicate, single element
    s1.insert(1);
    cout << "The modified multiset values of s1 are:" << endl;
    print(s1);
    cout << endl;

    // single element, with hint
    s1.insert(s1.end(), 30);
    cout << "The modified multiset values of s1 are:" << endl;
    print(s1);
    cout << endl;

    // The templatized version inserting a jumbled range
    multiset<int> s2;
    vector<int> v;
    v.push_back(43);
    v.push_back(294);
    v.push_back(41);
    v.push_back(330);
    v.push_back(42);
    v.push_back(45);

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

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

    cout << "The modified multiset values of s2 are:" << endl;
    print(s2);
    cout << endl;

    // The templatized versions move-constructing elements
    multiset<string>  s3;
    string str1("blue"), str2("green");

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

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

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

multiset::iterator

의 모든 요소를 읽을 수 있는 상수 양방향 반복기를 제공하는 형식입니다 multiset.

typedef implementation-defined iterator;

예시

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

multiset::key_comp

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

key_compare key_comp() const;

Return Value

템플릿 매개 변수Comparemultiset 요소를 정렬하는 데 사용하는 함수 개체를 반환합니다.

Compare에 대한 자세한 내용은 multiset 클래스 항목의 설명 섹션을 참조하세요.

설명

저장된 개체는 구성원 함수

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

를 정의합니다. 이 함수는 정렬 순서에서 x가 엄격하게 y 앞에 오면 true를 반환합니다.

value_compare 둘 다 key_compare 템플릿 매개 변수Compare의 동의어입니다. 클래스 맵 및 multimap과의 호환성을 위해 클래스 집합 및 다중 집합에 대해 두 형식이 모두 제공됩니다.

예시

// multiset_key_comp.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;

   multiset <int, less<int> > ms1;
   multiset <int, less<int> >::key_compare kc1 = ms1.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 s1."
           << endl;
   }
   else
   {
      cout << "kc1( 2,3 ) returns value of false "
           << "where kc1 is the function object of ms1."
           << endl;
   }

   multiset <int, greater<int> > ms2;
   multiset <int, greater<int> >::key_compare kc2 = ms2.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 ms2."
           << endl;
   }
   else
   {
      cout << "kc2( 2,3 ) returns value of false, "
           << "where kc2 is the function object of ms2."
           << endl;
   }
}
kc1( 2,3 ) returns value of true, where kc1 is the function object of s1.
kc2( 2,3 ) returns value of false, where kc2 is the function object of ms2.

multiset::key_compare

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

typedef Compare key_compare;

설명

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

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

예시

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

multiset::key_type

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

typedef Key key_type;

설명

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

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

예시

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

multiset::lower_bound

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

const_iterator lower_bound(const Key& key) const;

iterator lower_bound(const Key& key);

매개 변수

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

Return Value

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

예시

// multiset_lower_bound.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> ms1;
   multiset <int> :: const_iterator ms1_AcIter, ms1_RcIter;

   ms1.insert( 10 );
   ms1.insert( 20 );
   ms1.insert( 30 );

   ms1_RcIter = ms1.lower_bound( 20 );
   cout << "The element of multiset ms1 with a key of 20 is: "
        << *ms1_RcIter << "." << endl;

   ms1_RcIter = ms1.lower_bound( 40 );

   // If no match is found for the key, end( ) is returned
   if ( ms1_RcIter == ms1.end( ) )
      cout << "The multiset ms1 doesn't have an element "
           << "with a key of 40." << endl;
   else
      cout << "The element of multiset ms1 with a key of 40 is: "
           << *ms1_RcIter << "." << endl;

   // The element at a specific location in the multiset can be
   // found using a dereferenced iterator addressing the location
   ms1_AcIter = ms1.end( );
   ms1_AcIter--;
   ms1_RcIter = ms1.lower_bound( *ms1_AcIter );
   cout << "The element of ms1 with a key matching "
        << "that of the last element is: "
        << *ms1_RcIter << "." << endl;
}
The element of multiset ms1 with a key of 20 is: 20.
The multiset ms1 doesn't have an element with a key of 40.
The element of ms1 with a key matching that of the last element is: 30.

multiset::max_size

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

size_type max_size() const;

Return Value

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

예시

// multiset_max_size.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> ms1;
   multiset <int>::size_type i;

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

multiset::multiset

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

multiset();

explicit multiset (
    const Compare& Comp);

multiset (
    const Compare& Comp,
    const Allocator& Al);

multiset(
    const multiset& Right);

multiset(
    multiset&& Right);

multiset(
    initializer_list<Type> IList);

multiset(
    initializer_list<Type> IList,
    const Compare& Comp);

multiset(
    initializer_list<Type> IList,
    const Compare& Comp,
    const Allocator& Al);

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

template <class InputIterator>
multiset (
    InputIterator First,
    InputIterator Last,
    const Compare& Comp);

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

매개 변수

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

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

Right
multiset 생성된 다중 집합이 복사본이 될 수 있습니다.

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

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

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

설명

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

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

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

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

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

다섯 번째 생성자는 이동하여 Right복사본을 multiset 지정합니다.

6번째, 7번째 및 8번째 생성자는 요소를 복사할 initializer_list 지정합니다.

다음 세 생성자는 비교 함수 및 할당자의 형식을 지정할 때 명시성이 높아진 범위 [First, Last)multiset 의 범위를 복사합니다.

예시

// multiset_ctor.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main()
{
    using namespace std;
    //multiset <int>::iterator ms1_Iter, ms2_Iter, ms3_Iter;
    multiset <int>::iterator ms4_Iter, ms5_Iter, ms6_Iter, ms7_Iter;

    // Create an empty multiset ms0 of key type integer
    multiset <int> ms0;

    // Create an empty multiset ms1 with the key comparison
    // function of less than, then insert 4 elements
    multiset <int, less<int> > ms1;
    ms1.insert(10);
    ms1.insert(20);
    ms1.insert(20);
    ms1.insert(40);

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

    // Create a multiset ms3 with the
    // allocator of multiset ms1
    multiset <int>::allocator_type ms1_Alloc;
    ms1_Alloc = ms1.get_allocator();
    multiset <int> ms3(less<int>(), ms1_Alloc);
    ms3.insert(30);

    // Create a copy, multiset ms4, of multiset ms1
    multiset <int> ms4(ms1);

    // Create a multiset ms5 by copying the range ms1[ first,  last)
    multiset <int>::const_iterator ms1_bcIter, ms1_ecIter;
    ms1_bcIter = ms1.begin();
    ms1_ecIter = ms1.begin();
    ms1_ecIter++;
    ms1_ecIter++;
    multiset <int> ms5(ms1_bcIter, ms1_ecIter);

    // Create a multiset ms6 by copying the range ms4[ first,  last)
    // and with the allocator of multiset ms2
    multiset <int>::allocator_type ms2_Alloc;
    ms2_Alloc = ms2.get_allocator();
    multiset <int> ms6(ms4.begin(), ++ms4.begin(), less<int>(), ms2_Alloc);

    cout << "ms1 =";
    for (auto i : ms1)
        cout << " " << i;
    cout << endl;

    cout << "ms2 =";
    for (auto i : ms2)
        cout << " " << i;
   cout << endl;

   cout << "ms3 =";
   for (auto i : ms3)
       cout << " " << i;
    cout << endl;

    cout << "ms4 =";
    for (auto i : ms4)
        cout << " " << i;
    cout << endl;

    cout << "ms5 =";
    for (auto i : ms5)
        cout << " " << i;
    cout << endl;

    cout << "ms6 =";
    for (auto i : ms6)
        cout << " " << i;
    cout << endl;

    // Create a multiset by moving ms5
    multiset<int> ms7(move(ms5));
    cout << "ms7 =";
    for (auto i : ms7)
        cout << " " << i;
    cout << endl;

    // Create a multiset with an initializer_list
    multiset<int> ms8({1, 2, 3, 4});
    cout << "ms8=";
    for (auto i : ms8)
        cout << " " << i;
    cout << endl;
}

multiset::operator=

다른 multiset의 요소를 사용하여 이 multiset의 요소를 대체합니다.

multiset& operator=(const multiset& right);

multiset& operator=(multiset&& right);

매개 변수

Right
요소를 복사하거나 이동하는 원본 multiset입니다.

설명

operator=는 사용하는 참조 형식(lvalue 또는 rvalue)에 따라 Right의 요소를 이 multiset에 복사하거나 이동합니다. operator=가 실행되기 전에 이 multiset에 있는 요소가 삭제됩니다.

예시

// multiset_operator_as.cpp
// compile with: /EHsc
#include <multiset>
#include <iostream>

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

   v1.insert(10);

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

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

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

multiset::pointer

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

typedef typename allocator_type::pointer pointer;

설명

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

대부분의 경우 반복기를 사용하여 개체의 요소에 multiset 액세스해야 합니다.

multiset::rbegin

반전된 multiset에서 첫 번째 요소를 주소 지정하는 반복기를 반환합니다.

const_reverse_iterator rbegin() const;

reverse_iterator rbegin();

Return Value

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

설명

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

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

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

예시

// multiset_rbegin.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> ms1;
   multiset <int>::iterator ms1_Iter;
   multiset <int>::reverse_iterator ms1_rIter;

   ms1.insert( 10 );
   ms1.insert( 20 );
   ms1.insert( 30 );

   ms1_rIter = ms1.rbegin( );
   cout << "The first element in the reversed multiset is "
        << *ms1_rIter << "." << endl;

   // begin can be used to start an iteration
   // through a multiset in a forward order
   cout << "The multiset is:";
   for ( ms1_Iter = ms1.begin( ) ; ms1_Iter != ms1.end( ); ms1_Iter++ )
      cout << " " << *ms1_Iter;
   cout << endl;

   // rbegin can be used to start an iteration
   // through a multiset in a reverse order
   cout << "The reversed multiset is:";
   for ( ms1_rIter = ms1.rbegin( ) ; ms1_rIter != ms1.rend( ); ms1_rIter++ )
      cout << " " << *ms1_rIter;
   cout << endl;

   // a multiset element can be erased by dereferencing to its key
   ms1_rIter = ms1.rbegin( );
   ms1.erase ( *ms1_rIter );

   ms1_rIter = ms1.rbegin( );
   cout << "After the erasure, the first element "
        << "in the reversed multiset is "<< *ms1_rIter << "."
        << endl;
}
The first element in the reversed multiset is 30.
The multiset is: 10 20 30
The reversed multiset is: 30 20 10
After the erasure, the first element in the reversed multiset is 20.

multiset::reference

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

typedef typename allocator_type::reference reference;

예시

// multiset_ref.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> ms1;

   ms1.insert( 10 );
   ms1.insert( 20 );

   // Declare and initialize a reference &Ref1 to the 1st element
   const int &Ref1 = *ms1.begin( );

   cout << "The first element in the multiset is "
        << Ref1 << "." << endl;
}
The first element in the multiset is 10.

multiset::rend

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

const_reverse_iterator rend() const;

reverse_iterator rend();

Return Value

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

설명

rend 는 .와 함께 사용되는 것처럼 end 역방향 다중 집합과 함께 multiset사용됩니다.

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

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

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

예시

// multiset_rend.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main() {
   using namespace std;
   multiset <int> ms1;
   multiset <int>::iterator ms1_Iter;
   multiset <int>::reverse_iterator ms1_rIter;
   multiset <int>::const_reverse_iterator ms1_crIter;

   ms1.insert( 10 );
   ms1.insert( 20 );
   ms1.insert( 30 );

   ms1_rIter = ms1.rend( ) ;
   ms1_rIter--;
   cout << "The last element in the reversed multiset is "
        << *ms1_rIter << "." << endl;

   // end can be used to terminate an iteration
   // through a multiset in a forward order
   cout << "The multiset is: ";
   for ( ms1_Iter = ms1.begin( ) ; ms1_Iter != ms1.end( ); ms1_Iter++ )
      cout << *ms1_Iter << " ";
   cout << "." << endl;

   // rend can be used to terminate an iteration
   // through a multiset in a reverse order
   cout << "The reversed multiset is: ";
   for ( ms1_rIter = ms1.rbegin( ) ; ms1_rIter != ms1.rend( ); ms1_rIter++ )
      cout << *ms1_rIter << " ";
   cout << "." << endl;

   ms1_rIter = ms1.rend( );
   ms1_rIter--;
   ms1.erase ( *ms1_rIter );

   ms1_rIter = ms1.rend( );
   --ms1_rIter;
   cout << "After the erasure, the last element in the "
        << "reversed multiset is " << *ms1_rIter << "." << endl;
}

multiset::reverse_iterator

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

typedef std::reverse_iterator<iterator> reverse_iterator;

설명

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

예시

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

multiset::size

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

size_type size() const;

Return Value

의 현재 길이입니다 multiset.

예시

// multiset_size.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> ms1;
   multiset <int> :: size_type i;

   ms1.insert( 1 );
   i = ms1.size( );
   cout << "The multiset length is " << i << "." << endl;

   ms1.insert( 2 );
   i = ms1.size( );
   cout << "The multiset length is now " << i << "." << endl;
}
The multiset length is 1.
The multiset length is now 2.

multiset::size_type

multiset에서 요소 수를 표현할 수 있는 부호 없는 정수 형식입니다.

typedef typename allocator_type::size_type size_type;

예시

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

multiset::swap

두 multiset의 요소를 교환합니다.

void swap(
    multiset<Key, Compare, Allocator>& right);

매개 변수

Right
대상 multiset와 교환할 요소를 제공하는 인수 집합입니다.

설명

구성원 함수는 해당 요소를 교환할 두 multiset의 요소를 지정하는 참조, 포인터 또는 반복기를 무효화하지 않습니다.

예시

// multiset_swap.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> ms1, ms2, ms3;
   multiset <int>::iterator ms1_Iter;

   ms1.insert( 10 );
   ms1.insert( 20 );
   ms1.insert( 30 );
   ms2.insert( 100 );
   ms2.insert( 200 );
   ms3.insert( 300 );

   cout << "The original multiset ms1 is:";
   for ( ms1_Iter = ms1.begin( ); ms1_Iter != ms1.end( ); ms1_Iter++ )
      cout << " " << *ms1_Iter;
   cout << "." << endl;

   // This is the member function version of swap
   ms1.swap( ms2 );

   cout << "After swapping with ms2, list ms1 is:";
   for ( ms1_Iter = ms1.begin( ); ms1_Iter != ms1.end( ); ms1_Iter++ )
      cout << " " << *ms1_Iter;
   cout << "." << endl;

   // This is the specialized template version of swap
   swap( ms1, ms3 );

   cout << "After swapping with ms3, list ms1 is:";
   for ( ms1_Iter = ms1.begin( ); ms1_Iter != ms1.end( ); ms1_Iter++ )
      cout << " " << *ms1_Iter;
   cout   << "." << endl;
}
The original multiset ms1 is: 10 20 30.
After swapping with ms2, list ms1 is: 100 200.
After swapping with ms3, list ms1 is: 300.

multiset::upper_bound

multiset에 지정된 키보다 큰 키를 가진 첫 번째 요소에 반복기를 반환합니다.

const_iterator upper_bound(const Key& key) const;

iterator upper_bound(const Key& key);

매개 변수

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

Return Value

인수 키보다 크거나 const_iterator 키와 일치하는 항목이 없는 경우 마지막 요소 다음에 나오는 위치의 주소를 지정하는 키가 있는 요소 multisetmultiset 위치를 주소 지정하는 반복기입니다.

예시

// multiset_upper_bound.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> ms1;
   multiset <int> :: const_iterator ms1_AcIter, ms1_RcIter;

   ms1.insert( 10 );
   ms1.insert( 20 );
   ms1.insert( 30 );

   ms1_RcIter = ms1.upper_bound( 20 );
   cout << "The first element of multiset ms1 with a key greater "
           << "than 20 is: " << *ms1_RcIter << "." << endl;

   ms1_RcIter = ms1.upper_bound( 30 );

   // If no match is found for the key, end( ) is returned
   if ( ms1_RcIter == ms1.end( ) )
      cout << "The multiset ms1 doesn't have an element "
              << "with a key greater than 30." << endl;
   else
      cout << "The element of multiset ms1 with a key > 40 is: "
           << *ms1_RcIter << "." << endl;

   // The element at a specific location in the multiset can be
   // found using a dereferenced iterator addressing the location
   ms1_AcIter = ms1.begin( );
   ms1_RcIter = ms1.upper_bound( *ms1_AcIter );
   cout << "The first element of ms1 with a key greater than"
        << endl << "that of the initial element of ms1 is: "
        << *ms1_RcIter << "." << endl;
}
The first element of multiset ms1 with a key greater than 20 is: 30.
The multiset ms1 doesn't have an element with a key greater than 30.
The first element of ms1 with a key greater than
that of the initial element of ms1 is: 20.

multiset::value_comp

multiset에서 요소 값의 정렬에 사용되는 비교 개체의 복사본을 검색합니다.

value_compare value_comp() const;

Return Value

템플릿 매개 변수Comparemultiset 요소를 정렬하는 데 사용하는 함수 개체를 반환합니다.

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

설명

저장된 개체는 구성원 함수

bool operator( const Key&_xVal, const Key&_yVal);

앞에 오면 _xVal true를 반환하고 정렬 순서와 같지 _yVal 않습니다.

value_compare 둘 다 key_compare 템플릿 매개 변수Compare의 동의어입니다. 두 형식 모두 클래스 집합 및 multiset클래스 맵과의 호환성을 위해 제공되고, 클래스 맵과 호환되는 위치 및 multimap클래스가 서로 다른 위치에 대해 제공됩니다.

예시

// multiset_value_comp.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;

   multiset <int, less<int> > ms1;
   multiset <int, less<int> >::value_compare vc1 = ms1.value_comp( );
   bool result1 = vc1( 2, 3 );
   if( result1 == true )
   {
      cout << "vc1( 2,3 ) returns value of true, "
           << "where vc1 is the function object of ms1."
           << endl;
   }
   else
   {
      cout << "vc1( 2,3 ) returns value of false, "
           << "where vc1 is the function object of ms1."
           << endl;
   }

   set <int, greater<int> > ms2;
   set<int, greater<int> >::value_compare vc2 = ms2.value_comp( );
   bool result2 = vc2( 2, 3 );
   if( result2 == true )
   {
      cout << "vc2( 2,3 ) returns value of true, "
           << "where vc2 is the function object of ms2."
           << endl;
   }
   else
   {
      cout << "vc2( 2,3 ) returns value of false, "
           << "where vc2 is the function object of ms2."
           << endl;
   }
}
vc1( 2,3 ) returns value of true, where vc1 is the function object of ms1.
vc2( 2,3 ) returns value of false, where vc2 is the function object of ms2.

multiset::value_compare

두 정렬 키를 비교하여 상대적 순서를 확인할 수 있는 multiset함수 개체를 제공하는 형식입니다.

typedef key_compare value_compare;

설명

value_compare은 템플릿 매개 변수 Compare의 동의어입니다.

value_compare 둘 다 key_compare 템플릿 매개 변수Compare의 동의어입니다. 두 형식 모두 클래스 집합 및 multiset클래스 맵과의 호환성을 위해 제공되고, 클래스 맵과 호환되는 위치 및 multimap클래스가 서로 다른 위치에 대해 제공됩니다.

Compare에 대한 자세한 내용은 multiset 클래스 항목의 설명 섹션을 참조하세요.

예시

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

multiset::value_type

요소로 저장된 개체를 해당 용량의 값으로 multiset 설명하는 형식입니다.

typedef Key value_type;

설명

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

value_type 둘 다 key_type 템플릿 매개 변수Key의 동의어입니다. 클래스 맵 및 multimap과의 호환성을 위해 클래스 집합 및 다중 집합에 대해 두 형식이 모두 제공됩니다.

Key에 대한 자세한 내용은 이 항목의 설명 섹션을 참조하세요.

예시

// multiset_value_type.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int> ms1;
   multiset <int>::iterator ms1_Iter;

   multiset <int> :: value_type svt_Int;   // Declare value_type
   svt_Int = 10;             // Initialize value_type

   multiset <int> :: key_type skt_Int;   // Declare key_type
   skt_Int = 20;             // Initialize key_type

   ms1.insert( svt_Int );         // Insert value into s1
   ms1.insert( skt_Int );         // Insert key into s1

   // a multiset accepts key_types or value_types as elements
   cout << "The multiset has elements:";
   for ( ms1_Iter = ms1.begin( ) ; ms1_Iter != ms1.end( ); ms1_Iter++ )
      cout << " " << *ms1_Iter;
   cout << "." << endl;
}
The multiset has elements: 10 20.

참고 항목

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