Slides from my ACCU Silicon Valley talk

Jonathan M Davis jmdavisProg at gmx.com
Tue Dec 14 00:51:39 PST 2010


On Tuesday 14 December 2010 00:45:02 Don wrote:
> Walter Bright wrote:
> > bearophile wrote:
> >> Andrei:
> >>> D's constrained templates were introduced on 17 June 2008 and they've
> >>> been
> >>> a smashing hit. Virtually all of Phobos uses them, and I'm sure a lot
> >>> of generic client code. They take half a minute to explain and solve a
> >>> difficult problem in a very simple manner.<
> >> 
> >> A template with two constrains makes it less handy to add error
> >> messages that
> > 
> >> explain why the instantiation has failed:
> > Adding such error messages misses the point of constraints. The idea is
> > that template overloading is based on constraints. Given 3 templates
> > with 3 constraints, overload resolution picks the one with constraints
> > that pass. Giving error messages for the others is wrong.
> > 
> > If you want it to produce error messages if the instantiation is wrong,
> > the correct way is to use static asserts within the template body. No
> > additional features serve any purpose.
> 
> Actually I think there's considerable potential for better error messages.
> 
> Currently, if constraints fail for all templates, the error message
> prints the full constraint for the first template, which is not very
> helpful.
> A huge improvement would be to distinguish "no templates match at all",
> (eg the number of parameters is different)
> from "there are templates which would match, except that the template
> constraints fail".

Simply indicating that some of the templates' signatures match (or that none do) 
but that their constraints fail would be useful. Right now, you don't even know 
whether its the signature that doesn't match or whether it's the constraint that 
fails.

- Jonathan M Davis


More information about the Digitalmars-d mailing list