CopperSpice API  1.7.2
QMultiMap< Key, Val, C > Class Template Reference

Template class which provides a sorted container of keys and values, allows duplicate keys. More...

Classes

class  const_iterator
 STL style const iterator for QMultiMap More...
 
class  iterator
 STL style iterator for QMultiMap More...
 

Public Typedefs

using allocator_type = typename std::multimap< Key, Val, C >::allocator_type
 
using const_pointer = const Val *
 
using const_reference = const Val &
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 
using difference_type = typename std::multimap< Key, Val, C >::difference_type
 
using key_compare = typename std::multimap< Key, Val, C >::key_compare
 
using key_type = typename std::multimap< Key, Val, C >::key_type
 
using mapped_type = typename std::multimap< Key, Val, C >::mapped_type
 
using pointer = Val *
 
using reference = Val &
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using size_type = typename std::multimap< Key, Val, C >::difference_type
 
using value_type = Val
 

Public Methods

 QMultiMap () = default
 
 QMultiMap (C compare)
 
 QMultiMap (const QMultiMap< Key, Val, C > &other) = default
 
 QMultiMap (const std::multimap< Key, Val, C > &other)
 
template<typename Input_Iterator >
 QMultiMap (Input_Iterator first, Input_Iterator last, const C &compare=C ())
 
 QMultiMap (QMultiMap< Key, Val, C > &&other) = default
 
 QMultiMap (std::initializer_list< std::pair< const Key, Val >> list, const C &compare=C ())
 
 ~QMultiMap () = default
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
void clear ()
 
const_iterator constBegin () const
 
const_iterator constEnd () const
 
const_iterator constFind (const Key &key) const
 
const_iterator constFind (const Key &key, const Val &value) const
 
bool contains (const Key &key) const
 
bool contains (const Key &key, const Val &value) const
 
size_type count () const
 
size_type count (const Key &key) const
 
size_type count (const Key &key, const Val &value) const
 
const_reverse_iterator crbegin () const
 
const_reverse_iterator crend () const
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
QPair< iterator, iteratorequal_range (const Key &key)
 
QPair< const_iterator, const_iteratorequal_range (const Key &key) const
 
iterator erase (const_iterator iter)
 
iterator find (const Key &key)
 
const_iterator find (const Key &key) const
 
iterator find (const Key &key, const Val &value)
 
const_iterator find (const Key &key, const Val &value) const
 
Val & first ()
 
const Val & first () const
 
const Key & firstKey () const
 
iterator insert (const Key &key, const Val &value)
 
iterator insert (const std::pair< const Key, Val > &data)
 
iterator insert (const_iterator hint, const Key &key, const Val &value)
 
iterator insertMulti (const Key &key, const Val &value)
 
iterator insertMulti (const_iterator hint, const Key &key, const Val &value)
 
bool isEmpty () const
 
const Key key (const Val &value, const Key &defaultKey=Key ()) const
 
QList< Key > keys () const
 
QList< Key > keys (const Val &value) const
 
Val & last ()
 
const Val & last () const
 
const Key & lastKey () const
 
iterator lowerBound (const Key &key)
 
const_iterator lowerBound (const Key &key) const
 
bool operator!= (const QMultiMap< Key, Val, C > &other) const
 
QMultiMap operator+ (const QMultiMap &other) const
 
QMultiMap & operator+= (const QMultiMap &other)
 
QMultiMap< Key, Val, C > & operator= (const QMultiMap< Key, Val, C > &other) = default
 
QMultiMap< Key, Val, C > & operator= (QMultiMap< Key, Val, C > &&other) = default
 
bool operator== (const QMultiMap< Key, Val, C > &other) const
 
Val & operator[] (const Key &key)
 
const Val operator[] (const Key &key) const
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const
 
size_type remove (const Key &key)
 
size_type remove (const Key &key, const Val &value)
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 
iterator replace (const Key &key, const Val &value)
 
size_type size () const
 
void swap (QMultiMap< Key, Val, C > &other)
 
Val take (const Key &key)
 
