Changing the template defintion syntax.
Jari-Matti Mäkelä
jmjmak at utu.fi.invalid
Mon Dec 17 17:13:42 PST 2007
On Sat, 15 Dec 2007, Robert DaSilva wrote:
> One thing that has bugged me for a while is the in symmetry of how
> template are defined and used. If template were defined with !() instead
> of () it would also allow multi-level template to be defined with out
> the "same name as template" kludge.
> For example
> U to!(U)!(T)(T t);
I think you're confusing a lot of things here. Changing the syntax isn't
enough to make the static parameters of a functions partially applicable.
Also I'm not sure if a change in the syntax is needed. You could achieve
the same thing with implicit currying.
Another thing is that what you're showing here isn't the only thing that
can be done with nested templates. The C++ style "anonymous"
parametrization is cleaner in this case, but in D you can also change
the declaration type inside the template:
template foo(int i) {
static if(i == 0)
class foo {}
else
int foo;
}
> And while on the note of to, it would be nice if cast used template
> syntax (as well as any keyword function that took or returned types
> (const, invariant, typeof, typeid, etc.)).
Why?
>
> Also the template keyword could be replace with a generic namespace keyword.
What? Templates form a namespace, but that doesn't mean templates are
equivalent to namespaces. What would be useful though is to be able to
instantiate templates with no parameters or templates with only parameters
with default values without using !() syntax. But then, how would one
differentiate between template symbol and instantiation.
>
> We could even let all definitions be templatable
> T template_variable!(T);
> I don't know how practicable or use full that would be though.
Huh?
More information about the Digitalmars-d
mailing list