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

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, and std::visit is used for dynamic dispatch.

And CRTP?

Show that CRTP creates unrelated types that cannot be held in a container.

Allocators

std::string_view

  • Use as parameters instead of std::string

  • Never as member (obviously)

More

Dependencies

cluster_cxx03 C++ cluster_cxx03_inheritance_oo Inheritance And Object Oriented Design cluster_cxx03_data_encapsulation Data Encapsulation cluster_c The C Programming Language cluster_c_introduction Introduction cluster_cxx11 The New C++ (11-…) cluster_cxx11_embedded_problems Embedded Problems? Code Bloat? Type Erasure? Solutions? cluster_cxx11_miscellaneous Miscellaneous cxx03_introduction Introduction c_introduction_installation Installation cxx03_introduction->c_introduction_installation cxx03_inheritance_oo_virtual_method Virtual Methods cxx03_inheritance_oo_basics Inheritance Basics cxx03_inheritance_oo_virtual_method->cxx03_inheritance_oo_basics cxx03_inheritance_oo_interface C++ “Interfaces” cxx03_inheritance_oo_interface->cxx03_inheritance_oo_virtual_method cxx03_inheritance_oo_polymorphism Polymorphic Usage Of Objects cxx03_inheritance_oo_interface->cxx03_inheritance_oo_polymorphism cxx03_inheritance_oo_virtual_destructor Virtual Destructors cxx03_inheritance_oo_interface->cxx03_inheritance_oo_virtual_destructor cxx03_inheritance_oo_polymorphism->cxx03_inheritance_oo_virtual_method cxx03_inheritance_oo_virtual_destructor->cxx03_inheritance_oo_virtual_method cxx03_inheritance_oo_virtual_destructor->cxx03_inheritance_oo_polymorphism cxx03_inheritance_oo_destructor Destructors And Inheritance cxx03_inheritance_oo_virtual_destructor->cxx03_inheritance_oo_destructor cxx03_inheritance_oo_destructor->cxx03_inheritance_oo_basics cxx03_data_encapsulation_ctor_dtor More Constructors, Destructors cxx03_inheritance_oo_destructor->cxx03_data_encapsulation_ctor_dtor cxx03_data_encapsulation_classes_objects Classes and Objects cxx03_inheritance_oo_basics->cxx03_data_encapsulation_classes_objects cxx03_data_encapsulation_ctor_default Default Constructor cxx03_data_encapsulation_ctor_dtor->cxx03_data_encapsulation_ctor_default cxx03_data_encapsulation_ctor_custom Custom Constructor cxx03_data_encapsulation_ctor_dtor->cxx03_data_encapsulation_ctor_custom cxx03_data_encapsulation_classes_objects->cxx03_introduction cxx03_data_encapsulation_c Object Oriented Programming In Good Ol’ C cxx03_data_encapsulation_classes_objects->cxx03_data_encapsulation_c cxx03_data_encapsulation_c->cxx03_introduction cxx03_data_encapsulation_ctor_default->cxx03_data_encapsulation_ctor_custom cxx03_data_encapsulation_ctor_custom->cxx03_data_encapsulation_classes_objects cxx11_embedded_problems_variant_manual_visit std::variant (Manual Virtual Dispatch, Using std::visit) cxx11_embedded_problems_variant_manual_if std::variant (Manual Virtual Dispatch, Using if) cxx11_embedded_problems_variant_manual_visit->cxx11_embedded_problems_variant_manual_if cxx11_embedded_problems_classic_virtual Classic Virtual cxx11_embedded_problems_classic_virtual->cxx03_inheritance_oo_interface cxx11_embedded_problems_virtual_vs_nonvirtual Replacing virtual With std::variant<> (In Real Life) cxx11_embedded_problems_virtual_vs_nonvirtual->cxx03_inheritance_oo_interface cxx11_miscellaneous_variant New-Style Union: std::variant cxx11_embedded_problems_virtual_vs_nonvirtual->cxx11_miscellaneous_variant cxx11_embedded_problems_related_no_virtual Non-Virtual, But Related cxx11_embedded_problems_related_no_virtual->cxx11_embedded_problems_classic_virtual cxx11_embedded_problems_unrelated Unrelated (Duck-Typed) cxx11_embedded_problems_unrelated->cxx11_embedded_problems_related_no_virtual cxx11_embedded_problems_variant_automatic_visit std::variant (Automatic Virtual Dispatch Using Template Method) cxx11_embedded_problems_variant_automatic_visit->cxx11_embedded_problems_variant_manual_visit cxx11_embedded_problems_variant_manual_if->cxx11_embedded_problems_unrelated cxx11_embedded_problems_variant_manual_if->cxx11_miscellaneous_variant