template<
typename T>
class Quotient::asKeyValueRange< T >
An adaptor for Qt (hash-)maps to make them iterable in STL style.
QMap/QHash container iterators returned by begin() and end() dereference to values, unlike STL where similar iterators dereference to key-value pairs. It is a problem in range-for if you want to also access map keys. This adaptor allows to use range-for syntax with access to both keys and values in QMap/QHash containers. Just use for (auto&& [key, value] : asKeyValueRange(myMap)
instead of for (auto&& value : myMap)
.
- Note
- When an rvalue is passed as the constructor argument, asKeyValueRange shallow-copies the map object to ensure its lifetime is maintained throughout the loop; with lvalues, no copying occurs, assuming that the map object outlives the range-for loop
Definition at line 184 of file util.h.