What's wrong with D's templates?

yigal chripun yigal100 at gmail.com
Mon Dec 21 23:09:24 PST 2009


Walter Bright Wrote:

> Yigal Chripun wrote:
> > But that doesn't mean the idea itself isn't valid. Perhaps a different 
> > language with different goals in mind can provide a much simpler non 
> > convoluted implementation and semantics for the same idea?
> > You've shown in the past that you're willing to break backward 
> > compatibility in the name of progress and experiment with new ideas. You 
> > can make decisions that the C++ committee will never approve.
> > 
> > Doesn't that mean that this is at least worth a shot?
> 
> I believe that D's template constraint feature fills the bill, it does 
> everything Concepts purported to do, and more, in a simple and easily 
> explained manner, except check the template body against the constraint.
> 
> The latter is, in my not-so-humble opinion, a desirable feature but its 
> desirability is overwhelmed by the payment in complexity and 
> constrictions on the Concepts necessary to make it work.

could you please expand on what are the main issues with implementing that check? 
I also wonder what's the situation regarding this in other languages - C# has constraints IIRC - is the check performed there? 

IMO cconstraints are neat but they aren't perfect. For one, they need to be repeated for each template, it would be very awesome if that could be moved to the parameter of the template so instead of: 

template foo(T) if isRange!T ...
template bar(T) if isRange!T ... 

you could write something like: 
struct Range if ... {}
template foo(r : Range) ...
template bar(r : Range) ...

inside both templates the parameter r satisfies all the constraits of Range. 

does that sound reasonable at all?



More information about the Digitalmars-d mailing list