Exceptional coding style

bearophile bearophileHUGS at lycos.com
Tue Jan 15 07:27:43 PST 2013


Artur Skawina:

> static assert(checkArgs!A(fmt), "Invalid or unsupported printf 
> args");

A template constraint is better, I think.


>You can't get any less overhead than this; not even when using a 
>"well designed
statically compiled language".<

Maybe if you compile that with dmd and you look in the binary I 
think you will find some stuff related to that that's not needed.


>> void foo(int x)(string s) {}
>
> A /run-time value known at compile-time/ is an oxymoron.
>
> How would your above function to differ from this one
> 'void foo(alias x)(string s) {}' ?
> Are you asking for 'void foo(alias int x)(string s) {}'?

That wasn't an important request, feel free to ignore it.

What I was trying to say is not impossible. The run-time 
semantics of this:

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

Is meant to be the same as:

void foo(int x, string s) {}

The only difference is that the compiler requires x to be 
statically known (but then you can't use specialize code on the 
value of x, because that's really not a template function).

This is also allowed, and it's similar to what we were discussing 
about:

void foo(static int x)(string s) if (predicate(x)) {}

Bye,
bearophile


More information about the Digitalmars-d mailing list