Back to Basics: const and constexpr - Rainer Grimm - CppCon 2021
Вставка
- Опубліковано 21 гру 2021
- cppcon.org/
github.com/CppCon/CppCon2021
---
It is a virtue to program as const as possible in modern C++. Your program is by design way more type safe, has fewer concurrency issues, and runs with high probability faster.
Const has many flavors in modern C++. Thanks to const, you can protect a value against mutation. With constexpr, you can initialize and compute values at compile time. Thanks to conteval, a computation can only run at compile time. In the end, constinit empowers you to initialize a modifiable value at compile time.
Let me show you in my lecture how you can initialize a value with constexpr and constinit in a thread-safe way. Let me show you how const and constexpr help you protect values from mutation and, therefore, make them immune to data races. Finally, let me show you how constexpr and consteval empowers you to improve the performance of your program and get functions that are by design easy to test, easy to maintain, and implicitly thread-safe.
---
Rainer Grimm
I've worked as a software architect, team lead, and instructor since 1999. In 2002, I created company-intern meetings for further education. I have given training courses since 2002. My first tutorials were about proprietary management software, but I began teaching Python and C++ soon after. In my spare time, I like to write articles about C++, Python, and Haskell. I also like to speak at conferences. I publish weekly on my English blog (www.modernescpp.com/) and the (www.grimm-jaud.de/index.php/b..., hosted by Heise Developer. Since 2016 he is an independent instructor giving seminars about modern C++ and Python. Rainer published several books in various languages to modern C++ and concurrency, C++20, and the C++ Core Guidelines, in particular. Due to his profession, Rainer always searches for the best way to teach modern C++
---
Videos Streamed & Edited by Digital Medium: online.digital-medium.co.uk
*--*
Fantastic explanation of a subtle but fundamental set of tools.
Thanks for the talk! Extremely helpful.
This was a great refresher, thanks!
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".
To read the type correctly (const char* const ptr, etc) use the "spiral rule" - not just "right to left".
Great talk! I wish the chat could be shown on screen for the Q&A portion
It would be really great to add time codes to the description.
Great talk! Thanks for sharing! I wish subtitles was enabled.
Fantastic Presentaion
Is there a slip of tounge or did I misunderstand what is meant to be said at
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
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++.
small font size makes good information hard to understand. please give attention to font size its hard to read code on video.
Where are the slides ?! Thanks !
What about east const vs. const west?
This is interesting @
One thing is missing regarding consteval - Why should we use consteval ? Motivation advantages ?
Of course const objects can be victim of data races if there are mutable members.
The shared screen is awfully blurry :(