C++ Weekly - Ep 231 - Multiple Destructors in C++20?! How and Why

preview_player
Показать описание
☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟

T-SHIRTS AVAILABLE!

WANT MORE JASON?

SUPPORT THE CHANNEL

GET INVOLVED

JASON'S BOOKS

► C++23 Best Practices

► C++ Best Practices

JASON'S PUZZLE BOOKS

► Object Lifetime Puzzlers Book 1

► Object Lifetime Puzzlers Book 2

► Object Lifetime Puzzlers Book 3

► Copy and Reference Puzzlers Book 1

► Copy and Reference Puzzlers Book 2

► Copy and Reference Puzzlers Book 3

► OpCode Puzzlers Book 1


RECOMMENDED BOOKS

AWESOME PROJECTS

O'Reilly VIDEOS

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

Holy shit Jason the learning curve only gets curvier.

goodecheeseburgers
Автор

One word wow.... C++ going so fast and so vast, it just feels like we always catching up

gnulinux
Автор

"Choose! Choose the form of the destructor." -Ghostbusters

-taz-
Автор

I've been out of the loop in C++ development for a few years already and I'm just learning that concepts finally made it into C++20. That, and there's GCC 11. Shit's bananas.

guest
Автор

Was expecting some shenanigens, wasn't dissappointed,
Very intereseting thanks!

TNothingFree
Автор

This is insanely good. Though it makes me sad that STL implementations may not use it for backward compatibility.

LesleyLai
Автор

This is not "multiple destructors".
An Optional<int> only has one destructor (a trivial destructor) and an Optional<string> only has one destructor (a non trivial destructor)!

However there are multiple destructors in C++. Try to look at the generated assembler for a classes destructor for a class with non-trivial destructible members.

johnjohnson
Автор

In any case you end up with user-declared destructor. In such case compiler does not generate implicit move constructor for you. Therefore, you have to define move constructor explicitly, otherwise your optional<int> is not movable. So, is there a way to not define `~Struct() = default` at all?

ujosnah
Автор

Great episode. Finally some more advanced material in Weekly.

YourCRTube
Автор

Really this should be called "Conditional Inheritance" ;)

jasoncole
Автор

Regarding the audio clicking sound. Have you tried increasing the buffer size in whatever software you use to record? If the buffer is too small, then every once in a while the computer won't be able to process a buffer completely in time and this results in random clicks in the recording. I've definitely been there. Super annoying, super random

SalingToMars
Автор

Because of the anonymous union the data destructor is not called I guess?
Or does the union serve another purpose?

Wimpielef
Автор

Black screen around 6:22, and again at around 10:03

olafurw
Автор

Can this be applied to any function member or only to destructors?

kwkfortythree
Автор

That's actually pretty awesome, thanks for sharing!

STOJATEK
Автор

Great video. Btw seems like some portions you were holding arrow keys to move characters. Ctrl+arrow (I think alt+arrow on mac) jumps by word.

matt_
Автор

Now I must have chosen the wrong Jason turner weekly. This one flew right over my head. I can't still wrap my head around its necessity. But, well, thanks anyway.

larswadefalk
Автор

Thanks Jason for this insight..!!
Really nice and to the point video.

rajatgirotra
Автор

Apparently, code on 9:40 can't be compiled with Optional<std::string> being instantiated. Because of the union for non-trivial destructible type and because of line 8 where unknown name Contained being used. But that is not my question, my question is - in the presented shape code does compile, that mean that gcc does not fully figured out how exactly you can destruct the object, but already knew that is is not trivially destructible. That level of laizyness I was not expecting, do you have any other examples or explainations how it works under the hood?

tzlom
Автор

There are so many cases where you have to carefully analyse the generated assembly to understand which overload actually gets chosen.

Elite