Template params: decl vs instantiation syntax
Daniel Gibson
metalcaedes at gmail.com
Thu Oct 7 04:23:41 PDT 2010
Nick Sabalausky schrieb:
> A trivial thing, but something I've been wondering about for awhile:
>
> Function parameter syntax:
> Declare: foo(bar)
> Call: foo(bar)
>
> Template parameter syntax in C++/C#/etc:
> Declare: foo<bar>
> Instantiate: foo<bar>
>
> Template parameter syntax in D:
> Declare: foo(bar)
> Instantiate: foo!(bar)
>
> Why the difference in syntax between declaring and instantiating? Why not
> use the exclamation for declaration too? Would that create a grammar
> ambiguity? Some other reason? No particular reason?
>
> Obviously it's not a big issue, just curious.
>
>
because:
import std.stdio;
void fun(int X=3)(int a = 4){
writefln("X==%s a==%s", X, a);
}
void main() {
fun!(1)(2); // X==1, a==2
fun(2); // X==3, a==2
fun!(2); // X==2, a==4
}
Cheers,
- Daniel
More information about the Digitalmars-d
mailing list