CopperSpice API  1.9.1
QFlatMap< Key, Val, C > Class Template Reference

Template class which uses a vector to implement a sorted map. More...

Classes

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

Public Typedefs

using allocator_type = typename std::vector< std::pair< Key, Val > >::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::vector< std::pair< Key, Val > >::difference_type
 
using key_compare = typename std::map< Key, Val, C >::key_compare
 
using key_type = typename std::map< Key, Val, C >::key_type
 
using mapped_type = typename std::map< Key, Val, C >::mapped_type
 
using pointer = Val *
 
using reference = Val &
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using size_type = typename std::vector< std::pair< Key, Val > >::difference_type
 
using value_type = Val
 

Public Methods

 QFlatMap () = default
 
 QFlatMap (C compare)
 
 QFlatMap (const QFlatMap< Key, Val, C > &other) = default
 
 QFlatMap (const std::map< Key, Val, C > &other)
 
 QFlatMap (const_iterator first, const_iterator last, const C &compare=C ())
 
template<typename Input_Iterator >
 QFlatMap (Input_Iterator first, Input_Iterator last, const C &compare=C ())
 
 QFlatMap (QFlatMap< Key, Val, C > &&other) = default
 
 QFlatMap (std::initializer_list< std::pair< const Key, Val >> list, const C &compare=C ())
 
 ~QFlatMap () = 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
 
bool contains (const Key &key) const
 
size_type count () const
 
size_type count (const Key &key) 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
 
Val & first ()
 
const Val & first () const
 
const Key & firstKey () const
 
iterator insert (const Key &key, const Val &value)
 
iterator insert (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 QFlatMap< Key, Val, C > &other) const
 
QFlatMap< Key, Val, C > & operator= (const QFlatMap< Key, Val, C > &other) = default
 
QFlatMap< Key, Val, C > & operator= (QFlatMap< Key, Val, C > &&other) = default
 
bool operator== (const QFlatMap< 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)
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 
size_type size () const
 
void swap (QFlatMap< Key, Val, C > &other)
 
Val take (const Key &key)
 
QList< Key > uniqueKeys () const
 
QFlatMap< Key, Val, C > & unite (const QFlatMap< Key, Val, C > &other)
 
iterator upperBound (const Key &key)
 
const_iterator upperBound (const Key &key) const
 
const Val value (const Key &key, const Val &defaultValue=Val ()) const
 
QList< Val > values () const
 

Related Functions

These are not member functions

QDataStreamoperator<< (QDataStream &stream, const QFlatMap< Key, Val, C > &flatmap)
 
QDataStreamoperator>> (QDataStream &stream, QFlatMap< Key, Val, C > &flatmap)
 

Detailed Description

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

The QFlatMap class is a template class which uses a vector to implement a sorted map. This container stores the key and value as a pair. This class is useful when the number of elements stored in the container will be relatively small and read access is more common than write access.

  • Elements in a QMap are sorted by key, elements in a QHash are in an arbitrary order/li>
  • QHash provides faster lookups than a QMap or a QFlatMap
  • The key data type for a QHash must implement the operator==() method and a global qHash(key) function
  • The key data type for a QMap must implement the operator<() method
  • Use QFlatMap when your data set is relatively small

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.

Constructors

The following code is a simple example showing how to declare a QFlatMap.

QFlatMap<QString, QString> flatmap; // stores QString key and QString values

Accessing Elements

To insert a (key, value) pair into this flat map use operator[]() or insert(). This following code uses insert to add three (key, value) pairs into the flat map.

flatmap.insert("California", "Sacramento");
flatmap.insert("Oregon", "Salem");
flatmap.insert("Idaho", "Boise");

To look up a value by key in the flat map, use operator[]() or value(). If there is no entry with the specified key in the flat map, a default constructed element will be returned.

QString capitalA = flatmap["Idaho"];
QString capitalB = flatmap.value("Idaho");

To check whether the flat map contains a specific key you can use contains().

QString capital = "Unknown";
if (flatmap.contains("Texas")) {
capital = flatmap.value("Texas");
}

An overloaded value() method can be used which takes a second argument as the default value which will be returned if there is no item with the specified key.

QString capital = flatmap.value("Texas", "Unknown");

Implicit Insert

The following code looks like operator[]() is just doing a look up. There is a side effect of using this operator. If the key is not found then an implicit insert will occur and a (key, value) pair will be added with a default constructed value.

