[Issue 20246] isCallable fails for template opCall overload

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Sep 28 06:27:27 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=20246

Max Samukha <maxsamukha at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxsamukha at gmail.com

--- Comment #3 from Max Samukha <maxsamukha at gmail.com> ---
(In reply to Paul Backus from comment #2)

> One possible solution would be a trait like `isCallableWith!(S.init, int)`,
> that requires the user to specify the argument type(s). That way, we could
> just check with __traits(compiles) whether the call is valid or not.

That does not take into account rvalue-ness of the arguments:

void foo(ref int) {}
store
static if (isCallableWith!(typeof(1)))
    foo(1); // error

isCallableWith would have to accept the actual arguments, (type, rvalue-ness)
pairs, or both.

And if one implements isCallableWith for functions, he should also implement
isInstantiatableWith for templates. And that is a case for general
__traits(matchFunction/matchTemplate, symbol, args) that would return the
overloads callable/instantiatable with args.
isCallableWith/isInstantiatableWith could be built on that.

--


More information about the Digitalmars-d-bugs mailing list