std::map< Key, Val, C > toStdMap () const
 
QList< Key > uniqueKeys () const
 
QMultiMap< Key, Val, C > & unite (const QMultiMap< Key, Val, C > &other)
 
iterator upperBound (const Key &key)
 
const_iterator upperBound (const Key &key) const
 
const Val value (const Key &key) const
 
const Val value (const Key &key, const Val &defaultValue) const
 
QList< Val > values () const
 
QList< Val > values (const Key &key) const
 

Related Functions

These are not member functions

QDataStreamoperator<< (QDataStream &out, const QMultiMap< Key, Val, C > &map)
 
QDataStreamoperator>> (QDataStream &in, QMultiMap< Key, Val, C > &map)
 

Detailed Description

template<typename Key, typename Val, typename C>
class QMultiMap< Key, Val, C >

The QMultiMap class is a template class which provides a sorted container of keys and values, allowing duplicate keys. This container stores the key and value as a pair.

For an overview and comparison of all containers, refer to the documentation for Container Classes. Refer to the section on Time Complexity for a discussion about which operations will be relatively faster or slower for a given container with a size of n.

Refer to the QMap documentation for more information about the following topics.

  • Accessing Elements
  • Iterators
  • Using a class as a Key
  • Override the Sort Order ( third template parameter )

Basic Operations

The following examples shows how to create and add elements using a duplicate key.

map1.insert("plenty", 100);
map1.insert("plenty", 2000); // map1.size() == 2
map2.insert("plenty", 5000); // map2.size() == 1
map3 = map1 + map2; // map3.size() == 3

To retrieve all the values for a given key call values(const Key &key) which will return a QList<T>.

QList<int> values = map.values("plenty");
for (int i = 0; i < values.size(); ++i) {
cout << values.at(i) << endl;
}

The items which have duplicate keys are available from most recently to least recently inserted. A more efficient version of the code shown above is to call find() to retrieve an STL style iterator to the first item with a given key, then continue to iterate while the key remains the same.

QMultiMap<QString, int>::iterator iter = map.find("plenty");
while (iter != map.end() && iter.key() == "plenty") {
cout << iter.value() << endl;
++iter;
}

Constraints on type T

The QMultiMap<Key, Val> should be Default Constructible and Copy Constructible to work with all methods of this class. Data types like QObject are not copy constructible and therefore should never be stored in a container. You can however use a pointer to a QObject or any subclass as the type T.

The QMultiMap key type must provide operator<(). QMultiMap uses the comparison operator to sort. Two keys x and y are equal if "x is not less than y" and "y is not less than x".

See also
QFlatMap, QMap, QSet

Member Typedef Documentation

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::allocator_type

Typedef for allocator used by the container.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::const_pointer

Typedef for const Val *.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::const_reference

Typedef for const Val &.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::const_reverse_iterator

Typedef for an STL style const reverse iterator.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::difference_type

Typedef for integral type used to represent the distance between two elements.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::key_compare

Typedef for the key lessthan comparison object type.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::key_type

Typedef for Key.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::mapped_type

Typedef for Val.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::pointer

Typedef for Val *.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::reference

Typedef for Val &.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::reverse_iterator

Typedef for an STL style reverse iterator.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::size_type

Typedef for a signed integer of the appropriate size for your platform.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::value_type

Typedef for Val.

Constructor & Destructor Documentation

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::QMultiMap ( )
default

Constructs an empty QMultiMap.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::QMultiMap ( const QMultiMap< Key, Val, C > &  other)
default

Copy constructs a new QMultiMap from other.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::QMultiMap ( QMultiMap< Key, Val, C > &&  other)
default

Move constructs a new QMultiMap from other.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::QMultiMap ( std::initializer_list< std::pair< const Key, Val >>  list,
const C &  compare = C() 
)
inline

Constructs a multimap with a copy of each of the elements in the initializer list.

If the function object compare is passed it will be called when sorting keys in the container. Refer to Overriding Sort Order for more information about this template parameter.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::QMultiMap ( compare)
inlineexplicit

