3 ms·
Hand-coding multiple versions of a function or class to accommodate various types would be just as bad in terms of code size, no? Plus it'd be tedious and error
by kjgkjhfkjf 8y ago
Hand-coding multiple versions of a function or class to accommodate various types would be just as bad in terms of code size, no? Plus it'd be tedious and error-prone to do this.
- Negitivefrags 8y agoIn practice most of the time you would just write a generic version using one of the other mechanisms. Virtual functions, void* and casting, type ids, or whatever. Just like everything else, it's a time/space tradeoff because it generates less optimal code in exchange for a smaller binary size.
- cbsmith 8y agoThere's actually a pretty well established design pattern about wrapping one of those methods with the template class, thereby allowing type safety checks and such whilst still minimizing bloat.