return type and templates

Andrea Fontana nospam at example.com
Fri Nov 22 02:50:57 PST 2013


On Friday, 22 November 2013 at 10:34:12 UTC, Jonathan M Davis 
wrote:
> 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

I just mean:

int t = s.value;  // Means  int t = s.value!int;

If there's a problem with template instantiatio is the same we 
have now.
Now I have to write:

int t = s.value!int;

so if there's a problem with !int, it's just like now.

It's just a syntactic sugar, no new feature... Am I wrong?





More information about the Digitalmars-d-learn mailing list