Constructs an empty multimap using the function object compare. Refer to Overriding Sort Order for more information about this parameter.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::QMultiMap ( const std::multimap< Key, Val, C > &  other)
inlineexplicit

Constructs a copy of other.

See also
toStdMap()
template<typename Key , typename Val , typename C >
template<typename Input_Iterator >
QMultiMap< Key, Val, C >::QMultiMap ( Input_Iterator  first,
Input_Iterator  last,
const C &  compare = C() 
)
inline

Constructs a multimap containing copies of the elements between first and last.

If the function object compare is passed it will be called when sorting keys in the container. Refer to Overriding Sort Order for more information about this template parameter.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::~QMultiMap ( )
default

Destroys the multimap.

Method Documentation

template<typename Key , typename Val , typename C >
iterator QMultiMap< Key, Val, C >::begin ( )
inline

Returns an STL style iterator pointing to the first item in the multimap.

See also
constBegin(), end()
template<typename Key , typename Val , typename C >
const_iterator QMultiMap< Key, Val, C >::begin ( ) const
inline

Returns a const STL style iterator pointing to the first item in the multimap.

template<typename Key , typename Val , typename C >
const_iterator QMultiMap< Key, Val, C >::cbegin ( ) const
inline

Returns a const STL style iterator pointing to the first item in the multimap.

See also
begin(), cend()
template<typename Key , typename Val , typename C >
const_iterator QMultiMap< Key, Val, C >::cend ( ) const
inline

Returns a const STL style iterator pointing to the imaginary item after the last item in the multimap.

See also
cbegin(), end()
template<typename Key , typename Val , typename C >
void QMultiMap< Key, Val, C >::clear ( )
inline

Removes all items from the multimap.

See also
remove()
template<typename Key , typename Val , typename C >
const_iterator QMultiMap< Key, Val, C >::constBegin ( ) const
inline

Returns a const STL style iterator pointing to the first item in the multimap.

See also
begin(), constEnd()
template<typename Key , typename Val , typename C >
const_iterator QMultiMap< Key, Val, C >::constEnd ( ) const
inline

Returns a const STL style iterator pointing to the imaginary item after the last item in the multimap.

See also
constBegin(), end()
template<typename Key , typename Val , typename C >
const_iterator QMultiMap< Key, Val, C >::constFind ( const Key &  key) const
inline

Returns an const iterator pointing to the item with key in the multimap. If the multimap contains no item with key this method returns constEnd().

See also
find()
template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::const_iterator QMultiMap< Key, Val, C >::constFind ( const Key &  key,
const Val &  value 
) const
inline

Returns an iterator pointing to the item with key and the value value in the multimap. If the multimap contains no such item the method returns constEnd().

See also
find()
template<typename Key , typename Val , typename C >
bool QMultiMap< Key, Val, C >::contains ( const Key &  key) const
inline

Returns true if the multimap contains an item with given key, otherwise it returns false.

See also
count()
template<class Key , class Val , class C >
bool QMultiMap< Key, Val, C >::contains ( const Key &  key,
const Val &  value 
) const

Returns true if the multimap contains an item with the given key and value, otherwise it returns false.

See also
contains()
template<typename Key , typename Val , typename C >
size_type QMultiMap< Key, Val, C >::count ( ) const
inline

Equivalent to calling size().

template<typename Key , typename Val , typename C >
size_type QMultiMap< Key, Val, C >::count ( const Key &  key) const
inline

Returns the number of items associated with the given key.

See also
contains(), insertMulti()
template<class Key , class Val , class C >
QMultiMap< Key, Val, C >::size_type QMultiMap< Key, Val, C >::count ( const Key &  key,
const Val &  value 
) const

Returns the number of items with the given key and value.

template<typename Key , typename Val , typename C >
const_reverse_iterator QMultiMap< Key, Val, C >::crbegin ( ) const
inline

Returns a const STL-style reverse iterator pointing to the first item in the multimap, in reverse order.

See also
begin(), rbegin(), rend()
template<typename Key , typename Val , typename C >
const_reverse_iterator QMultiMap< Key, Val, C >::crend ( ) const
inline

