GIT_SILENT
Details
Tests pass, KParts-based apps work as before.
Diff Detail
- Repository
- R306 KParts
- Branch
- morerangebased
- Lint
No Linters Available - Unit
No Unit Test Coverage - Build Status
Buildable 17159 Build 17177: arc lint + arc unit
src/plugin.cpp | ||
---|---|---|
196–199 | Do we have rules in KF whether stl-like names liks cbegin() & cend() are fine? Does it make sense to catch the reference library by reference? Myself do not have a stable best-practice rules here, so happy to learn more. | |
src/statusbarextension.cpp | ||
139–140 | container elements are modified. | |
143–144 | Same here :) |
src/plugin.cpp | ||
---|---|---|
196–199 | STL is fine by definition, it's the C++ standard. But yes, no need for cbegin/cend on a const container. Catching library by reference makes sense, just like you wouldn't pass it by value to a function, here you're capturing it by value. The fact that it's a reference in the argument list doesn't change anything. See e.g. http://www.cplusplus.com/forum/general/142165/ |
src/plugin.cpp | ||
---|---|---|
196–199 | Meh, I need to check quite some code of mine then, I got that wrong and thought that the values of the actual variables listed are captured (i.e. for a reference type the reference "pointer"), and not that some kind of interpretation happens here. |
src/plugin.cpp | ||
---|---|---|
196–199 | 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 :) |
It's actually quite clear in my head, because I imagine the generated class. A captured variable in a lambda becomes a member variable. If it's a capture by value (which is what happens with [library]), it's a "plain value" member.
So:
bool Plugin::hasPlugin(const QString &library) { auto func = [&library](QObject* p) { return ...; }); }
becomes
bool Plugin::hasPlugin(const QString &library) { class Closure { bool operator(QObject *p) const { return ...; } QString library; }; auto func = Closure{library}; }
or something like that.
src/plugin.cpp | ||
---|---|---|
196–199 | Understanding captures becomes simple as soon as you follow what the compiler essentially does for you with the lambda: 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. |
David's explanation is much more correct: Behind the scenes you have this Closure trick with a functor object, not really a free function what I was claiming ;)
Thanks for your teaching, appreciated :) Will have another look again when not tired. Just tried again to read on cppreference.com the stuff about lambda capturing, but still not digested what I read this afternoon, reread now did not help. So next try scheduled.
So far my thinking was, given some variables in the scope Type& ref; Type* pointer; Type type;,
it would be for [&]
class Closure { bool operator() const { return ...; } Type&& ref; // yes, no idea if this even is supported by C++, that was just my mind model Type*& pointer; Type& type; };
and it would be for [=]
class Closure { bool operator() const { return ...; } Type& ref; Type* pointer; Type type; };
So seems I have to rewrite my mind model for the type of ref.
@kossebau: did you try the C++ Standard (working draft): https://isocpp.org/blog/2013/10/n3797-working-draft-standard-for-programming-language-c-stefanus-du-toit
This ^ one is circa 2012.
All the sources used to generate the C++ Standard drafts are maintained in this git repo:
https://github.com/cplusplus/draft
(Reading the standard feels like reading legalese, but it's quite informative albeit very^Wslightly mind boggling).
Sorry if this is off-topic.
Edit: phabricator doesn't support removing inline comments? (stupid, stupid)
src/plugin.cpp | ||
---|---|---|
196–199 |
|
Please make the loop variable const-ref whenever possible.
src/browseropenorsavequestion.cpp | ||
---|---|---|
270 ↗ | (On Diff #66996) | Why not *const* auto &app? |
src/plugin.cpp | ||
138 ↗ | (On Diff #66996) | const auto & (space before '&', btw, not after) |
214 ↗ | (On Diff #66996) | const... |
src/scriptableextension.cpp | ||
260 ↗ | (On Diff #66996) | const |
src/browseropenorsavequestion.cpp | ||
---|---|---|
270 ↗ | (On Diff #66996) | In most projects I have seen people omitting the const, and only adding explicitly any &/* to help the human reader a bit more. |
Thanks. Yes, quite legalese, but it narrowed things down to some good degree for me now. The quote you made in the inline comment seems indeed to be the one I should grasp: "The type of such a data member is the type of the corresponding captured entity if the entity is not areference to an object, or the referenced type otherwise." (about "captured by copy"). I think I start to make this known to me :) [Edit; and while checking own commits from recent times already found code from others where the missing & results in value copies :) ]
src/browseropenorsavequestion.cpp | ||
---|---|---|
270 ↗ | (On Diff #66996) | auto or not auto isn't the question when it comes to const :-) Would you have written foreach(QString &app, apps) if apps was a qstringlist (to simplify)? And while * is redundant (therefore it only helps humans), the & is definitely not redundant. Without it you get a copy. |
src/browseropenorsavequestion.cpp | ||
---|---|---|
270 ↗ | (On Diff #66996) | Sigh... I learned C++ originally from the Stroustrup book, mostly reading in bed in leisure time. C++11 I learned from peers and the internet on the job, and now find myself often with misconceptions. I start to think I should return to proper books in bed :) |
src/browseropenorsavequestion.cpp | ||
---|---|---|
270 ↗ | (On Diff #66996) | I give C++11/14/17 trainings, if it helps :-) |
src/browseropenorsavequestion.cpp | ||
---|---|---|
270 ↗ | (On Diff #66996) | :) Though, I doubt you give them in single person understanding-pace-driven tiredness-cut bed settings (besides own family.... how to tell a nerd kid: "Mummy/Daddy, please, please, another good night tutorial!"). |