Re: Templates for syntatic niceness only, does it waste space?
collection60@hotmail.com wrote:
If you're using the same code to manipulate many disparate pointer
types, chances are you're not doing much significant with them (e.g.,
you aren't using the interface for Fred, using them polymorphically,
etc.). So just declare the function inline, and things will likely be
the same (since "inline" is only a hint) as if you wrote that pointer
manipulating code in each place where you call the function.
Well, think of the hash_map class.
Let's say I have a hash_map relating strings to long*, another for
strings to Fred* and another for strings to X*.
Well, the code is entirely interchangable. I'd hope that the compiler
knows this. Know it seems that it doesn't?
(It's the custom here to put your reply inline or after the post you
are responding to. I fixed yours here.)
As Bo Persson said, it is more of a QoI issue as to whether the
compiler will actively combine code for classes and functions generated
from templates, but even with the STL, my point stands: most STL
containers' member functions (and those of soon-to-be STL containers
like hash_map, aka std::tr1::unordered_map) are inline by default,
which will often amount to the same thing as combining code.
Cheers! --M