CppCon 2018: Richard Powell “How to Argue(ment)"

CppCon · 12K views · 2018 · 54:10

Open on YouTube

C, C++, Rust, Go & systems languagesSoftware architecture & designtalk

Why Stack Overflow recommends it

Stack Overflow users link it when explaining what different C++ parameter types imply, such as why a non-const reference signals mutation or why a const overload is chosen.

Recommended by 1 people across 1 different months, 2018 to 2020.

What it is

A CppCon 2018 talk by audio software engineer Richard Powell cataloguing the many ways to pass function arguments in C++ (by value, const reference, non-const reference, rvalue reference and so on). It argues that a function signature should communicate purpose, semantics and side effects, and ends with recommendations for which parameter types express which intent.

What people said

Recommends Nathan Chappell · 2020-02 · Stack Overflow · on “Const overload unexpectedly called in gcc. Compiler bug or compatibility fix?”

There is a debate about whether or not this is "intuitive behavior" in the comments, so I thought I would take a stab at the reasoning behind this behavior. There's a pretty nice talk that was given at CPPCON that makes this a bit more clear to me { talk [this video] , slides [LINK] }. Basically, what does a function which takes a non-const reference imply? That the input object must be read/write . Even stronger, it implies I intend to modify this object, this function has side effects . A const ref implies read only , and rvalue ref means I may take the resources . If test_1() were to end up calling the NON-CONST constructor, it would mean I intend to modify this object, even though after I'm d

Cites cmwt · 2018-11 · Stack Overflow · on “How to apply restrict qualifier on this pointer”

How can I apply GCC's/Clang's __restrict__ qualifier to the this pointer of a class? This question was inspired by Richard Powell's CppCon 2018 talk, " How to Argue(ment). [this video] " I saw a similar question " restrict qualifier on member functions (restrict this pointer). [LINK] " (All code can be found on Compiler Explorer [LINK] ) void bar(); class Foo { public: int this_example() const { if (value > 0) { bar(); return value; } else { return value; } } private: int value; }; The above code generates the following assembly. In it, we can see that value has to be loaded twice, via the this pointer. This makes sense, it is a consequence that C++ inherited from C and the restrict qualifier [LI

Cites alfC · 2019-06 · Stack Overflow · on “Why isn't forwarding reference const?”

Interesting question, it is possible that there is no use for this kind of signature. Either you do `T&&` or `T const&`. [this video]