Returns a const STL style reverse iterator pointing to one past the last item in the multimap, in reverse order.

See also
end(), rend(), rbegin()
template<typename Key , typename Val , typename C >
bool QMultiMap< Key, Val, C >::empty ( ) const
inline

Equivalent to calling isEmpty().

template<typename Key , typename Val , typename C >
iterator QMultiMap< Key, Val, C >::end ( )
inline

Returns an STL style iterator pointing to the imaginary item after the last item in the multimap.

See also
begin(), constEnd()
template<typename Key , typename Val , typename C >
const_iterator QMultiMap< Key, Val, C >::end ( ) const
inline

Returns a const STL style iterator pointing to the imaginary item after the last item in the multimap.

template<typename Key , typename Val , typename C >
QPair< iterator, iterator > QMultiMap< Key, Val, C >::equal_range ( const Key &  key)
inline

Returns a pair of iterators corresponding to the range of items [first, second) which have the given key. If the range is empty then both iterators will be equal to end().

template<typename Key , typename Val , typename C >
QPair< const_iterator, const_iterator > QMultiMap< Key, Val, C >::equal_range ( const Key &  key) const
inline

Returns a pair of iterators corresponding to the range of items [first, second) which have the given key. If the range is empty then both iterators will be equal to end().

template<typename Key , typename Val , typename C >
iterator QMultiMap< Key, Val, C >::erase ( const_iterator  iter)
inline

Removes the (key, value) pair pointed to by the iterator iter from the multimap and returns an iterator to the next item in the multimap.

This method assumes the iterator is valid and refers to an element in the multimap. It will not check if iter points past the end of the multimap or is equal to the end() iterator.

See also
remove()
template<typename Key , typename Val , typename C >
iterator QMultiMap< Key, Val, C >::find ( const Key &  key)
inline

Returns an iterator pointing to the item with key in the multimap. If the multimap contains no item with key, the method returns end().

See also
constFind(), value(), values(), lowerBound(), upperBound()
template<typename Key , typename Val , typename C >
const_iterator QMultiMap< Key, Val, C >::find ( const Key &  key) const
inline

This is an overloaded method.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::iterator QMultiMap< Key, Val, C >::find ( const Key &  key,
const Val &  value 
)
inline

Returns an iterator pointing to the item with key and value in the multimap. If the multimap contains no such item, the method returns end().

If the multimap contains multiple items with key this method returns an iterator that points to the most recently inserted value.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::const_iterator QMultiMap< Key, Val, C >::find ( const Key &  key,
const Val &  value 
) const
inline

Returns a const iterator pointing to the item with the given key and value in the multimap. If the multimap contains no such item, the method returns end().

If the multimap contains multiple items with the specified key this method returns a const iterator that points to the most recently inserted value.

template<typename Key , typename Val , typename C >
Val & QMultiMap< Key, Val, C >::first ( )
inline

Returns a reference to the first value in the multimap. This method assumes the multimap is not empty.

template<typename Key , typename Val , typename C >
const Val & QMultiMap< Key, Val, C >::first ( ) const
inline

Returns a const reference to the first value in the multimap. This method assumes the multimap is not empty.

template<typename Key , typename Val , typename C >
const Key & QMultiMap< Key, Val, C >::firstKey ( ) const
inline

Returns a const reference to the first key in the multimap. This method assumes the multimap is not empty.

template<typename Key , typename Val , typename C >
QMultiMap::iterator QMultiMap< Key, Val, C >::insert ( const Key &  key,
const Val &  value 
)
inline

Inserts a new item with the given key and a value. If there is already an item with the same key in the multimap, this method will create a new item.

This behavior is different from replace() which overwrites the value of an existing item.

See also
replace()
template<typename Key , typename Val , typename C >
iterator QMultiMap< Key, Val, C >::insert ( const std::pair< const Key, Val > &  data)
inline

Inserts a new item with key and value from data, which is an std::pair. If there is already an item with the same key in the multimap, this method will create a new item.

