Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
July 28, 2016 Verifying the arguments of a function with ref parameters? | ||||
---|---|---|---|---|
| ||||
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 Re: Verifying the arguments of a function with ref parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to pineapple | 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 Re: Verifying the arguments of a function with ref parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to jdfgjdf | 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 Re: Verifying the arguments of a function with ref parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to pineapple | 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 Re: Verifying the arguments of a function with ref parameters? | ||||
---|---|---|---|---|
| ||||
Posted in reply to pineapple | 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);}));
|
Copyright © 1999-2021 by the D Language Foundation