Infer return type from assignment
Steven Schveighoffer
schveiguy at yahoo.com
Wed Apr 11 15:01:50 UTC 2018
On 4/11/18 10:26 AM, ixid wrote:
> Is it possible to infer a template's return type from what it's assigned
> to? If not is this a difficult or worthless feature to add?
>
> OUT fun(IN, OUT)(IN value) {
> return value.to!OUT;
> }
>
> void main() {
> float a = 5.0;
> int b = fun(a);
> }
Sort of:
void fun(IN, OUT)(IN value, out OUT result)
{
result = value.to!OUT;
}
Other than that, it doesn't work.
-Steve
More information about the Digitalmars-d-learn
mailing list