Back to Basics: The Rule of Five in C++ - Andre Kostur - CppCon 2023

preview_player
Показать описание
---

Back to Basics: The Rule of Five in C++ - Andre Kostur - CppCon 2023

Designing a class to behave correctly when copied and moved takes a lot of thought. The Core Guidelines provide guidance to streamline that work. In this talk we are going to look at the Core Guideline known as "the Rule of Five", how it came about, and is there anything better.
---

Andre Kostur

Andre Kostur has been a professional C++ developer for nearly 30 years, and was responsible for introducing and championing the use of C++ in his previous company. He is responsible for forming and leading a C++ Users Group as his current company, routinely presenting on all topics regarding C++ ranging from the basics to the latest developments in C++20 and beyond. He has previously been a speaker at CppCon.
---

---

#cppcon #cppprogramming #cpp
Рекомендации по теме
Комментарии
Автор

Thanks. Useful, Interesting, Calm talk.

videofountain
Автор

Great talk! Always nice to get a refresher on the basics. The examples clearly show the usage of the rule. Looking forward to your 2024 talk.

stephanebourque
Автор

Thank you so much. Cleared a lot of doubts. Took screen prints of Rule of 5 and the table of special methods provided by compiler vs ones provided by the user. Can't thank you enough. Saved me a lot of reading and going round in circles to nowhere

vasudevans
Автор

I love these B2B videos. And this one is long overdue! Thanks, Andre!

IsaacC
Автор

I really like the idea of back to basics section. This talk fits perfectly to help me understand.

SafaAndac
Автор

Thanks Andre, appreciate your time and effort sharing your knowledge of the C++ language. Whilst I am very familiar with the rules of 3/5/0, it is often nice to challenge and remind oneself of their knowledge and assumptions.

russCoding
Автор

Great talk, thank you so much, I really enjoyed!

supertacosauce
Автор

Great talk! Very clear and well explained.

justinlink
Автор

37:25 Since C++20, a class with user-declared constructors is considered not to be an aggregate. ("= default" is still user-declared.)

treehouse
Автор

Came for entertainment, Found gold. Immediately smashed that like button

debajyotimajumder
Автор

The question that soon arises for maintainers of older code soon becomes:
If the code was already written correctly complying with the Rule of Three, will it still be safe with the new compiler without any changes?
As far as I can understand - based on the chart - it still should be. You just don't get the benefit of move semantics. It can be a bit more fuzzy when inheritance is involved, and maybe one of the base classes has been "upgraded" to the Rule of Five, not to mention when some of the methods may be declared virtual too. Larger codebases often find themselves in such a mixed "transition state" after the passage of time and many programmers have left their mark.

benhetland
Автор

informative and important cppCon topic.. however, the few of the last QnA wasn't clear without real example/code.

ParvezKhanPK
Автор

For a SString you could get rule of zero by using std::vector

fane
Автор

I want to learn C++ but the more I learn either from books or elsewhere the more it seems like C++ is a language that wrote itself into a corner of bad decisions and now can't fix them because it has to keep backwards compatibility and people can't switch because nothing else with the same use cases is as developed (or widely used) as it. Like all this would be so much easier and less error prone if the compiler didn't create or remove different things depending on a myriad of factors but just expected you to define what you need and to manually tell it to provide defaults (or mark as intentionally not implemented) for what you didn't.

Ircy
Автор

Would it make sense in implementing sstring to use std::vector<char> as the container type? Implementing Estring to use string feels like a bit of a cop-out answer here... but I'm not sure if std::vector<char> would be enough as I honestly haven't carefully considered it. I would think it would get us close with copy/move semantics though, and it still has access to the pointer through the data() member(or something with a similar name?) iirc.

Firestar-rmdf
Автор

6:41 But you see, I will never construct an allocation function in a manner like this to make a leak. Most of my memory allocation will have a simple step to later delete. In any case, I will never have a constructor with routines, without a destructor with the opposing routines new/delete new[]/delete[], open/close etc

colinmaharaj
Автор

Around 32:00 Andre talks about a class that the developer wants to use the copy constructor or assignment operator when moving and suggests commenting out the move constructor and move assignment operator to get that behaviour. Would it be possible to =default the move constructor and move assignment operator to get the same result?

andrewduncan
Автор

I feel like the entire special member functions are not that well implemented in C++ considering we get a talk about the rule of 5 every second cppcon

bruderdasisteinschwerermangel
Автор

I wonder if there is a proposal for some kind of `value_ptr` which is like `unique_ptr` except it can be copied by copying the underlying data to a new allocation, possibly with a custom allocator similar to a custom deleter.

TinBryn
Автор

@19:45-19:49 This sounds incorrect. Can someone verify std::unique_ptr is NOT copyable and IS movable?

IsaacC