|
explicit multiset ( const Compare& comp = Compare(),
const Allocator& = Allocator() );
template <class InputIterator>
multiset ( InputIterator first, InputIterator last,
const Compare& comp = Compare(), const Allocator& = Allocator() );
multiset ( const multiset<Key,Compare,Allocator>& x );
Construct multiset
Constructs a multiset container object, initializing its contents depending on the constructor version used:
- explicit multiset ( const Compare& comp = Compare(), Allocator& = Allocator() );
- Default constructor: constructs an empty multiset object, with no content and a size of zero.
- template <class InputIterator> multiset ( 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.
- multiset ( const multiset<Key,Compare,Allocator>& x );
- Copy constructor: The object is initialized to have the same contents and properties as the x multiset 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 multiset object with the same class template parameters (Key, Compare and Allocator).
- comp
- Comparison object to be used for the strict weak ordering.
Compare is the second 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
|
// constructing multisets
#include <iostream>
#include <set>
using namespace std;
bool fncomp (int lhs, int rhs) {return lhs<rhs;}
struct classcomp {
bool operator() (const int& lhs, const int& rhs) const
{return lhs<rhs;}
};
int main ()
{
multiset<int> first; // empty multiset of ints
int myints[]= {10,20,30,20,20};
multiset<int> second (myints,myints+5); // pointers used as iterators
multiset<int> third (second); // a copy of second
multiset<int> fourth (second.begin(), second.end()); // iterator ctor.
multiset<int,classcomp> fifth; // class as Compare
bool(*fn_pt)(int,int) = fncomp;
multiset<int,bool(*)(int,int)> sixth (fn_pt); // function pointer as Compare
return 0;
}
|
The code does not produce any output, but demonstrates some ways in which a multiset 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
|