I never understood this issue with templates. For me instantiating a method multiple types for different type of parameter is same as implementing the same in terms of function overloading. If this is the case how template causes the code bloat or exceeds the binary size to a certain limit. Please bring clarity into this.
Sometimes I am unsure whether to use templates or function overloading. Template code bloat is the problem I have heard of, but never understood.
How does template cause the code bloat in C++?
Code bloat occurs because compilers generate code for all templated functions in each translation unit that uses them. Back in the day, the duplicate code was not consolidated, which resulted in "code bloat". These days, the duplicate code can be removed at link time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With