Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
multimap
comparison operators
multimap::multimap
multimap::~multimap
member functions:
multimap::begin
multimap::clear
multimap::count
multimap::empty
multimap::end
multimap::equal_range
multimap::erase
multimap::find
multimap::get_allocator
multimap::insert
multimap::key_comp
multimap::lower_bound
multimap::max_size
multimap::operator=
multimap::rbegin
multimap::rend
multimap::size
multimap::swap
multimap::upper_bound
multimap::value_comp


multimap::multimap

public member function
explicit multimap ( const Compare& comp = Compare(),
               const Allocator& = Allocator() );
template <class InputIterator>
  multimap ( InputIterator first, InputIterator last,
        const Compare& comp = Compare(), const Allocator& = Allocator() );
multimap ( const multimap<Key,T,Compare,Allocator>& x );

Construct multimap

Constructs a multimap container object, initializing its contents depending on the constructor version used:

explicit multimap ( const Compare& comp = Compare(), Allocator& = Allocator() );
Default constructor: constructs an empty multimap object, with no content and a size of zero.
template <class InputIterator> multimap ( InputIterator first, InputIterator last, const Compare& comp= Compare(), const Allocator& = Allocator() );
Iteration constructor: Iterates between first and last, setting a copy of each of the sequence of elements as the content of the container object.
multimap ( const multimap<Key,T,Compare,Allocator>& x );
Copy constructor: The object is initialized to have the same contents and properties as the x multimap object.

Parameters

first, last
Input iterators to the initial and final positions in a sequence. The range used is [first,last), which includes all the elements between first and last, including the element pointed by first but not the element pointed by last.
The function template type can be any type of input iterator.
x
Another multimap object with the same class template parameters (Key, T, Compare and Allocator).
comp
Comparison object to be used for the strict weak ordering.
Compare is the third class template parameter (see class description).
unnamed Allocator parameter
Allocator object to be used instead of constructing a new one.
For class instantiations using their version of the default allocator class template, this parameter is not relevant.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// constructing multimaps
#include <iostream>
#include <map>
using namespace std;
bool fncomp (char lhs, char rhs) {return lhs<rhs;}
struct classcomp {
  bool operator() (const char& lhs, const char& rhs) const
  {return lhs<rhs;}
};
int main ()
{
  multimap<char,int> first;
  first.insert(pair<char,int>('a',10));
  first.insert(pair<char,int>('b',15));
  first.insert(pair<char,int>('b',20));
  first.insert(pair<char,int>('c',25));
  multimap<char,int> second (first.begin(),first.end());
  multimap<char,int> third (second);
  multimap<char,int,classcomp> fourth;                 // class as Compare
  bool(*fn_pt)(char,char) = fncomp;
  multimap<char,int,bool(*)(char,char)> fifth (fn_pt); // function pointer as comp
  return 0;
}


The code does not produce any output, but demonstrates some ways in which a multimap container can be constructed.

Complexity

For the default constructor, constant.
For the iterator constructor, linear in the distance between the iterators (copy constructions) if the elements are already sorted according to comp. For unsorted sequences, linearithmic (N*logN) in that distance (sorting,copy constructions).
For the copy constructor, linear in x's size (copy constructions).

See also