CopperSpice API  1.9.1
QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator Class Reference

STL style const iterator for QMultiHash. More...

Public Methods

 const_iterator () = default
 
 const_iterator (iterator other)
 
const Key & key () const
 
bool operator!= (const_iterator other) const
 
const Val & operator* () const
 
const_iterator operator+ (size_type n) const
 
const_iterator & operator++ ()
 
const_iterator operator++ (int)
 
const_iterator & operator+= (size_type n)
 
const_iterator operator- (size_type n) const
 
const_iterator & operator-= (size_type n)
 
const Val * operator-> () const
 
bool operator== (const_iterator other) const
 
const std::pair< const Key, Val > & pair () const
 
const Val & value () const
 

Friends

bool operator!= (iterator iter1, const_iterator iter2)
 
bool operator== (iterator iter1, const_iterator iter2)
 
class QMultiHash< Key, Val, Hash, KeyEqual >
 

Detailed Description

template<typename Key, typename Val, typename Hash, typename KeyEqual>
class QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator

The QMultiHash::const_iterator class provides an STL style const iterator for QMultiHash. QMultiHash features both STL style iterators and Java style iterators.

QMultiHash::const_iterator allows you to iterate over a QMultiHash. If you want to modify the QMultiHash as you iterate over it use QMultiHash::iterator instead.

After construction you must initialize the iterator using a method like QMultiHash::constBegin(), QMultiHash::constEnd(), or QMultiHash::find() before you can start iterating. The following is an example which prints all of the (key, value) pairs in the container.

hash.insert("January", 1);
hash.insert("February", 2);
...
hash.insert("December", 12);
for (auto iter = hash.constBegin(); iter != hash.constEnd(); ++iter) {
cout << iter.key() << ": " << iter.value() << endl;
}

Unlike QMultiMap which orders its items by key, QMultiHash stores its items in an arbitrary order. The only guarantee is items which share the same key will appear consecutively.

See also
QMultiHash::iterator

Constructor & Destructor Documentation

template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator::const_iterator ( )
default

Constructs an uninitialized iterator.

Methods like key(), value(), and operator++() must not be called on an uninitialized iterator. Use operator=() to assign a value to it before using it.

See also
QMultiHash::constBegin(), QMultiHash::constEnd()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator::const_iterator ( iterator  other)
inline

Constructs a copy of other.

Method Documentation

template<typename Key , typename Val , typename Hash , typename KeyEqual >
const Key & QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator::key ( ) const
inline

Returns the current item's key.

See also
value()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
bool QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator::operator!= ( const_iterator  other) const
inline

Returns true if other points to a different item than this iterator, otherwise it returns false.

See also
operator==()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
const Val & QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator::operator* ( ) const
inline

Returns the current item's value. Equivalent to calling value().

See also
key()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
const_iterator QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator::operator+ ( size_type  n) const
inline

Returns an iterator to the item at n positions forward from this iterator. If n is negative the iterator goes backward.

This operation can be slow for large values of n.

See also
operator-()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
const_iterator & QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator::operator++ ( )
inline

The prefix ++ operator (++i) advances the iterator to the next item in the hash and returns an iterator to the new current item.

Calling this method on QMultiHash::end() leads to undefined behavior.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
const_iterator QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator::operator++ ( int  )
inline

The postfix ++ operator (i++) advances the iterator to the next item in the hash and returns an iterator to the previously current item.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
const_iterator & QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator::operator+= ( size_type  n)
inline

Advances the iterator by n items. If n is negative the iterator goes backward.

This operation can be slow for large values of n.

See also
operator-=(), operator+()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
const_iterator QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator::operator- ( size_type  n) const
inline

Returns an iterator to the item at n positions backward from this iterator. If n is negative the iterator goes forward.

This operation can be slow for large values of n.

See also
operator+()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
const_iterator & QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator::operator-= ( size_type  n)
inline

Makes the iterator go back by n items. If n is negative the iterator goes forward.

This operation can be slow for large values of n.

See also
operator+=(), operator-()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
const Val * QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator::operator-> ( ) const
inline

Returns a pointer to the current item's value.

See also
value()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
bool QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator::operator== ( const_iterator  other) const
inline

Returns true if other points to the same item as this iterator, otherwise it returns false.

See also
operator!=()
template<typename Key , typename Val , typename Hash , typename KeyEqual >
const std::pair< const Key, Val > & QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator::pair ( ) const
inline

Returns the current item's key and value as a pair.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
const Val & QMultiHash< Key, Val, Hash, KeyEqual >::const_iterator::value ( ) const
inline

Returns the current item's value.

See also
key(), operator*()

Friends And Related Function Documentation

template<typename Key , typename Val , typename Hash , typename KeyEqual >
bool operator!= ( iterator  iter1,
const_iterator  iter2 
)
friend

Returns true if iter1 points to a different item than iter2, otherwise it returns false.

template<typename Key , typename Val , typename Hash , typename KeyEqual >
bool operator== ( iterator  iter1,
const_iterator  iter2 
)
friend

Returns true if iter1 points to the same item as iter2, otherwise it returns false.