[Development] Proposal: Deprecating platforms in Qt 5.6 that don't support lambda
Matthew Woehlke
mw_triad at users.sourceforge.net
Fri Feb 20 18:53:24 CET 2015
On 2015-02-20 07:10, Иван Комиссаров wrote:
> Sorry for interupting the discussion, but i saw mentioning of a
> range-based-for, so i have a question. std::map/unordered_map uses
> std::pair as a value type, and map::iterator::operator* returns reference
> to a pair, while Qt doesn't have an underlying struct and operator* returns
> ref to T (without a Key). So, using range-based-for (and foreach) with Qt
> containers doesn't allow to have an access to a key.
> Should this behavior be changed in the future (yes, this breaks source
> compatibility)?
No. No need. (Also... note that foreach doesn't give you keys either.)
You can instead wrap the container in an iterator wrapper that gives you
iterators rather than values. (I have code somewhere, but not sure I
have permission to share it.) No SIC, and you can still iterate directly
over values.
It's not entirely unlike the trick to do:
for (auto const i : qtIndexRange(5))
...and looks like:
for (auto const i : qtEnumerate(map))
Maybe it would be nice for Qt to provide one or both of these?
--
Matthew
More information about the Development
mailing list