4 ms·
Why would a C++ version involve method call overhead? Wouldn't C++ actually be more straightforward with its value-typed template parameters?
by ridiculous_fish 7y ago
Why would a C++ version involve method call overhead?
Wouldn't C++ actually be more straightforward with its value-typed template parameters?
- thenewwazoo 7y agoWith C++, wouldn't I need to either use a virtual base class with a typed template parameter (to emulate interfaces), or need to use duck-typed parameter and lose type safety?
- kccqzy 7y agoSprinkle in a bunch of std::enable_if to do SFINAE and that's it. It's a way to tell the compiler a certain function or method should be enabled only when some other compile-time condition is true.
- gmueckl 7y agoWhich of the two template arguments are you talking about? The enum-typed template argument will lead to a optimized specialization of the template. C++ does, however, have an unfortunate problem with restricting type parameters to types with certain properties/guarantees in ways that won't make the compiler explode in obtuse error messages.
- llukas 7y agostatic_assert, enable_if or just plain not providing default implementation and only specializations, as everything in C++ error messages is something you can customize to high extent...
- orbifold 7y agoYou don’t have to use a virtual base class. You can implement interfaces statically by passing in the implementation as a template parameter.
- comex 7y agoRust is getting value-typed template parameters Real Soon Now - in fact, they now work to some extent on nightly. In the parent’s example, my guess is that only the second parameter could be changed to a value, whereas the first is actually used somewhere as a type - but I have no context so it’s just a guess.