Q: What are the rules for emitting template code?

Jonathan M Davis jmdavisProg at gmx.com
Mon Oct 25 09:26:48 PDT 2010


On Monday, October 25, 2010 06:08:24 Austin Hastings wrote:
> On 10/24/2010 5:16 AM, Simen kjaeraas wrote:
> > Austin Hastings <ah08010-d at yahoo.com> wrote:
> >> If Decider uses Option1.sizeof, does any Option1 code get emitted?
> > 
> > For sizeof to be known, the template would have to be instantiated, yes.
> 
> Instantiated does not necessarily imply emitting code, I think. (Of
> course, this is why I asked - to find out the compiler behavior and
> expectations.)

They're exactly the same thing. When a template is instantiated, a copy of that 
template is created with the paramaters that it was given. The only reason new 
code wouldn't be emitted would be is if that particular set of parameters had 
already been used with that template and so there was no need to create it anew.

- Jonathan M Davis


More information about the Digitalmars-d mailing list