To avoid this problem replace flatmap[i] with flatmap.value(i).

//
for (int i = 0; i < 1000; ++i) {
if (flatmap[i] == okButton) {
cout << "Found button with key " << i << endl;
}
}

Iterators

To navigate through all (key, value) pairs stored in a QFlatMap use an iterator. QFlatMap provides both Java style iterators (QFlatMapIterator and QMutableFlatMapIterator) and STL style iterators (QFlatMap::const_iterator and QFlatMap::iterator).

The following shows how to iterate over a QFlatMap<QString, QString> using a Java style iterator.

while (iter.hasNext()) {
iter.next();
cout << iter.key() << ": " << iter.value() << endl;
}

Here is the same code using an STL style iterator.

while (iter != flatmap.constEnd()) {
cout << iter.key() << ": " << iter.value() << endl;
++iter;
}

The items are traversed in ascending key order. QFlatMap allows only one value per key. If you call insert() with a key which already exists in the QFlatMap, the previous value will be replaced with the new value.

flatmap.insert("Oregon", "Salem");
flatmap.insert("Oregon", "Medford");
// after the second insert flatmap.value("Oregon") will equal "Medford"

To extract the values from a flat map and not the keys use a range based for.

for (QString value : flatmap) {
cout << value << endl;
}

Items can be removed from the flat map in several ways. One way is to call remove() which will remove any item with the given key. Another way is to use QMutableFlatMapIterator::remove(). In addition, the entire map can be cleared using the clear() method.

Comparison

The QFlatMap<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 QFlatMap key type must provide operator<(). QFlatMap 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".

Overriding the Sort Order

The third template parameter is used to define a sort order for QFlatMap, which is optional. If no user defined sort or compare parameter is provided, the default will be used. The following code is the default QFlatMap Compare template.

template <class Key>
class qMapCompare
{
public:
bool operator()(const Key &a, const Key &b) const {
return qMapLessThanKey(a, b);
}
};

The following is an example of an user defined compare class which provides case insensitive sorting.

class Compare
{
public:
bool operator()(const QString &a, const QString &b) const {
return a.compare(b, Qt::CaseInsensitive) < 0;
}
};
See also
QHash, QMap

Member Typedef Documentation

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

Typedef for allocator used by the container.

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

Typedef for const Val *.

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

Typedef for const Val &.

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

Typedef for an STL style const reverse iterator.

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

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

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

Typedef for the key lessthan comparison object type.

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

Typedef for Key.

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

Typedef for Val.

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

Typedef for Val *.

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

Typedef for Val &.

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

Typedef for an STL style reverse iterator.

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

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

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

Typedef for Val.

Constructor & Destructor Documentation

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

Constructs an empty QFlatMap.

See also
clear()
template<typename Key , typename Val , typename C >
QFlatMap< Key, Val, C >::QFlatMap ( const QFlatMap< Key, Val, C > &  other)
default

Copy constructs a new QFlatMap from other.

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

Move constructs a new QFlatMap from other.

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

Constructs a flat map with a copy of each of the elements in the specified initializer list. If compare is specified it will be used to sort the flat map.

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

Constructs an empty flat map using the specified comparison object compare.

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

Constructs a copy of other.

template<typename Key , typename Val , typename C >
template<typename Input_Iterator >
QFlatMap< Key, Val, C >::QFlatMap ( Input_Iterator  first,
Input_Iterator  last,
const C &  compare = C() 
)
inline

Constructs a flat map using the specified iterator range. These iterators can be any iterator which returns a Pair when dereferenced.

template<typename Key , typename Val , typename C >
QFlatMap< Key, Val, C >::QFlatMap ( const_iterator  first,
const_iterator  last,
const C &  compare = C() 
)
inline

Constructs a flat map using the specified iterator range. These iterators are const QFlatMap iterators.

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

Destroys the flat map. References to the values in the flat map and all iterators over this flat map become invalid.

Method Documentation

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

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

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

This is an overloaded method.

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

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

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

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

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

Removes all items from the flat map.

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

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

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

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

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

Returns a const iterator pointing to the item with the specified key. If the flat map contains no item with key, the method returns constEnd().

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

Returns true if the flat map contains an item with the specified key, otherwise it returns false.

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

Equivalent to calling size().

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

Returns the number of items associated with the specified key.

