Q: What are the rules for emitting template code?

Austin Hastings ah08010-d at yahoo.com
Sat Oct 23 21:06:23 PDT 2010


Howdy,

This is a bit involved, so bear with me.

Suppose I have a template, Decider(Args...) and some other templates, 
Option1(...), Option2(...), etc.

The job of Decider() is to decide, based on the given parameters, which 
of the possible OptionN templates to use.

Decider uses "static if" and some builtins and maybe some CTFE to 
determine its result.

Now:

How much can Decider ask of one of the Option templates without that 
template being expensively realized?

Alternatively:

What parts of an Option template have to be realized for Decider to do 
its job?

In particular:

If Decider uses Option1.sizeof, does any Option1 code get emitted?

If Decider uses some external function that makes use of type aliases in 
Option1, (example:  Option1() { alias byte value_t; } ) does any Option1 
code get emitted?

If Decider uses some function defined inside the same module with 
Option1, but NOT inside of Option1, does any/all of the Option1 code get 
emitted?

If Decider uses a static method of Option1, does any more of the Option1 
code get emitted?



Obviously, I am trying to ... decide ... how to do compile time 
selection. But I'm also just a tad curious at the internals of the 
template engine.

Thanks,

=Austin


More information about the Digitalmars-d mailing list