On 2/1/16 5:20 PM, tsbockman wrote:
On Sunday, 31 January 2016 at 22:11:45 UTC, Steven Schveighoffer wrote:
Thanks! I was surprised this is not straightforward.

-Steve

For function return values, at least, you can do this:

import std.traits, std.stdio;

int foo()
{
     return 0;
}

ref int bar()
{
     static int x = 0;
     return x;
}

enum isRetByRef(alias func) = (functionAttributes!func &
FunctionAttribute.ref_) != 0;

void main()
{
     writeln("foo: ", isRetByRef!foo);
     writeln("bar: ", isRetByRef!bar);
}

(DPaste: http://dpaste.dzfl.pl/2aa8d3553a12)

Thanks. In my case, I need to treat fields and properties that return by ref the same way.

What I wanted essentially was a template constraint that says "this type has a member named foo, and t.foo is an lvalue"

-Steve

Reply via email to