This class template implements a value‐semantic container type holding an ordered sequence of key‐value pairs having possibly duplicate keys that provide a mapping from keys (of the template parameter type, KEY) to their associated values (of another template parameter type, VALUE).

Synopsis

Declared in <bslstl_multimap.h>

template<
    class KEY,
    class VALUE,
    class COMPARATOR = std::less<KEY>,
    class ALLOCATOR = allocator<pair<KEY const, VALUE>>>
class multimap;

Description

This class: * supports a complete set of value‐semantic operations

  • except for BDEX serialization * is exception‐neutral * is alias‐safe * is const thread‐safe For terminology see {`bsldoc_glossary`}.

Types

Name

Description

value_compare

This nested class defines a mechanism for comparing two objects of value_type by adapting an object of (template parameter) type COMPARATOR, which compares two objects of (template parameter) type KEY . Note that this class exactly matches its definition in the C++11 standard [23.4.4.1]; otherwise, we would have implemented it as a separate component‐local class.

Type Aliases

Name

Description

allocator_type

Allocator type for this container.

const_iterator

Constant bidirectional iterator over multimap elements.

const_pointer

Constant pointer type for elements in this container.

const_reference

Constant reference type for elements.

const_reverse_iterator

Const reverse iterator type for traversing the multimap in reverse order.

difference_type

Signed integer type measuring iterator distance.

iterator

Bidirectional iterator over multimap elements.

key_compare

Comparator type for ordering keys.

key_type

Key type for this multimap.

mapped_type

Mapped value type for this multimap.

pointer

Pointer type for elements in this container.

reference

Modifiable reference type for elements.

reverse_iterator

Reverse iterator type for traversing the multimap in reverse order.

size_type

Unsigned integer type measuring multimap size.

value_type

Element type stored in this multimap.

Member Functions

Name

Description

multimap [constructor]

Constructors

~multimap [destructor]

Destroy this object.

operator=

Assignment operators

begin

begin overloads

cbegin

Return an iterator providing non‐modifiable access to the first value_type object in the ordered sequence of value_type objects maintained by this multimap, or the cend iterator if this multimap is empty.

cend

Return an iterator providing non‐modifiable access to the past‐the‐end element in the ordered sequence of value_type objects maintained by this multimap.

clear

Remove all entries from this multimap. Note that the multimap is empty after this call, but allocated memory may be retained for future use.

contains

Return true if this multimap contains an element whose key is equivalent to the specified key.

count

Return the number of value_type objects within this multimap whose keys are equivalent to the specified key.

crbegin

Return a reverse iterator providing non‐modifiable access to the last value_type object in the ordered sequence of value_type objects maintained by this multimap, or rend if this multimap is empty.

crend

Return a reverse iterator providing non‐modifiable access to the prior‐to‐the‐beginning element in the ordered sequence of value_type objects maintained by this multimap.

emplace

Insert into this multimap a newly‐created value_type object, constructed by forwarding get_allocator() (if required) and the specified (variable number of) args to the corresponding constructor of value_type. Return an iterator referring to the newly created and inserted object in this multimap. This method requires that the (template parameter) types KEY and VALUE both be emplace‐constructible from args (see {Requirements on KEY and VALUE}).

emplace_hint

Insert into this multimap a newly‐created value_type object, constructed by forwarding get_allocator() (if required) and the specified (variable number of) args to the corresponding constructor of value_type (in amortized constant time if the specified hint is a valid immediate successor to the value_type object constructed from args). Return an iterator referring to the newly created and inserted object in this multimap. If hint is not a valid immediate successor to the value_type object implied by args, this operation has O[log(N)] complexity where N is the size of this multimap. This method requires that the (template parameter) types KEY and VALUE both be emplace‐constructible from args (see {Requirements on KEY and VALUE}). The behavior is undefined unless hint is an iterator in the range [begin() .. end()] (both endpoints included).

empty

Return true if this multimap contains no elements, and false otherwise.

end

end overloads

equal_range

equal_range overloads

erase

erase overloads

find

find overloads

get_allocator

Return (a copy of) the allocator used for memory allocation by this multimap.

insert

insert overloads

insert_range

Insert into this multimap the value of each value_type object in the specified range. The (template parameter) type RANGE must meet the requirements of the C++20 standard [ranges]providing access to values of a type convertible to value_type, and value_type must be emplace‐constructible from *i into this multimap, where i is a dereferenceable iterator obtained from range (see {Requirements on KEY and VALUE}). The behavior is undefined if range overlaps this multimap.

key_comp

Return the key‐comparison functor (or function pointer) used by this multimap; if a comparator was supplied at construction, return its value, otherwise return a default constructed key_compare object. Note that this comparator compares objects of type KEY, which is the key part of the value_type objects contained in this multimap.

lower_bound

lower_bound overloads

max_size

Return a theoretical upper bound on the largest number of elements that this multimap could possibly hold. Note that there is no guarantee that the multimap can successfully grow to the returned size, or even close to that size without running out of resources.

rbegin

rbegin overloads

rend

rend overloads

size

Return the number of elements in this multimap.

swap

