how do I tell if something is lvalue?

tsbockman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Feb 1 14:20:03 PST 2016


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)


More information about the Digitalmars-d-learn mailing list