how do I tell if something is lvalue?

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Feb 1 13:54:29 PST 2016


On Monday, 1 February 2016 at 20:53:35 UTC, Artur Skawina wrote:
> On 02/01/16 21:42, Artur Skawina wrote:
>> On 02/01/16 20:47, Meta via Digitalmars-d-learn wrote:
>>> That looks much nicer. It still needs work to properly handle 
>>> functions with non-empty argument lists.
>> 
>> Then it gets a bit long for a one-liner ;)
>> 
>>    enum isLvalue(A...) = is(typeof((ref _){}(A[0](A[1..$])))) 
>> || is(typeof((ref _){}(A[0])));
>
> And it's of course wrong in case there is a zero-args 
> ref-returning overload present. So...
>
>    enum isLvalue(A...) = A.length>1?is(typeof((ref 
> _){}(A[0](A[1..$])))):is(typeof((ref _){}(A[0])));
>
>
> artur

Hmm, I think it can be simplified by replacing `A[0](A[1..$])` 
with `A(Parameters!A.init)`. Then the whole thing becomes:

enum isLvalue(alias A) = is(typeof((ref _) {} 
(A(Parameters!A.init))));


*However*, we then run into this problem:

int n;

ref int returnN(int, float, bool) { return n; }
ref int returnN() { return n; }

static assert(isLvalue!returnN);


If I remember correctly this will just check the first returnN 
declaration.


More information about the Digitalmars-d-learn mailing list