May 24, 2017
On Wednesday, 24 May 2017 at 13:03:37 UTC, Steven Schveighoffer wrote:
> This is different. It's IFTI based on return type.

Well, the way I see it it is a special case of top-down type inference. Yes, you also have to instantiate the template, but I assume that happens after type inference is complete?

So my point was more: why not cover the general case, if you are going to add it as a feature?

> auto p = Point(row.get("x"), row.get("y")); // with better IFTI

Ok, well, I see templates in this context as a variation of overloading, just with the template parametric type being a set of types i.e. all types that the program provides, minus the ones prevented by contraints.  I guess it is a matter of vantage point.

It would be odd to allow this for templates only and not provide it for functions...

May 24, 2017
On 5/24/17 10:28 AM, Ola Fosheim Grøstad wrote:
> On Wednesday, 24 May 2017 at 13:03:37 UTC, Steven Schveighoffer wrote:
>> This is different. It's IFTI based on return type.
>
> Well, the way I see it it is a special case of top-down type inference.
> Yes, you also have to instantiate the template, but I assume that
> happens after type inference is complete?
>
> So my point was more: why not cover the general case, if you are going
> to add it as a feature?
>
>> auto p = Point(row.get("x"), row.get("y")); // with better IFTI
>
> Ok, well, I see templates in this context as a variation of overloading,
> just with the template parametric type being a set of types i.e. all
> types that the program provides, minus the ones prevented by
> contraints.  I guess it is a matter of vantage point.
>
> It would be odd to allow this for templates only and not provide it for
> functions...
>

I believe that IFTI would be much more straightforward than overloading, because there is no concern about implicit conversion.

-Steve
May 24, 2017
On 5/24/17 10:58 AM, Steven Schveighoffer wrote:
> On 5/24/17 10:28 AM, Ola Fosheim Grøstad wrote:
>> Ok, well, I see templates in this context as a variation of overloading,
>> just with the template parametric type being a set of types i.e. all
>> types that the program provides, minus the ones prevented by
>> contraints.  I guess it is a matter of vantage point.
>>
>> It would be odd to allow this for templates only and not provide it for
>> functions...
>>
>
> I believe that IFTI would be much more straightforward than overloading,
> because there is no concern about implicit conversion.

In fact, you could simulate overloading of return values based on IFTI instantiation:

void fooImpl(ref int retval, int x) { ... }
void fooImpl(ref string retval, int x) { ... }

T foo(T)(int x) { T t; fooImpl(t, x); return t; }
int x = foo(1);
string y = foo(2);

-Steve

June 03, 2017
On Wednesday, 24 May 2017 at 15:02:05 UTC, Steven Schveighoffer wrote:
> In fact, you could simulate overloading of return values based on IFTI instantiation:
>
> void fooImpl(ref int retval, int x) { ... }
> void fooImpl(ref string retval, int x) { ... }
>
> T foo(T)(int x) { T t; fooImpl(t, x); return t; }
> int x = foo(1);
> string y = foo(2);
>
> -Steve

https://dpaste.dzfl.pl/7d8351fe2f07

What am I doing wrong?
June 05, 2017
On 6/3/17 7:37 PM, Enamex wrote:
> On Wednesday, 24 May 2017 at 15:02:05 UTC, Steven Schveighoffer wrote:
>> In fact, you could simulate overloading of return values based on IFTI
>> instantiation:
>>
>> void fooImpl(ref int retval, int x) { ... }
>> void fooImpl(ref string retval, int x) { ... }
>>
>> T foo(T)(int x) { T t; fooImpl(t, x); return t; }
>> int x = foo(1);
>> string y = foo(2);
>
> https://dpaste.dzfl.pl/7d8351fe2f07
>
> What am I doing wrong?

You are not realizing that my example requires IFTI on return types, something that I proposed but is not implemented ;)

-Steve
1 2
Next ›   Last »