return type and templates

Jonathan M Davis jmdavisProg at gmx.com
Fri Nov 22 02:33:50 PST 2013


On Friday, November 22, 2013 11:24:30 bearophile wrote:
> Jonathan M Davis:
> > It's not going to work for the compiler to figure out what
> > types might work with a given template constraint and then
> > have it pick one when you don't tell the template what
> > type to be instantiated with.
> 
> It could work if the type system become more powerful, but what
> are the costs in compiler complexity, compilation times, and
> possible bugs in user code?

What's it going to do? Try ever type that it knows about and see which happens 
to work? Try every type that it sees in the template constraint (particularly 
those in is expressions) and see if any of them work? It's a feature which 
sounds like you're trying to write AI. I don't think that even makes sense to 
attempt it. If there's really a type that makes sense by default, then just 
give a default template argument. Why try and make the compiler more 
complicated, particularly when it's questionable that it's a solvable problem, 
and it's pretty much a guarantee that it would have a high efficiency cost even 
if you could pull it off.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list