Embedded Problems? Code Bloat? Type Erasure? Solutions?¶
virtual
Is Bad. Is virtual
Bad? (Type Erasure)¶
Type erasure appears to be a C++ hype currently. Speakers on C++ conferences beat each others in creating incomprehensible crap that solves no obvious problem. This is my personal attempt to create another solution to an unknown problem.
Showing options to eliminate virtual
, landing in
Type Erasure (Static vs. Dynamic Polymorphism), CRTP
- Why Replace
virtual
? - Classic Virtual
- Non-Virtual, But Related
- Unrelated (Duck-Typed)
std::variant
(Manual Virtual Dispatch, Usingif
)std::variant
(Manual Virtual Dispatch, Usingstd::visit
)std::variant
(Automatic Virtual Dispatch Using Template Method)- Type Erasure (Static vs. Dynamic Polymorphism), CRTP
See that livehacked
Another attempt is that one:
Note
TODO
Strip down the hacking story to a minimum. It is sufficient to
Show that a
std::vector
of (smart) pointers to polymorphic object is sub-optimal, memory-wise (and cache-performance-wise)Show the final version where a
std::variant
holds unrelated types, andstd::visit
is used for dynamic dispatch.
And CRTP?¶
Show that CRTP creates unrelated types that cannot be held in a container.
Allocators¶
Arena allocators
Modern C++: C++ Patterns to Make Embedded Programming More Productive - Steve Bush - CppCon 2022 (44:30)
std::string_view¶
Use as parameters instead of
std::string
Never as member (obviously)
More¶
Modern C++: C++ Patterns to Make Embedded Programming More Productive - Steve Bush - CppCon 2022
The Most Important Optimizations to Apply in Your C++ Programs - Jan Bielak - CppCon 2022
C++ in Constrained Environments - Bjarne Stroustrup - CppCon 2022
Using Modern C++ to Eliminate Virtual Functions - Jonathan Gopel - CppCon 2022