top | item 47162476

(no title)

Panzerschrek | 4 days ago

Since std::variant was introduced I use inheritance and virtual calls much less than before. It's faster, since variant dispatch (via std::visit) is basically a switch statement with all execution paths visible to the compiler and thus inlining is possible. Inheritance and virtual calls are nowadays only necessary in places where it's not possible to statically list all alternatives (where the set of derived classes is open).

discuss

order

dalvrosa|3 days ago

Yeah for C++17 or above, it's a nicer and more performant alternative in most cases