See also
contains()
template<typename Key , typename Val , typename C >
const_reverse_iterator QFlatMap< Key, Val, C >::crbegin ( ) const
inline

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

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

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

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

Equivalent to calling isEmpty().

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

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

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

This is an overloaded method.

template<typename Key , typename Val , typename C >
QPair< iterator, iterator > QFlatMap< 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 > QFlatMap< 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 QFlatMap< Key, Val, C >::erase ( const_iterator  iter)
inline

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

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

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

Returns an iterator pointing to the item with the specified key. If the flat map contains no item with this key, the method returns end().

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

This is an overloaded method.

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

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

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

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

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

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

template<typename Key , typename Val , typename C >
iterator QFlatMap< Key, Val, C >::insert ( 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 specified key, the item's value is replaced with value.

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

Inserts a new item with the key and value using hint as a suggestion about where to insert. If there is already an item with the specified key, the item's value is replaced with value.

template<typename Key , typename Val , typename C >
bool QFlatMap< Key, Val, C >::isEmpty ( ) const
inline

Returns true if the flat map contains no items, otherwise returns false.

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

Returns the first key with the specified value or the defaultKey if the flat map contains no such item. If no defaultKey was passed it will be value initialized using the data type of Key. Refer to default constructed elements for additional information.

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 > QFlatMap< Key, Val, C >::keys ( ) const

Returns a list containing all the keys in the flat map in ascending order. To obtain a list of unique keys where each key from the flat map only occurs once, use uniqueKeys(). The order is guaranteed to be the same as returned by values().

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

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

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

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

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

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

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

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

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

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

Returns an iterator pointing to the first item specified by key. If the flat map contains no item with key, the method returns an iterator to the nearest item with a greater key.

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

This is an overloaded method.

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

Returns true if other is not equal to this flat map, otherwise returns false. Two flat maps 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 >
QFlatMap< Key, Val, C > & QFlatMap< Key, Val, C >::operator= ( const QFlatMap< Key, Val, C > &  other)
default

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

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

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

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

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

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

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

Returns a reference to the value for the item with the given key. If the key was not found then a new value initialized object of type Val with the given key is inserted. Refer to default constructed elements for additional information.

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

Equivalent to calling value().

template<typename Key , typename Val , typename C >
reverse_iterator QFlatMap< Key, Val, C >::rbegin ( )
inline

This is an overloaded method.

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

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

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

Removes the item which has the given key. Returns the number of items removed which is either zero or one,

See also
clear(), take()
template<typename Key , typename Val , typename C >
reverse_iterator QFlatMap< Key, Val, C >::rend ( )
inline

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

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

This is an overloaded method.

template<typename Key , typename Val , typename C >
size_type QFlatMap< Key, Val, C >::size ( ) const
inline

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

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

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

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

Removes the item specified by key from the flat map and returns the value associated with it. If you do not use the return value remove() will be more efficient. If the key was not found then a value initialized object of type Val will be returned. Refer to default constructed elements for additional information.

See also
remove()
template<typename Key , typename Val , typename C >
QList< Key > QFlatMap< Key, Val, C >::uniqueKeys ( ) const

Returns a list of every key in the flat map with out duplicates.

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

Inserts all the items in the other flat map into this flat map. If a key is common to both flat maps the resulting flat map will contain the old value.

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

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

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

This is an overloaded method.

template<class Key , class Val , class C >
const Val QFlatMap< Key, Val, C >::value ( const Key &  key,
const Val &  defaultValue = Val() 
) const

Returns the value associated with the specified key. If the flat map contains no item with the specified key, the defaultValue is returned.

See also
key(), values(), contains(), operator[]()
template<typename Key , typename Val , typename C >
QList< Val > QFlatMap< Key, Val, C >::values ( ) const

Returns a list containing all the values in the flat map in ascending order of their keys.

See also
keys(), value()

Friends And Related Function Documentation

QDataStream & operator<< ( QDataStream stream,
const QFlatMap< Key, Val, C > &  flatmap 
)
related

Writes the given flatmap to the stream. Returns a reference to the stream. This function requires the type T to support operator<<().

Refer to Serializing Data Types for additional information.

QDataStream & operator>> ( QDataStream stream,
QFlatMap< Key, Val, C > &  flatmap 
)
related

Reads from the stream into the given flatmap. Returns a reference to the stream. This function requires the type T to support operator>>().

Refer to Serializing Data Types for additional information.