A Journey Into Non-Virtual Polymorphism in C++ - Rudyard Merriam - CppCon 2023

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

A Journey Into Non-Virtual Polymorphism addressing std::any, std::variant and visit, std::tuple and apply, and CRTP. - Rudyard Merriam - CppCon 2023

Join me on an introductory journey into polymorphism that doesn't use class inheritance and virtual functions. I'll share my amazement at how polymorphism permeates C++. Then we'll visit the long-used Curiously Recurring Template Pattern (CRTP) with its modernization using implicit this.

Do you like lambdas? So does the override pattern, which uses them to handle std::tuples and std::variants with std::apply and std::visit.

Want to walk through a container of disparate types invoking their functions? You'll see this and all the above in code examples galore.

Afterward, you'll be eager to learn more on your own!
---

Rudyard Merriam

Rud Merriam is a retired software developer, having lived through the spaghetti, structured programming, and object-oriented development paradigms. He's trying to figure out functional programming and keep up with the latest C++ standards.

---

---

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

I love this talk, it is true gem. Old school, straight to the implementation. No BS 😀Loaded with knowledge and experience. Extra thing added, it considers embedded or more restricted environments. Loop unrolling through std::apply() is wild!

wojciechbartczak
Автор

I found some if this very insightful and helpful. I hadn't used std::any, std::variant, or any of the tools with them, but learning this has opened my eyes to trying them out later so I can remember them and hopefully keep in mind when and where to use them when applicable.

ChrisCarlos
Автор

I've been using std::variant for some time and found it extremely useful (as a type safe union or using it in a visitor). Along with optional this is best feature in C++17 IMO. I also implemented a number of classes similar to what std::any does but with some additional features and type constrains, but I am yet to find a use case for std::any itself.

stanbarvinsky
Автор

Well done presentation. Examples are simple and clear

Radioguy
Автор

Beautiful presentation. Such great examples

hsarasan
Автор

'Deducing this' with CRTP is sooo neat!

pawello
Автор

Hi Rud! I remember you from a meet-up group years ago. Glad to see you’re doing well. Cheers!

eric-seastrand
Автор

Pretty good talk so far, I have played with a lot of these things in my personal projects already. I guess std::function would qualify as runtime polymorphism though, the templates are the static (compile time) version.

multiHappyHacker
Автор

This is a great talk by him. Concise and solid communication

commander
Автор

If there's a library with this style for embedded i'd love get a look at it. Looks awesome and clean.
Regards
Jean-François

chrysalide_aero
Автор

Like his every man style. Credibility from the trenches.

stephenjames
Автор

Really good talk! Love to try these :)

niteshkumarsukumaran
Автор

Nice talk. I just want to provide a little correction: the CTAD line is needed prior to C++17, not C++20.( 21:26 )

gcvfune
Автор

We were taught cpp in 11th and 12th grade in turbo cpp. XD i recognise this screenshot very well.

KartikayKaul
Автор

I'm way younger, but turbo c++ was my first editor

junaid
Автор

Think you can use std::ref instead of pointers also in the vector

zxul
Автор

Nice one. Sad to see no comments here.

lombeelo
Автор

This is something I run into quite a lot, so I need to see if this will work for me. I too do embedded systems and the compilers are not as up to date as we'd like, Arduino is, if I recall correctly, C++ 14 and I need to do something like this for a hobby project so it's more than a good example in my case. And I ran into all kinds of weirdness, it seems that if you're having to force the language to abstract an interface, that perhaps that language isn't yet expressive enough to handle it, I would like dynamic polymorphic dispatch... that's true Object Oriented.

raymitchell
Автор

1:45 I spent thousands of hours using that IDE.

drescherjm
Автор

Same things I thought about last week 😂

protasov-by