Exchange the value and comparator of this object with those of the specified other object; also exchange the allocator of this object with that of other if the (template parameter) type ALLOCATOR has the propagate_on_container_swap trait, and do not modify either allocator otherwise. This method provides the no‐throw exception‐safety guarantee if and only if the (template parameter) type COMPARATOR provides a no‐throw swap operation, and provides the basic exception‐safety guarantee otherwise; if an exception is thrown, both objects are left in valid but unspecified states. This operation has O[1] complexity if either this object was created with the same allocator as other or ALLOCATOR has the propagate_on_container_swap trait; otherwise, it has O[n + m] complexity, where n and m are the number of elements in this object and other, respectively. Note that this method's support for swapping objects created with different allocators when ALLOCATOR does not have the propagate_on_container_swap trait is a departure from the C++ Standard.

upper_bound

upper_bound overloads

value_comp

Return a functor for comparing two value_type objects by comparing their respective keys using key_comp(). Note that this comparator compares objects of type value_type (i.e., 'pair<const KEY, VALUE>').

Deduction Guides

Name

Description

multimap<KEY, VALUE>

Deduce the template parameters KEY and VALUE from the value_type of the initializer_list supplied to the constructor of multimap. This deduction guide does not participate unless the supplied allocator is convertible to bsl::allocator<bsl::pair<const KEY, VALUE>>.

multimap<KEY, VALUE>

Deduce the template parameters KEY and VALUE from the value_type of the iterators supplied to the constructor of multimap. This deduction guide does not participate unless the supplied allocator is convertible to bsl::allocator<bsl::pair<const KEY, VALUE>>.

multimap<KEY, VALUE, COMPARATOR>

Deduce the template parameters KEY and VALUE from the value_type of the initializer_list supplied to the constructor of multimap. Deduce the template parameter COMPARATOR from the other parameters passed to the constructor. This deduction guide does not participate unless the supplied allocator is convertible to bsl::allocator<bsl::pair<const KEY, VALUE>>.

multimap<KEY, VALUE, COMPARATOR>

Deduce the template parameters KEY and VALUE from the value_type of the iterators supplied to the constructor of multimap. Deduce the template parameter COMPARATOR from the other parameter passed to the constructor. This deduction guide does not participate unless the supplied allocator is convertible to bsl::allocator<bsl::pair<const KEY, VALUE>>.

multimap<KEY, VALUE, COMPARATOR, ALLOCATOR>

Deduce the template parameters KEY and VALUE from the value_type of the initializer_list supplied to the constructor of multimap. Deduce the template parameters COMPARATOR and ALLOCATOR from the other parameters passed to the constructor. This deduction guide does not participate unless the supplied allocator meets the requirements of a standard allocator.

multimap<KEY, VALUE, COMPARATOR, ALLOCATOR>

Deduce the template parameters KEY and VALUE from the value_type of the iterators supplied to the constructor of multimap. Deduce the template parameters COMPARATOR and ALLOCATOR from the other parameters passed to the constructor. This deduction guide does not participate unless the supplied allocator meets the requirements of a standard allocator.

multimap<KEY, VALUE, std::less<KEY>, ALLOCATOR>

Deduce the template parameters KEY and VALUE from the value_type of the initializer_list supplied to the constructor of multimap. Deduce the template parameter ALLOCATOR from the other parameter passed to the constructor. This deduction guide does not participate unless the supplied allocator meets the requirements of a standard allocator.

multimap<KEY, VALUE, std::less<KEY>, ALLOCATOR>

Deduce the template parameters KEY and VALUE from the value_type of the iterators supplied to the constructor of multimap. This deduction guide does not participate unless the supplied allocator meets the requirements of a standard allocator.

Non-Member Functions

Name

Description

erase_if

Erase all the elements in the specified multimap m that satisfy the specified predicate predicate. Return the number of elements erased.

operator<=>

Perform a lexicographic three‐way comparison of the specified lhs and the specified rhs maps by using the comparison operators of bsl::pair<const KEY, VALUE> on each element; return the result of that comparison.

operator==

Return true if the specified lhs and rhs objects have the same value, and false otherwise. Two multimap objects lhs and rhs have the same value if they have the same number of key‐value pairs, and each element in the ordered sequence of key‐value pairs of lhs has the same value as the corresponding element in the ordered sequence of key‐value pairs of rhs. This method requires that the (template parameter) types KEY and VALUE both be equality‐comparable (see {Requirements on KEY and VALUE}).

swap

Exchange the value and comparator of the specified a object with those of the specified b object; also exchange the allocator of a with that of b if the (template parameter) type ALLOCATOR has the propagate_on_container_swap trait, and do not modify either allocator otherwise. This function provides the no‐throw exception‐safety guarantee if and only if the (template parameter) type COMPARATOR provides a no‐throw swap operation, and provides the basic exception‐safety guarantee otherwise; if an exception is thrown, both objects are left in valid but unspecified states. This operation has O[1] complexity if either a was created with the same allocator as b or ALLOCATOR has the propagate_on_container_swap trait; otherwise, it has O[n + m] complexity, where n and m are the number of elements in a and b, respectively. Note that this function's support for swapping objects created with different allocators when ALLOCATOR does not have the propagate_on_container_swap trait is a departure from the C++ Standard.

Created with MrDocs