Template constraints in D

Walter Bright newshound1 at digitalmars.com
Sun Jun 22 19:23:27 PDT 2008


Bill Baxter wrote:
>> You can do that with a proxy object.
> 
> A) How exactly?  If you're going to claim it's equivalent, I think the 
> burden is on you to show an example of it.

The opDot feature allows one to wrap a type, override what you need to 
and forward the rest to the wrapped object.

> B) Whatever you have in mind, my hunch is that it is going to be 
> significantly more cumbersome.  For example in my code I like using 
> Vince's Vector.  I like his API.  But if I go with proxy objects then I 
> think that means either I have to use the proxy object (with Larry's 
> API) instead of Vince's Vector directly, or else every time I call 
> Larry's code I have to wrap my Vince Vector in a Larry VectorConcept 
> proxy wrapper.  Either way it's not ideal, and more cumbersome than just 
> writing down the mapping once in one central place.

Implicit casting casts from, and constructors cast to. That should 
handle it.


> Anyway, I think you need to find 
> someone who understands the ins and outs of C++0x concepts and discuss 
> with them face-to-face whether your plan for D covers all the bases 
> sufficiently or not.

It doesn't need to cover all the bases. It only has to cover the 
relevant useful ones. I should also point out that there are areas where 
D's constraint system is far more powerful (try doing isPrime() in C++).

One thing to keep in mind is C++ concepts are very complicated. There's 
a lot of grammar, a lot of explanation, a lot of special cases to 
understand. None of it has proven useful in production code (that will 
take years). You have to stack up that high implementation cost and high 
learning cost for programmers up against the utility of it - just what 
doors does it really open? Is it a paradigm changing feature? I don't 
see it.

On the other hand, constraints are trivial to implement, simple to 
understand (they build on what you already know - expressions), and 
arguably get the meat of what concepts do and extend it.




More information about the Digitalmars-d mailing list