New blog post on the cost of compile time

Walter Bright newshound2 at digitalmars.com
Wed Jan 18 22:20:23 UTC 2023


On 1/17/2023 1:58 PM, H. S. Teoh wrote:
> If the
> language had instead been extended so that you could, for example,
> extract the return type of some given callable directly, say
> typeof(return(myfunc)), then none of this would have been necessary in
> the first place.

https://dlang.org/spec/expression.html#is_expression

     int func();

     static if (is(typeof(func) R == return))
         pragma(msg, R);

prints:

     int

The implementation of std.traits.ReturnType is:

     template ReturnType(alias func)
     if (isCallable!func)
     {
         static if (is(FunctionTypeOf!func R == return))
             alias ReturnType = R;
         else
             static assert(0, "argument has no return type");
     }

ReturnType can do a little more than the raw IsExpression, as it can identify:

     struct G
     {
         int opCall (int i) { return 1;}
     }



More information about the Digitalmars-d mailing list