[Interest] How to make QMap work as input to std::ranges::views?

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Mon Apr 14 17:57:10 CEST 2025


Il 14/04/25 17:35, Volker Hilsheimer via Interest ha scritto:
> As Thiago says, you have to use std::views::transform. In that case, you can put the QMap itself directly into the pipeline:
> 
> auto viewAsPair = map | std::views::transform(fTransform);
> 
> But you cannot use an rvalue as the input range (see e.g.https://en.cppreference.com/w/cpp/ranges/dangling). Make a copy first:
> 
>      auto keyValueRange = map.asKeyValueRange();
>      auto viewAsPair = keyValueRange | std::views::transform(fTransform);

This is a bug. The type returned asKeyValueRange() is supposed to model 
ranges::view. It doesn't; it doesn't inherit from view_interface nor has 
enabled_view enabled for it, and it doesn't model std::moveable. This 
should be a subtask of QTBUG-105465.

My 2 c,
-- 
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - Trusted Software Excellence

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4244 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20250414/dec926ec/attachment.bin>


More information about the Interest mailing list