This behavior is different from replace() which overwrites the value of an existing item.

template<typename Key , typename Val , typename C >
iterator QMultiMap< Key, Val, C >::insert ( const_iterator  hint,
const Key &  key,
const Val &  value 
)
inline

Inserts a new item with the given key and value using hint as a suggestion about where to do the insert. If there is already an item with the same key in the multimap, this method will create a new item.

See also
insertMulti()
template<typename Key , typename Val , typename C >
iterator QMultiMap< Key, Val, C >::insertMulti ( const Key &  key,
const Val &  value 
)
inline

Inserts a new item with the given key and value. If there is already an item with the same key, a new one will still be added.

See also
insert(), values()
template<typename Key , typename Val , typename C >
iterator QMultiMap< Key, Val, C >::insertMulti ( const_iterator  hint,
const Key &  key,
const Val &  value 
)
inline

Inserts a new item with the given key and value using hint as a suggestion about where to do the insert. If there is already an item with the same key, a new one will still be added.

See also
insertMulti()
template<typename Key , typename Val , typename C >
bool QMultiMap< Key, Val, C >::isEmpty ( ) const
inline

Returns true if the multimap contains no items, otherwise it returns false.

See also
size()
template<class Key , class Val , class C >
const Key QMultiMap< Key, Val, C >::key ( const Val &  value,
const Key &  defaultKey = Key() 
) const

Returns the first key with value. If the multimap contains no item with value then defaultKey is returned.

This method can be slow (linear time), because the internal data structure is optimized for fast lookup by key, not by value.

See also
value(), keys()
template<typename Key , typename Val , typename C >
QList< Key > QMultiMap< Key, Val, C >::keys ( ) const

Returns a list containing all the keys in the multimap in ascending order. To obtain a list of unique keys, where each key from the multimap only occurs once use uniqueKeys().

The order is guaranteed to be the same as returned by values().

Keys which occur multiple times in the multimap (because items were inserted with insertMulti() or unite()) will also occur multiple times in this list.

See also
uniqueKeys(), values(), key()
template<class Key , class Val , class C >
QList< Key > QMultiMap< Key, Val, C >::keys ( const Val &  value) const

Returns a list containing all the keys associated with value value in ascending order.

This method can be slow (linear time), because the internal data structure is optimized for fast lookup by key, not by value.

template<typename Key , typename Val , typename C >
Val & QMultiMap< Key, Val, C >::last ( )
inline

Returns a reference to the last value in the multimap. This method assumes the map is not empty.

template<typename Key , typename Val , typename C >
const Val & QMultiMap< Key, Val, C >::last ( ) const
inline

Returns a const reference to the last value in the multimap. This method assumes the map is not empty.

template<typename Key , typename Val , typename C >
const Key & QMultiMap< Key, Val, C >::lastKey ( ) const
inline

Returns a const reference to the last key in the multimap. This method assumes the map is not empty.

template<typename Key , typename Val , typename C >
iterator QMultiMap< Key, Val, C >::lowerBound ( const Key &  key)
inline

Returns an iterator pointing to the first item with key in the multimap. If the multimap contains no item with key then the method returns an iterator to the nearest item with a greater key.

Example:

map.insert(1, "one");
map.insert(5, "five");
map.insert(10, "ten");
map.lowerBound(0); // returns iterator to (1, "one")
map.lowerBound(1); // returns iterator to (1, "one")
map.lowerBound(2); // returns iterator to (5, "five")
map.lowerBound(10); // returns iterator to (10, "ten")
map.lowerBound(999); // returns end()

If the multimap contains multiple items with the same key then this method will return an iterator which points to the most recently inserted value. The other values are accessible by incrementing the iterator. For example, the following code iterates over all the items with the same key.

while (iter != upperBound) {
cout << iter.value() << endl;
++iter;
}
See also
qLowerBound(), upperBound(), find()
template<typename Key , typename Val , typename C >
const_iterator QMultiMap< Key, Val, C >::lowerBound ( const Key &  key) const
inline

This is an overloaded method.

