Re: how do I tell if something is lvalue?

2016-02-01 Thread Artur Skawina via Digitalmars-d-learn
On 02/01/16 20:47, Meta via Digitalmars-d-learn wrote: > On Monday, 1 February 2016 at 18:28:05 UTC, Artur Skawina wrote: >> On 01/31/16 23:11, Steven Schveighoffer via Digitalmars-d-learn wrote: >>> Thanks! I was surprised this is not straightforward. >> >>enum isLvalue(alias A) =

Re: how do I tell if something is lvalue?

2016-02-01 Thread Artur Skawina via Digitalmars-d-learn
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...) =

Re: how do I tell if something is lvalue?

2016-02-01 Thread Meta via Digitalmars-d-learn
On Monday, 1 February 2016 at 18:28:05 UTC, Artur Skawina wrote: On 01/31/16 23:11, Steven Schveighoffer via Digitalmars-d-learn wrote: Thanks! I was surprised this is not straightforward. enum isLvalue(alias A) = is(typeof((ref _){}(A))); artur That looks much nicer. It still needs

Re: how do I tell if something is lvalue?

2016-02-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/1/16 2:47 PM, Meta wrote: On Monday, 1 February 2016 at 18:28:05 UTC, Artur Skawina wrote: On 01/31/16 23:11, Steven Schveighoffer via Digitalmars-d-learn wrote: Thanks! I was surprised this is not straightforward. enum isLvalue(alias A) = is(typeof((ref _){}(A))); artur That

Re: how do I tell if something is lvalue?

2016-02-01 Thread Meta via Digitalmars-d-learn
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

Re: how do I tell if something is lvalue?

2016-02-01 Thread tsbockman via Digitalmars-d-learn
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;

Re: how do I tell if something is lvalue?

2016-02-01 Thread Steven Schveighoffer via Digitalmars-d-learn
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

Re: how do I tell if something is lvalue?

2016-02-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/31/16 5:12 PM, Meta wrote: On Sunday, 31 January 2016 at 22:11:45 UTC, Steven Schveighoffer wrote: On 1/31/16 4:48 PM, Meta wrote: This seems to do the trick, although I haven't extensively tested it. There's probably a simpler way but this is the first thing I could come up with that

Re: how do I tell if something is lvalue?

2016-02-01 Thread tsbockman via Digitalmars-d-learn
On Monday, 1 February 2016 at 22:32:26 UTC, Steven Schveighoffer wrote: What I wanted essentially was a template constraint that says "this type has a member named foo, and t.foo is an lvalue" -Steve Like this? template hasLValProperty(T, string property) { enum hasLValProperty =

Re: how do I tell if something is lvalue?

2016-02-01 Thread Artur Skawina via Digitalmars-d-learn
On 01/31/16 23:11, Steven Schveighoffer via Digitalmars-d-learn wrote: > Thanks! I was surprised this is not straightforward. enum isLvalue(alias A) = is(typeof((ref _){}(A))); artur

Re: how do I tell if something is lvalue?

2016-01-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/31/16 4:48 PM, Meta wrote: This seems to do the trick, although I haven't extensively tested it. There's probably a simpler way but this is the first thing I could come up with that works. Thanks! I was surprised this is not straightforward. -Steve

Re: how do I tell if something is lvalue?

2016-01-31 Thread Meta via Digitalmars-d-learn
On Sunday, 31 January 2016 at 22:11:45 UTC, Steven Schveighoffer wrote: On 1/31/16 4:48 PM, Meta wrote: This seems to do the trick, although I haven't extensively tested it. There's probably a simpler way but this is the first thing I could come up with that works. Thanks! I was

how do I tell if something is lvalue?

2016-01-31 Thread Steven Schveighoffer via Digitalmars-d-learn
struct S { int x; ref int y() { return x; } int z() { return 1; } } What can I use, given S, to determine that x and y yield lvalues, while z yields an rvalue? I was expecting something like isLvalue somewhere, but cannot find it. __traits(isRef, ...) doesn't work. -Steve

Re: how do I tell if something is lvalue?

2016-01-31 Thread Meta via Digitalmars-d-learn
On Sunday, 31 January 2016 at 20:49:43 UTC, Steven Schveighoffer wrote: struct S { int x; ref int y() { return x; } int z() { return 1; } } What can I use, given S, to determine that x and y yield lvalues, while z yields an rvalue? I was expecting something like isLvalue somewhere, but

Re: how do I tell if something is lvalue?

2016-01-31 Thread Ali Çehreli via Digitalmars-d-learn
On 01/31/2016 01:48 PM, Meta wrote: This seems to do the trick, although I haven't extensively tested it. There is hasLvalueElements() as well. Its implementation my be similar or give other ideas: https://dlang.org/phobos/std_range_primitives.html#hasLvalueElements Ali

Re: how do I tell if something is lvalue?

2016-01-31 Thread Meta via Digitalmars-d-learn
On Monday, 1 February 2016 at 00:20:00 UTC, Ali Çehreli wrote: On 01/31/2016 01:48 PM, Meta wrote: This seems to do the trick, although I haven't extensively tested it. There is hasLvalueElements() as well. Its implementation my be similar or give other ideas: