D24262: Modernize code: use range-based loops & algorithms in more places
Dominik Haumann
noreply at phabricator.kde.org
Sat Sep 28 20:55:52 BST 2019
dhaumann added inline comments.
INLINE COMMENTS
> kossebau wrote in plugin.cpp:196
> Confirmed by experiments. Still not yet found a document where explicitly it is mentioned that the copy constructor will be invoked to generate a copy of the object for any captured variables only being of type reference, so if anyone can point out one which reads this clearly to me, happy to get a reference to, so I can try to do a copy of that referenced document into my brain lambda :)
Understanding captures becomes simple as soon as you follow what the compiler essentially does for you with the lambda:
The lambda function does not capture `[this]`, so behind the scenes the compiler will create for you a free function (with an internal unique function name). This free function will have a local const variable "library". If you write [library] than this local variable will simply be a copy (think of the definition `const QString library = library_from_outer_scope;`. When you write `[&library]` instead, you will get a `const QString &library = library_from_outer_scope;`. Does that clarify when to use `&` or not? :-)
PS: If you capture `[this]`, then the compiler will not a create a free function, instead the compiler will create a member function for you (again with internal unique name ....).
Looking at lambda functions from this perspective makes this rather simple.
REPOSITORY
R306 KParts
REVISION DETAIL
https://phabricator.kde.org/D24262
To: kossebau, dfaure
Cc: dhaumann, kde-frameworks-devel, LeGast00n, GB_2, michaelh, ngraham, bruns
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20190928/dc861424/attachment.html>
More information about the Kde-frameworks-devel
mailing list