template<typename Key , typename Val , typename C >
bool QMultiMap< Key, Val, C >::operator!= ( const QMultiMap< Key, Val, C > &  other) const
inline

Returns true if other is not equal to this multimap, otherwise it returns false. Two multimaps are considered equal if they contain the same (key, value) pairs.

This method requires the type T to support operator==().

See also
operator==()
template<typename Key , typename Val , typename C >
QMultiMap QMultiMap< Key, Val, C >::operator+ ( const QMultiMap< Key, Val, C > &  other) const
inline

Returns a multimap that contains all the items in this multimap in addition to all the items in other. If a key is common to both multimaps the resulting multimap will contain the key multiple times.

See also
operator+=()
template<typename Key , typename Val , typename C >
QMultiMap & QMultiMap< Key, Val, C >::operator+= ( const QMultiMap< Key, Val, C > &  other)
inline

Inserts all the items in the other multimap into this map and returns a reference to this multimap.

See also
insert(), operator+()
template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C > & QMultiMap< Key, Val, C >::operator= ( const QMultiMap< Key, Val, C > &  other)
default

Copy assigns from other and returns a reference to this object.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C > & QMultiMap< Key, Val, C >::operator= ( QMultiMap< Key, Val, C > &&  other)
default

Move assigns from other and returns a reference to this object.

template<typename Key , typename Val , typename C >
bool QMultiMap< Key, Val, C >::operator== ( const QMultiMap< Key, Val, C > &  other) const
inline

Returns true if other is equal to this multimap, otherwise it returns false. Two multimaps are considered equal if they contain the same (key, value) pairs.

This method requires the type T to support operator==().

See also
operator!=()
template<typename Key , typename Val , typename C >
Val & QMultiMap< Key, Val, C >::operator[] ( const Key &  key)

Returns a reference to the value for the item with the given key.

If the multimap contains no item with key, a reference to a value initialized object is returned. Refer to default constructed elements for additional information.

See also
insert(), value()
template<typename Key , typename Val , typename C >
const Val QMultiMap< Key, Val, C >::operator[] ( const Key &  key) const

Returns a copy of the value associated with the key.

If the multimap contains no item with key, the method returns a value initialized object. Refer to default constructed elements for additional information.

See also
insert(), value()
template<typename Key , typename Val , typename C >
reverse_iterator QMultiMap< Key, Val, C >::rbegin ( )
inline

This is an overloaded method.

template<typename Key , typename Val , typename C >
const_reverse_iterator QMultiMap< Key, Val, C >::rbegin ( ) const
inline

Returns a STL style reverse iterator pointing to the first item in the multimap, in reverse order.

See also
begin(), crbegin(), rend()
template<typename Key , typename Val , typename C >
size_type QMultiMap< Key, Val, C >::remove ( const Key &  key)
inline

Removes all the items which have the given key. Returns the number of items removed which is usually 1, however this will be 0 if the key is not in the multimap, or greater than 1 if insertMulti() has been used with the key.

See also
clear(), take()
template<class Key , class Val , class C >
QMultiMap< Key, Val, C >::size_type QMultiMap< Key, Val, C >::remove ( const Key &  key,
const Val &  value 
)

Removes all the items which have the given key and value. Returns the number of items removed.

template<typename Key , typename Val , typename C >
reverse_iterator QMultiMap< Key, Val, C >::rend ( )
inline

Returns a STL style reverse iterator pointing to one past the last item in the multimap, in reverse order.

See also
end(), crend(), rbegin()
template<typename Key , typename Val , typename C >
const_reverse_iterator QMultiMap< Key, Val, C >::rend ( ) const
inline

This is an overloaded method.

template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C >::iterator QMultiMap< Key, Val, C >::replace ( const Key &  key,
const Val &  value 
)
inline

Inserts a new item with the given key and value. If there is already an item with the key key, that item's value is replaced with value.

If there are multiple items with the key, the most recently inserted item's value is replaced with value.

See also
insert()
template<typename Key , typename Val , typename C >
size_type QMultiMap< Key, Val, C >::size ( ) const
inline

