www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Simplifying templates

reply dfgh <dfgh mailinator.com> writes:
Kagamin Wrote:

 how do you plan to infer types?

What needs to be inferred? The type would be written wherever it is needed.
Nov 30 2008
next sibling parent Kagamin <spam here.lot> writes:
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.
Nov 30 2008
prev sibling parent reply Kagamin <spam here.lot> writes:
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.
Nov 30 2008
parent dfgh <dfgh mailinator.com> writes:
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
Nov 30 2008