Template namespaces - Obsolete?
BCS
BCS at pathlink.com
Wed Sep 19 14:31:39 PDT 2007
Janice Caron wrote:
> Now that we can do:
> class A(T);
> struct A(T);
> union A(T);
> T func(T)(T x);
> static int func(int n);
> ...
> etc.
>
> Is there any need, any more, for the old fashioned
>
> template t(T)
> {
> int f();
> int g();
> }
>
> and having to refer to t!(T).f() and t!(T).g() ?
>
> I almost think it would suffice to complete the new notation with
> obvious extensions like
> typedef(T) something t; /* == template t(T) { typedef something t; } */
> alias(T) something t; /* == template t(T) { typedef something t; } */
> enum(T) t : T {...}; /* == template t(T) { enum t : T {...}; } */
> int a(int N)[N]; /* == template a(int N) { int a[N]; } */
>
> (Not too sure about the usefulness of that last one, but I include if
> for completion).
>
> and then deprecate the old namespace notation.
>
> The namespace notation is very useful for defining mixins though, and
> perhaps that has now become its primary purpose. If that functionality
> is ever replaced by "macro", what then?
one other use of it is where a collection of things needs to be passed
around
template Foo(char[] str)
{
const char[] post = str[IndexOfFirst(':').In(str)..$];
const char[] pre = str[0..pre.length];
}
alias Foo!("hello:world") bar;
bar.pre;
bar.post;
dparse uses this to build parse trees at compile time*.
* actually it puts them inside a struct but that is to work around a bug
in DMD and causes a host of other issues.
More information about the Digitalmars-d
mailing list