Returns the number of (key, value) pairs in the multimap.

See also
isEmpty(), count()
template<typename Key , typename Val , typename C >
void QMultiMap< Key, Val, C >::swap ( QMultiMap< Key, Val, C > &  other)
inline

Swaps multimap other with this multimap. This operation is very fast and never fails.

template<typename Key , typename Val , typename C >
Val QMultiMap< Key, Val, C >::take ( const Key &  key)
inline

Removes the item with the given key from the multimap and returns the value which was associated with it. If there are multiple items for key in the multimap, the most recently inserted one is removed and returned.

If the multimap contains no item with key, a value initialized object is returned. Refer to default constructed elements for additional information.

If you do not use the return value remove() is more efficient.

See also
remove()
template<typename Key , typename Val , typename C >
std::map< Key, Val, C > QMultiMap< Key, Val, C >::toStdMap ( ) const

Returns an STL multimap equivalent to this QMultiMap.

template<typename Key , typename Val , typename C >
QList< Key > QMultiMap< Key, Val, C >::uniqueKeys ( ) const

Returns a list containing all the keys in the multimap in ascending order. Keys that occur multiple times in the multimap (because items were inserted with insertMulti(), or unite() was used) occur only once in the returned list.

See also
keys(), values()
template<typename Key , typename Val , typename C >
QMultiMap< Key, Val, C > & QMultiMap< Key, Val, C >::unite ( const QMultiMap< Key, Val, C > &  other)
inline

Inserts all the items in the other multimap into this multimap. If a key is common to both multimaps, the resulting map will contain the key multiple times.

See also
insertMulti()
template<typename Key , typename Val , typename C >
iterator QMultiMap< Key, Val, C >::upperBound ( const Key &  key)
inline

Returns an iterator pointing to the item which immediately follows the last item with key in the multimap. If the map contains no item with key, the method returns an iterator to the nearest item with a greater key.

map.insert(1, "one");
map.insert(5, "five");
map.insert(10, "ten");
map.upperBound(0); // returns iterator to (1, "one")
map.upperBound(1); // returns iterator to (5, "five")
map.upperBound(2); // returns iterator to (5, "five")
map.upperBound(10); // returns end()
map.upperBound(999); // returns end()
See also
qUpperBound(), lowerBound(), find()
template<typename Key , typename Val , typename C >
const_iterator QMultiMap< Key, Val, C >::upperBound ( const Key &  key) const
inline

This is an overloaded method.

template<class Key , class Val , class C >
const Val QMultiMap< Key, Val, C >::value ( const Key &  key) const

Returns the value associated with the given key. If there are multiple items for key in the multimap, the value of the most recently inserted one is returned.

If the multimap contains no item with key, a value initialized object is returned. Refer to default constructed elements for additional information.

See also
key(), values(), contains(), operator[]()
template<class Key , class Val , class C >
const Val QMultiMap< Key, Val, C >::value ( const Key &  key,
const Val &  defaultValue 
) const

Returns the value associated with the key. If the multimap contains no item with key, this method returns the defaultValue.

template<typename Key , typename Val , typename C >
QList< Val > QMultiMap< Key, Val, C >::values ( ) const

Returns a list containing all the values in the multimap, in ascending order of their keys. If a key is associated with multiple values then all of its values will be in the list.

See also
keys(), value()
template<class Key , class Val , class C >
QList< Val > QMultiMap< Key, Val, C >::values ( const Key &  key) const

Returns a list containing all the values associated with key key, from the most recently inserted to the least recently inserted one.

See also
count(), insertMulti()

Friends And Related Function Documentation

QDataStream & operator<< ( QDataStream out,
const QMultiMap< Key, Val, C > &  map 
)
related

Writes the map to stream out. This function requires the key and value types to implement operator<<().

Refer to Serializing Data Types for additional information.

QDataStream & operator>> ( QDataStream in,
QMultiMap< Key, Val, C > &  map 
)
related

Reads a map from stream in into map. This function requires the key and value types to implement operator>>().

Refer to Serializing Data Types for additional information.