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

  Рет қаралды 26,001

CppCon

CppCon

4 ай бұрын

cppcon.org/
---
A Journey Into Non-Virtual Polymorphism addressing std::any, std::variant and visit, std::tuple and apply, and CRTP. - Rudyard Merriam - CppCon 2023
github.com/CppCon/CppCon2023
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.
Rud wrote his first FORTRAN IV in 1968 and his first C++ in 1990 with Borland's Turbo C++. During his career, he worked mainly with embedded systems, with one system measuring the flow in real pipelines. Since retirement, he has used C++ with multiple NASA Centennial Challenges of robotics on Mars and the Moon. He sporadically writes about C++ on Medium.com.
---
Videos Filmed & Edited by Bash Films: www.BashFilms.com
KZbin Channel Managed by Digital Medium Ltd: events.digital-medium.co.uk
---
Registration for CppCon: cppcon.org/registration/
#cppcon #cppprogramming #cpp

Пікірлер: 39
@wojciechbartczak3109
@wojciechbartczak3109 4 ай бұрын
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!
@ChrisCarlos64
@ChrisCarlos64 4 ай бұрын
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.
@Radioguy00
@Radioguy00 4 ай бұрын
Well done presentation. Examples are simple and clear
@hsarasan
@hsarasan 2 ай бұрын
Beautiful presentation. Such great examples
@stanbarvinsky1011
@stanbarvinsky1011 4 ай бұрын
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.
@makaedg
@makaedg 4 ай бұрын
Agree, C++17 gave us so much elements from functional programming. I also really like to use fold expressions. C++ is awesome
@mfc1190
@mfc1190 4 ай бұрын
I haven’t used std::variant before, but I use std::optional sometimes when it’s appropriate, I’d like to check this out!
@pawello87
@pawello87 2 ай бұрын
'Deducing this' with CRTP is sooo neat!
@eric-seastrand
@eric-seastrand 4 ай бұрын
Hi Rud! I remember you from a meet-up group years ago. Glad to see you’re doing well. Cheers!
@samuelsrikar2870
@samuelsrikar2870 4 ай бұрын
Amazing talk. Loved it :D
@commander7023
@commander7023 4 ай бұрын
This is a great talk by him. Concise and solid communication
@niteshkumarsukumaran
@niteshkumarsukumaran 4 ай бұрын
Really good talk! Love to try these :)
@KartikayKaul
@KartikayKaul Ай бұрын
We were taught cpp in 11th and 12th grade in turbo cpp. XD i recognise this screenshot very well.
@multiHappyHacker
@multiHappyHacker 4 ай бұрын
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.
@jfsimon1981
@jfsimon1981 4 ай бұрын
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
@johnwellbelove148
@johnwellbelove148 4 ай бұрын
My OSS library may be useful to you. It has many STL features, but uses no dynamically allocated memory. I've been maintaining it since 2014. Search 'Embedded Template Library'
@marcoradovancovici1312
@marcoradovancovici1312 4 ай бұрын
Cool stuff!
@user-gc5vf7un7e
@user-gc5vf7un7e 4 ай бұрын
Nice talk. I just want to provide a little correction: the CTAD line is needed prior to C++17, not C++20.( 21:26 )
@stephenjames2951
@stephenjames2951 4 ай бұрын
Like his every man style. Credibility from the trenches.
@MartinCordova
@MartinCordova 4 ай бұрын
What a good way to express it
@RudMerriam
@RudMerriam 3 ай бұрын
Thanks! I didn't realize it, but that is exactly how I wanted it to sound. "Shucks, I'm just another developer talking about m' code."
@lombeelo8780
@lombeelo8780 4 ай бұрын
Nice one. Sad to see no comments here.
@junaid1464
@junaid1464 3 ай бұрын
I'm way younger, but turbo c++ was my first editor
@raymitchell9736
@raymitchell9736 4 ай бұрын
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.
@johnwellbelove148
@johnwellbelove148 4 ай бұрын
My OSS library may be useful to you. It has many STL features, but uses no dynamically allocated memory. I've been maintaining it since 2014. Search 'Embedded Template Library'
@drescherjm
@drescherjm 4 ай бұрын
1:45 I spent thousands of hours using that IDE.
@protasov-by
@protasov-by 4 ай бұрын
Same things I thought about last week 😂
@randfur
@randfur 4 ай бұрын
35:50 for code.
@CartoType
@CartoType 3 ай бұрын
Interesting but I can’t see the reason for not using virtual functions.
@randomname-cc9hc
@randomname-cc9hc 24 күн бұрын
Virtual functions require virtual table, which increases size of every single object of given class. Also, calls of such functions are slower, because instead of straightforward functon call we need to look up into vtable and only then call suitable implementation. This is negligible for most cases, but for embedded systems or other constrained enviroments such solution can significantly improve perfomance of program
@imrank340
@imrank340 4 ай бұрын
This old-Timer saying something about C++ programming but I cant figure out where IS start and where is an End? Bit hard to understand.
@josefpharma4714
@josefpharma4714 4 ай бұрын
From a C++ experimental perspective: Nice. From real coding perspective: Too complex for nearly nothing. 😀
@toolazytobeoriginal4587
@toolazytobeoriginal4587 4 ай бұрын
Wait so is it too complex for basically any project or is it simple enough for basically anything?
@makaedg
@makaedg 4 ай бұрын
I used CRTP in the production code this week.
@andrewf8366
@andrewf8366 4 ай бұрын
There are plenty of times that this kind of polymorphism is massively simpler than alternatives.
@StanleyPinchak
@StanleyPinchak 4 ай бұрын
Deducing This is going to be a game changer for currying and mixins. I use std::variant + overload in my own production code and I am excited to see the static polymorphism capabilities of C++23 reduce both boilerplate and cognitive load. This will lead to much greater acceptance of these tools in community.
@josefpharma4714
@josefpharma4714 4 ай бұрын
@@toolazytobeoriginal4587 I would not use it in real projects. IMHO: Code should be optimized for easy reading. Many years ago when I went through the C++ Standard (2003) I liked coding C++ on its boundaries and find the most clever (I thought at this time) solutions. But this is not easy to read - you could say it’s a skill issue, but you need to assume typically skilled c++ developers. And most of them are not even familiar with e.g. template specialization - specially in embedded.
Joven bailarín noquea a ladrón de un golpe #nmas #shorts
00:17
Тяжелые будни жены
00:46
К-Media
Рет қаралды 5 МЛН
Como ela fez isso? 😲
00:12
Los Wagners
Рет қаралды 26 МЛН
How to write SOLID C++
29:22
platis.solutions
Рет қаралды 36 М.
Constructors Are Broken
18:16
Logan Smith
Рет қаралды 99 М.
Better Code: Runtime Polymorphism - Sean Parent
57:33
NDC Conferences
Рет қаралды 70 М.
CppCon 2018: Andrei Alexandrescu “Expect the expected”
58:58
1 Problem, 4 C++'s
7:16
code_report
Рет қаралды 34 М.
A Comprehensive Guide to Using Zoyya Tools for Photo Editing
0:50
ПРОБЛЕМА МЕХАНИЧЕСКИХ КЛАВИАТУР!🤬
0:59
Корнеич
Рет қаралды 3,4 МЛН
Apple, как вас уделал Тюменский бренд CaseGuru? Конец удивил #caseguru #кейсгуру #наушники
0:54
CaseGuru / Наушники / Пылесосы / Смарт-часы /
Рет қаралды 4,4 МЛН
wyłącznik
0:50
Panele Fotowoltaiczne
Рет қаралды 22 МЛН