"Understanding value categories in C++" by Kris van Rens

  Рет қаралды 5,149

C/C++ Dublin User Group

C/C++ Dublin User Group

Күн бұрын

Talk slides: krisvanrens.github.io/slides/...
Abstract: In C++ today, do you know what an xvalue is? Or a prvalue? Why would you want to know? Because it matters! In C++, each expression is characterized by a value category. These value categories are used to describe parts of the C++ standard, and are often used in books and articles. You might have heard of terms like 'lvalue' or 'rvalue', which are the most commonly known ones. Over the years, changes to the C++ language changed the meaning of value categories. This means a lot of information about value categories is outdated or just plain wrong. In this talk, I will explain what expression value categories are in today's C++ standard. It turns out that knowledge about value categories can really be beneficial. Not only will it enrich your understanding of C++ in general, it will deepen your understanding of mechanisms like move semantics. Also, it can help you to make better choices about code. These choices can then leverage language rules to enable compilers to generate efficient code without redundant copies. Other, related topics that will be covered: copy elision, return value optimization, temporary materialization.

Пікірлер: 10
@jvsnyc
@jvsnyc 3 жыл бұрын
Wonderful. I watched BOTH versions of this talk available on KZbin. It was that good.
@krizzzlybear
@krizzzlybear 2 жыл бұрын
Thanks for the kind words!
@aarfeenanees9147
@aarfeenanees9147 5 ай бұрын
Wonderfully explained. I came with surface level knowledge and am leaving with in depth knowledge of value categories. Plus RVO and Temporary Materialisation coverage was a pleasant surprise!
@carlschumann
@carlschumann Жыл бұрын
20:36 is the start of a useful diagram the value categories and their relationship to each other
@samuelbartik5265
@samuelbartik5265 3 жыл бұрын
I recommend putting it on 1.25x speed. It's better that way.
@krizzzlybear
@krizzzlybear 3 жыл бұрын
Yeah I was wearing the slow pants that evening ;-) Thanks for watching anyway!
@luckyj321
@luckyj321 20 күн бұрын
I have a might be stupid question, what does it mean for "identity"?
@tebes9265
@tebes9265 3 жыл бұрын
Hey Kris, thank you very much for your awesome video! I struggled a lot with the new value categories and temporary materialization. I have two questions: 1. How do you interpret the term "temporary materialization"? Is it a materialization that is temporary or is it a temporary that gets materialized? I get confused by the term "temporary" and can't find its definition anywhere. What exactly is it? Is it something that exists (as in a register or in memory) or is it just something "hypothetical" that can be materialized? 2. The slide "temporary materialization in action" at 56:30 shows that there are 3 temporary materializations in the second example (auto x = ...). Cppreference says: "Note that temporary materialization does not occur when initializing an object from a prvalue of the same type (by direct-initialization or copy-initialization): such object is initialized directly from the initializer. This ensures "guaranteed copy elision"." So the 3rd one should not be a temporary materialization but rather the x getting directly initialized by the prvalue, shouldn't it? But what exactly does that mean? I understand the first and the second materialization. The +operator then produces an rvalue (which is not really existent?) and then suddenly the auto x gets initalized directly by it? What is actually happening in memory? This is still really confusing to me and I would appreciate clarification a lot. Best regards, Te
@krizzzlybear
@krizzzlybear 2 жыл бұрын
Hi Te Bes, Don't overthink the used terminology! The term "temporary materialization" is just a name for a mechanism. Of course it has some concrete meaning, but it is a term used in the context of the C++ standard, which defines the programming language C++, not the exact machine code result. What I'm trying to say: thinking about 'temporary' as an actual value in memory/register does not make sense in the context of the definition of 'temporary materialization' in the C++ standard. What temporary materialization describes is a mechanism for prvalues to materialize/come to be when they in some way need to. Regarding your second question; you have a point. Perhaps I'm not fully qualified to answer this, but the way I see it: here's where the mechanisms of temporary materialization and direct initialization overlap. Or, perhaps a temporary materialization conversion is identified, but overruled/follows by a direct initialization. Regarding whether or not an rvalue exists or not; again, the whole mechanisms behind the scenes are just language specification constructs for compilers to deal with. In other words; most likely the compiler will have *something* in memory, but using the construct for compilation it may well be completely removed at the end of compilation due to optimizations for examples. So, does it really matter if they exist? Not for the compilation output. But the concept of value categories are useful for talking about language specifications and reason about overload resolution/move semantics etc. I hope this helps.
@tebes9265
@tebes9265 2 жыл бұрын
@@krizzzlybear Thanks for the answer!
We Got Expelled From Scholl After This...
00:10
Jojo Sim
Рет қаралды 74 МЛН
[CppDay20] Understanding value categories in C++ (Kris van Rens)
55:41
Italian Cpp Community
Рет қаралды 2,3 М.
Deterministic Disappointment by Niall Douglas
1:59:48
C/C++ Dublin User Group
Рет қаралды 3,4 М.
lvalues and rvalues in C++
14:13
The Cherno
Рет қаралды 304 М.
Core C++ 2019 :: Dan Saks :: Understanding Lvalues and Rvalues
1:01:11
ctypes made easy
41:19
C/C++ Dublin User Group
Рет қаралды 20 М.
WHY IS THE STACK SO FAST?
13:46
Core Dumped
Рет қаралды 138 М.
CppCon 2019: Jason Turner “The Best Parts of C++"
58:36
CppCon
Рет қаралды 90 М.
Advanced C: The UB and optimizations that trick good programmers.
1:12:34
Eskil Steenberg
Рет қаралды 159 М.
Will the battery emit smoke if it rotates rapidly?
0:11
Meaningful Cartoons 183
Рет қаралды 36 МЛН
iPhone 12 socket cleaning #fixit
0:30
Tamar DB (mt)
Рет қаралды 55 МЛН
1$ vs 500$ ВИРТУАЛЬНАЯ РЕАЛЬНОСТЬ !
23:20
GoldenBurst
Рет қаралды 1,4 МЛН
Secret Wireless charger 😱 #shorts
0:28
Mr DegrEE
Рет қаралды 2,3 МЛН
Low Price Best 👌 China Mobile 📱
0:42
Tech Official
Рет қаралды 717 М.