2 ms·
For this particular left/right example a much cheaper alternative is to make the enum variants a 1st class citizen of the type system. Then the compiler will be
by the8472 7y ago
For this particular left/right example a much cheaper alternative is to make the enum variants a 1st class citizen of the type system. Then the compiler will be able to use the variant type information from one callsite to monomorphize all the uses without inlining.
- pron 7y agoYou're absolutely right, but the same general analysis applies. The example is contrived, but I want to show the principle (perhaps static variants would have made for a better example; oh, well).
- perfmode 7y agoThe example is merely used to motivate the principle. Let’s not miss the forest for the trees.
- kllrnohj 7y agoFor this particular example it'd be even easier to just put 'int foo(kind k, int x)' in the header so it's inlined & optimized at each call site anyway. Slap a constexpr on it so the compiler even yells at you if it can't resolve it at compile time for some reason.