C++20 & Rust on Static vs Dynamic Generics

preview_player
Показать описание
Demo of static vs dynamic generics with C++20 concepts & virtual methods and with Rust traits.
Рекомендации по теме
Комментарии
Автор

That thing about fat pointers blew my mind. It solves the double indirection problem. Amazing!

ciberman
Автор

C++ 20 syntax is virtually unrecognizable to someone like myself, who studied C++ in college. Like I can barely follow it because so many new structures and features have been introduced to the language. How do C++ programmers keep it all in their heads?

MrBranh
Автор

I like your videos, and you have too little subscribers. So, the way you can organically improve that is to add tags/keywords on videos. So that the youtube algorithm pick them up.
Also, add a little message encouraging people to like the videos. It can be as nuance as you want, but that works for people that like what they are seeing.
And if you want you could use a github repo, and keep your examples there giving you an additional audience. Which can collide with the youtube one.
Great videos, keep up the good work.

TheMoisex
Автор

You could use std::variant to create a heterogeneous container at compile time.

HendrikNiemeyer
Автор

I'm surprised why you didn't write your Rust function like:
*fn area_per_perimeter(shape: &dyn ShapeImpl) -> f64 {..}* for dynamic dispatch.
and,
*fn area_per_perimeter(shape: impl ShapeImpl) -> f64 {..}* for static dispatch.
Lest it makes it look like it's a hack to choose one type of dispatch over the other and not something properly supported.

comradepeter
Автор

Why are you using virtual inheritance?

HenrikxF
Автор

Great video! It's good to see some videos including concepts from the C++20 standard.

I think you may have glossed over the fact that in Rust you are forced to use traits, while C++ doesn't force you to use concepts. If you chose to implement dynamic dispatch first, the C++ would require more work to convert it to concepts, while Rust would require some regex find+replace.

That may be over simplifying on my part, but Rust does seem to push you in the right direction most of the time.

jaysistar
Автор

7:34 - just a minor hint (even if you probably already know), but another trait could have been created, like AreaPerPerimeter, and that trait could have been implemented for all T: Shape + ?Sized,
So then on the call side they could keep being method calls.

swfsql
Автор

if you remove "OOP" from "C" and add typeclasses mechanism from "Haskell" to "C" you'll get "rust", easy stuff

DjLeonSKennedy
Автор

Just subbed, thanks for the explanation!

bamtoday
Автор

Can anyone explain to me why did he use, for example, “auto area() const -> double” instead of just “double area() const”?

omokokkoro
Автор

You program like someone who knows how to.
By the way, you could have mentioned static polymorphism too. This discards the virtual table and uses templates at compile time to pass the correct class to the parent class.

akj
Автор

Shape is a common example, but its one that's deeply flawed if you so much as scratch the surface of it.

khatdubell
Автор

tried to write a sand-box game with dynamic dispatch. Decided that it is an anti-pattern and against the whole idea of zero cost abstractions. A simple lookup matrix is good enough for dispatch. No need for virtual or anything.

teenspirit
Автор

Hi, what is your choice for today, Rust or C++ ? :) BTW: interesting video

radeksmola
Автор

Demo is incomplete without also comparing std::variant+std::visit.

sizur
Автор

I think the fat pointer concept in Rust is directly borrowed from Cyclone. It's such a shame that language never took off. Instead, we wasted so much time with C99...

EvanBC
Автор

Does C++20 come with lambda functions? (Closures in Rust)

____-gymq
Автор

Great video, I'm a rust guy. Have never really dived into C++, but the syntax looks incredibly verbose.

dan
Автор

now what are concepts.... sighs. C++ leaving me behind again

JoshuaKisb