Idea: Reverse Type Inference
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Wed May 24 08:02:05 PDT 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
More information about the Digitalmars-d
mailing list