templatizing parameters and induction (was Re: Writing Bug-Free C/D Code)
David B. Held
dheld at codelogicconsulting.com
Thu Mar 22 23:48:06 PDT 2007
Andrei Alexandrescu (See Website For Email) wrote:
> [...]
> int foo(int x, int y, int z);
> int foo(static int x, int y, int z); // x is known during compilation
> int foo(int x, static int y, int z); // y is known during compilation
> int foo(static int x, static int y, int z); // x and y are... you know
> [...]
> final a = to!(int)(readln), b = to!(int)(readln);
> foo(a, b, b); // firsts overload
> foo(1, a + b, b); // 2nd
> foo(a + b, a - b, b); // 3rd
> foo(42, 7, b); // 4th
> [...]
Great sir, could you impart upon us mere mortals the wisdom by which you
are able to ascertain, at compile time, the difference between two
values known only at runtime (a la the "3rd" overload)? We are in great
need of such Oracle-like behavior.
Dave
More information about the Digitalmars-d
mailing list