Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


C++ Multiset

A multiset is an associative container that stores sorted elements. Unlike set, in a multiset multiple elements can have same values and the value of the element is itself the key, of type T. In a multiset, values can be inserted or deleted but can not be altered.

Multisets are typically implemented as Binary Search Tree.

Syntax

template < class T,                        // key_type/value_type
           class Compare = less<T>,        // key_compare/value_compare
           class Alloc = allocator<T> >    // allocator_type
           > class multiset;

Parameters

T Type of the elements stored in the container.
Compare A binary predicate that takes two elements of multiset as arguments and returns a bool. Elements are sorted by using this function.
Alloc Type of the allocator object used to define the storage allocation model, default:allocator.

Member Types

Member typesDefinition
key_type T (First template parameter)
value_type T (First template parameter)
key_compare Compare (Second template parameter), default: less<key_type>
value_compare Compare (Second template parameter), default: less<value_type>
allocator_type Alloc (Third template parameter), default: allocator<value_type>
reference value_type&
const_reference const value_type&
pointer Alloc::pointer, default: value_type*
const_pointer Alloc::const_pointer, default: value_type*
iterator a bidirectional iterator to value_type
const_iterator a bidirectional iterator to const value_type
reverse_iterator reverse_iterator <iterator>
const_reverse_iterator reverse_iterator <const_iterator>
difference_type ptrdiff_t
size_type size_t

C++ - Multiset Functions

The C++ multiset container has a number of member functions which are listed below:

FunctionsDescription
operator=() Assign content to a multiset.

Capacity

FunctionsDescription
empty() Checks whether the multiset is empty or not.
size() Returns the length of the multiset in terms of bytes.
max_size() Returns the maximum length of the multiset.

Iterators

FunctionsDescription
begin() Returns iterator pointing to the first element of the multiset.
end() Returns iterator pointing to the past-the-last element of the multiset.
rbegin() Returns reverse iterator to the last element of the multiset.
rend() Returns reverse iterator to the element preceding the first element of the multiset.
cbegin() Returns const_iterator pointing to the first element of the multiset.
cend() Returns const_iterator pointing to the past-the-last element of the multiset.
crbegin() Returns const_reverse_iterator to the last element of the multiset.
crend() Returns const_reverse_iterator to the element preceding the first element of the multiset.

Modifiers

FunctionsDescription
clear() Clears all elements of the multiset.
erase() Deletes either a single element or range of elements from a multiset.
insert() Insert elements in the multiset.
swap() Exchanges elements between two Multiset.
emplace() Constructs and inserts a new element in the multiset.
emplace_hint() Constructs and inserts a new element with hint in the multiset.

Observers

FunctionsDescription
key_comp() Returns a copy of the comparison object used by the container.
value_comp() Returns a copy of the comparison object used by the container.

Operations

FunctionsDescription
find() Searches the container for a value and returns the iterator to it if found, else returns the iterator to multiset::end.
count() Returns the number of occurrences of an element in the multiset container.
lower_bound() Returns an iterator pointing to the first element in the multiset container which is not considered to go before specified value.
upper_bound() Returns an iterator pointing to the first element in the multiset container which is considered to go after specified value.
equal_range() Returns the range of elements in the multiset container that matches with given value.

Non-member function overloads

FunctionsDescription
swap() Exchanges elements between two Multiset.

Allocator

FunctionsDescription
get_allocator() Return a copy of allocator object associated with the multiset.