libQuotient
A Qt library for building matrix clients
Quotient::asKeyValueRange< T > Class Template Reference

An adaptor for Qt (hash-)maps to make them iterable in STL style. More...

#include <util.h>

Public Member Functions

 asKeyValueRange (T data)
 

Detailed Description

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 114 of file util.h.

Constructor & Destructor Documentation

◆ asKeyValueRange()

template<typename T >
Quotient::asKeyValueRange< T >::asKeyValueRange ( data)
inlineexplicit

Definition at line 117 of file util.h.


The documentation for this class was generated from the following file: