digitalmars.D.learn - Verifying the arguments of a function with ref parameters?
- pineapple (16/16) Jul 28 2016 Why doesn't this code do what I'd expect it to, and how can I fix
- jdfgjdf (4/20) Jul 28 2016 "Parameters!dgref.init" does not yield a reference. The real
- pineapple (3/6) Jul 28 2016 What would be a better way to check whether some callable can be
- ZombineDev (2/8) Jul 28 2016 http://dlang.org/phobos/std_traits#.lvalueOf
- pineapple (4/10) Jul 28 2016 Oh, I answered my own question
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!
Jul 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...."
Jul 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?
Jul 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?
Jul 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:Oh, I answered my own question enum bool dgrefcallable = is(typeof((){auto params = Parameters!dgref.init; dgref(params);}));"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?
Jul 28 2016