<table><tr><td style="">dhaumann added inline comments.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D24262">View Revision</a></tr></table><br /><div><strong>INLINE COMMENTS</strong><div><div style="margin: 6px 0 12px 0;"><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D24262#inline-137498">View Inline</a><span style="color: #4b4d51; font-weight: bold;">kossebau</span> wrote in <span style="color: #4b4d51; font-weight: bold;">plugin.cpp:196</span></div>
<div style="margin: 8px 0; padding: 0 12px; color: #74777D;"><p style="padding: 0; margin: 8px;">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 :)</p></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">Understanding captures becomes simple as soon as you follow what the compiler essentially does for you with the lambda:<br />
The lambda function does not capture <tt style="background: #ebebeb; font-size: 13px;">[this]</tt>, 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 <tt style="background: #ebebeb; font-size: 13px;">const QString library = library_from_outer_scope;</tt>. When you write <tt style="background: #ebebeb; font-size: 13px;">[&library]</tt> instead, you will get a <tt style="background: #ebebeb; font-size: 13px;">const QString &library = library_from_outer_scope;</tt>. Does that clarify when to use <tt style="background: #ebebeb; font-size: 13px;">&</tt> or not? :-)</p>
<p style="padding: 0; margin: 8px;">PS: If you capture <tt style="background: #ebebeb; font-size: 13px;">[this]</tt>, 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 ....).</p>
<p style="padding: 0; margin: 8px;">Looking at lambda functions from this perspective makes this rather simple.</p></div></div></div></div></div><br /><div><strong>REPOSITORY</strong><div><div>R306 KParts</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D24262">https://phabricator.kde.org/D24262</a></div></div><br /><div><strong>To: </strong>kossebau, dfaure<br /><strong>Cc: </strong>dhaumann, kde-frameworks-devel, LeGast00n, GB_2, michaelh, ngraham, bruns<br /></div>