QGIM: Add utilities for generic access of keys and values of iterators

Since Qt associative containers don't have the same iterator API as
their std equivalents, generic access to the key/value pair of a
container will be useful when adding support for multi-role storage
types and sparse tables.

Change-Id: I409e94485257982ac8a231f9bffd791a53867968
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Artem Dyomin 2025-03-22 00:51:03 +01:00 committed by Volker Hilsheimer
parent 0a567a7f92
commit 47cf043329

View File

@ -155,6 +155,18 @@ namespace QGenericItemModelDetails
template <typename T> static auto pointerTo(T &t) { return std::addressof(t); }
template <typename T> static auto pointerTo(const T &&t) = delete;
template <typename It>
auto key(It&& it) -> decltype(it.key()) { return it.key(); }
template <typename It>
auto key(It&& it) -> decltype((it->first) /*pars for ref type*/ ) { return it->first; }
template <typename It>
auto value(It&& it) -> decltype(it.value()) { return it.value(); }
template <typename It>
auto value(It&& it) -> decltype((it->second)) { return it->second; }
// The storage of the model data. We might store it as a pointer, or as a
// (copied- or moved-into) value. But we always return a pointer.
template <typename ModelStorage>