Exceptional coding style

bearophile bearophileHUGS at lycos.com
Tue Jan 15 05:25:28 PST 2013


Artur Skawina:

> You can't both avoid template bloat *and* statically check the 
> arguments.

In a well designed statically compiled language you don't need to 
instantiate templates and let them generate binary code to 
statically verify a condition. What's needed to test compile time 
arguments is just some compile-time computation; there is no need 
for such computation to leave any trace in the resulting binary. 
Beside the idea of "ghost types" (it's not a Pokemon), see also 
this little thread:

http://forum.dlang.org/thread/nxhsgwliuwdgidaoudud@forum.dlang.org

D needs ways to avoid some template bloat in the first place, not 
just to remove it later.

In some cases I'd like to write code like this, but to not let 
this generate different template instantiations (this means x is 
really a run-time value, but it's required to be known at 
compile-time):

void foo(int x)(string s) {}

Bye,
bearophile


More information about the Digitalmars-d mailing list