Thread overview
Verifying the arguments of a function with ref parameters?
Jul 28, 2016
pineapple
Jul 28, 2016
jdfgjdf
Jul 28, 2016
pineapple
Jul 28, 2016
ZombineDev
Jul 28, 2016
pineapple
July 28, 2016
Why doesn't this code do what I'd expect it to, and how can I fix it?

    unittest{
        import std.traits : Parameters;
        // Works as expected
        alias dg = int delegate(int value);
        enum bool dgcallable = is(typeof((){dg(Parameters!dg.init);}));
        pragma(msg, dgcallable); // Prints true
        // Doesn't work as expected
        alias dgref = int delegate(ref int value);
        enum bool dgrefcallable = is(typeof((){dgref(Parameters!dgref.init);}));
        pragma(msg, dgrefcallable); // Prints false
    }

Thanks!
July 28, 2016
On Thursday, 28 July 2016 at 19:19:06 UTC, pineapple wrote:
> Why doesn't this code do what I'd expect it to, and how can I fix it?
>
>     unittest{
>         import std.traits : Parameters;
>         // Works as expected
>         alias dg = int delegate(int value);
>         enum bool dgcallable = is(typeof((){dg(Parameters!dg.init);}));
>         pragma(msg, dgcallable); // Prints true
>         // Doesn't work as expected
>         alias dgref = int delegate(ref int value);
>         enum bool dgrefcallable = is(typeof((){dgref(Parameters!dgref.init);}));
>         pragma(msg, dgrefcallable); // Prints false
>     }
>
> Thanks!

"Parameters!dgref.init" does not yield a reference. The real error is not displayed. In a normal context it would be "stuff is not callable with...."


July 28, 2016
On Thursday, 28 July 2016 at 20:28:39 UTC, jdfgjdf wrote:
> "Parameters!dgref.init" does not yield a reference. The real error is not displayed. In a normal context it would be "stuff is not callable with...."

What would be a better way to check whether some callable can be called using a parameters tuple?
July 28, 2016
On Thursday, 28 July 2016 at 21:49:00 UTC, pineapple wrote:
> On Thursday, 28 July 2016 at 20:28:39 UTC, jdfgjdf wrote:
>> "Parameters!dgref.init" does not yield a reference. The real error is not displayed. In a normal context it would be "stuff is not callable with...."
>
> What would be a better way to check whether some callable can be called using a parameters tuple?

http://dlang.org/phobos/std_traits#.lvalueOf
July 28, 2016
On Thursday, 28 July 2016 at 21:49:00 UTC, pineapple wrote:
> On Thursday, 28 July 2016 at 20:28:39 UTC, jdfgjdf wrote:
>> "Parameters!dgref.init" does not yield a reference. The real error is not displayed. In a normal context it would be "stuff is not callable with...."
>
> What would be a better way to check whether some callable can be called using a parameters tuple?

Oh, I answered my own question

    enum bool dgrefcallable = is(typeof((){auto params = Parameters!dgref.init; dgref(params);}));