Back to Basics: const and constexpr - Rainer Grimm - CppCon 2021

  Рет қаралды 30,998

CppCon

CppCon

Күн бұрын

Пікірлер: 28
@isayurdagul
@isayurdagul Жыл бұрын
Is there a slip of tounge or did I misunderstand what is meant to be said at 19:30 . Should it be "The more variables are const, easier to reason about concurrent program"?
@superscatboy
@superscatboy 3 жыл бұрын
Fantastic explanation of a subtle but fundamental set of tools.
@LiveseyMD
@LiveseyMD 3 жыл бұрын
It would be really great to add time codes to the description.
@MaxCoplan
@MaxCoplan 2 жыл бұрын
Great talk! I wish the chat could be shown on screen for the Q&A portion
@fppt1555
@fppt1555 3 жыл бұрын
Thanks for the talk! Extremely helpful.
@ChrisOffner
@ChrisOffner 2 жыл бұрын
Unfortunately I still don't understand the meaning of "logical constness: The object is const but could be changed." Yes, there was an example about avoiding a compilation error when using *mutable* for a mutex, but it didn't really clarify much for me conceptually.
@darranrowe174
@darranrowe174 2 жыл бұрын
One thing that these kinds of talks don't do that well is explain why you would want something like that. As an example, suppose you have a read only view into a database, you want to iterate though a database containing data on cats and their preferred treats as an example. Since it is data stored into an external service, you would have to read it first, and it may be unfeasible or even impossible to read all of the data at once if the database is large. In this case, it would be possible to cache a few entries, iterate through those and then cache more entries. The caching of the data would end up modifying any data that you are working with, but your view of that data would be technically read only.
@MagnificentImbecil
@MagnificentImbecil 2 жыл бұрын
Physical constness: A non-static member function marked as const is not allowed (in the absence of const_cast and C-style cast and mutable) to modify the kernel-block of the object (e.g. a pointer-to-non-const), but it could modify an extension-block (e.g. the pointee). Logical constness: For a container or a Pimpl-wrapper, we might want to programatically consider both the kernel-block (the pointers) and the extension-blocks (the pointees) as logical parts of the object. And even if the compiler allows us to modify the pointees from a const member function, we should restrain from doing so. And from a const member function, we should not return pointer-to-non-const (even if the compiler allows us), but pointer-to-const instead. Please consider std::vector . It has two versions of the begin member function: one which is non-const and returns pointer/iterator-to-non-const and one which is const and returns pointer/iterator-to-const. The latter could have returned pointer/iterator-to-non-const without any cast -- it would have been allowed by the compiler, because the compiler only enforces physical constness. But the programmer wanted to enforce logical constness (i.e. constness not just of the kernel of the vector, but of the T elements too), which in this case goes beyond physical constness.
@ejyjawa352
@ejyjawa352 2 жыл бұрын
Where are the slides ?! Thanks !
@sky_is_the_limit_13
@sky_is_the_limit_13 6 ай бұрын
Great talk! Thanks for sharing! I wish subtitles was enabled.
@m1t0z
@m1t0z 3 жыл бұрын
Nice talk! Thanks for structuring different types of "const" both from historical and functional perspectives. Look forward to use constinit to solve issues with initialization order of the variables with ssd in our codebase (currently we are relaying on the linker order but are not really happy with that approach). P. S. In case you need some constructive feedback I would suggest to add an additional explicit section to your presentation where to highlight the guidelines where, when and why to use which type of "const".
@bogdansikach7709
@bogdansikach7709 2 жыл бұрын
To read the type correctly (const char* const ptr, etc) use the "spiral rule" - not just "right to left".
@ns1198
@ns1198 8 ай бұрын
what is the spiral rule? Any reference pls?
@x87-64
@x87-64 3 ай бұрын
@@ns1198 Google "Clockwise/Spiral Rule in C". It is a very classic way to read convoluted C declarations.
@paxdei1988
@paxdei1988 18 күн бұрын
Or just write it as char const* const ptr. Now you can read it right to left without spirals.
@discreet_boson
@discreet_boson 3 жыл бұрын
This was a great refresher, thanks!
@sadiqueali930
@sadiqueali930 3 жыл бұрын
Fantastic Presentaion
@CppCon
@CppCon 3 жыл бұрын
Many thanks
@sanjaygatne1424
@sanjaygatne1424 3 жыл бұрын
small font size makes good information hard to understand. please give attention to font size its hard to read code on video.
@saipan1970
@saipan1970 3 жыл бұрын
Such a wonderful content, could not enjoy just because of small fonts.Sir,please consider also the mobile viewers, I sincerely follows your 📖 and articles on C++.
@ChrisOffner
@ChrisOffner 2 жыл бұрын
Even on my 16" notebook display I found the code examples hard to read. Any presenter should know to use large font sizes in their presentations.
@bsdooby
@bsdooby 3 жыл бұрын
What about east const vs. const west?
@badassopenpolling
@badassopenpolling 11 ай бұрын
One thing is missing regarding consteval - Why should we use consteval ? Motivation advantages ?
@rutabega306
@rutabega306 8 ай бұрын
Prevent accidental runtime calculations
@Heyothatsittahowski
@Heyothatsittahowski Жыл бұрын
This is interesting @33:37
@OlliS71
@OlliS71 9 ай бұрын
Of course const objects can be victim of data races if there are mutable members.
@Moriadin
@Moriadin Жыл бұрын
The shared screen is awfully blurry :(
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
Enter the Void if you Dare! Installing Minimal Void Linux.
23:08
Back to Basics: Concurrency - Arthur O'Dwyer - CppCon 2020
1:04:28
Back to Basics: Lambdas - Nicolai Josuttis - CppCon 2021
1:05:21
C++ Reflection - Back on Track - David Olsen - C++Now 2024
1:26:49