Thread overview
Re: Simplifying templates
Nov 30, 2008
dfgh
Nov 30, 2008
Kagamin
Nov 30, 2008
Kagamin
Nov 30, 2008
dfgh
November 30, 2008
Kagamin Wrote:

> how do you plan to infer types?

What needs to be inferred? The type would be written wherever it is needed.
November 30, 2008
dfgh Wrote:

> Kagamin Wrote:
> 
> > how do you plan to infer types?
> 
> What needs to be inferred? The type would be written wherever it is needed.

That will be too verbose. May be I misused the term. In http://www.digitalmars.com/d/2.0/template.html it's called argument deduction. See Function Templates section where Square(3) is deduced to be Square!(int)(3). This is a nice feature.
November 30, 2008
And you'd better get acquainted with
http://www.digitalmars.com/d/2.0/template.html
http://www.digitalmars.com/d/2.0/template-mixin.html
http://www.digitalmars.com/d/2.0/templates-revisited.html
http://www.digitalmars.com/d/2.0/variadic-function-templates.html
http://www.digitalmars.com/d/2.0/template-comparison.html
and figure out whether you proposal barely covers all D templates use cases.
November 30, 2008
Kagamin Wrote:

> And you'd better get acquainted with
> http://www.digitalmars.com/d/2.0/template.html
> http://www.digitalmars.com/d/2.0/template-mixin.html
> http://www.digitalmars.com/d/2.0/templates-revisited.html
> http://www.digitalmars.com/d/2.0/variadic-function-templates.html
> http://www.digitalmars.com/d/2.0/template-comparison.html
> and figure out whether you proposal barely covers all D templates use cases.

I have read all those pages. My proposal would be compatible with them. About your other question, instead of writing:

T Square(T)(T t)
{
    return t * t;
}

writefln("The square of %s is %s", 3, Square(3));

we would write:

T Square(type T, T t)
{
    return t * t;
}

writefln("The square of %s is %s", 3, Square(3));

If a non-type argument is used in place of a type that will occur later in the parameter list, we just skip the type and infer it later. It works just as well as the current approach. If you think it would be too confusing, you can put all your types before any non-types; it would just be syntactic sugar on what we have now.

--Sam