In https://github.com/tiger40490/repo1/blob/cppProj/cppProj/HRT/messages.h my baseclass template is able to use a subclass field. This reusable technique is reusable in a very restrictive context —
- the base and sub classes represent market data messages, used in a reinterpret_cast context, with zero padding. Therefore, a proposed vptr would add a pointer and mess up reinterpret_cast.
- multiple (say 11) subclasses have a “qty” field, so I don’t want code duplication 11 times
- The order among the fields is fixed in struct definition. Without this restriction, I would define the “price” field in a base struct and also a getPrice() method. With a subclass instance, CRTP could probably work like static_cast<Subclass const*>(ptr)->getPrice() but the “price” field’s physical offset would be be dictated by the compiler not according to my struct definition
My technique uses CRTP but no SFINAE no enable_if.
My technique is easier to /internalize/, as it relies on simple overload resolution + simple type deduction. In contrast, the SFINAE technique used in my RTS codebase is off-putting and alien to me