www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Verifying the arguments of a function with ref parameters?

reply pineapple <meapineapple gmail.com> writes:
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
parent reply jdfgjdf <jdfgjdf jdfgjdf.ck> writes:
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
parent reply pineapple <meapineapple gmail.com> writes:
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
next sibling parent ZombineDev <petar.p.kirov gmail.com> writes:
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
prev sibling parent pineapple <meapineapple gmail.com> writes:
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);}));
Jul 28 2016