if(arr) now a warning

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Sat May 2 07:58:28 PDT 2015


On 4/30/15 5:34 AM, Byron Heads wrote:
> On Wed, 29 Apr 2015 22:44:22 -0400, Steven Schveighoffer wrote:
>
>> On 4/29/15 8:35 PM, Martin Nowak wrote:
>>> Occasionally I'm using if (auto ary = func()), despite the fact that
>>> the semantics are wrong, but it's nice and short and works as long a
>>> func always returns null instead of empty slices.
>>
>> I wonder if it's possible to fix this, as it is, IMO, the only
>> legitimate drawback of this change. Could we make the following work?
>>
>> if((auto ary = func()).length)
>>
>> -Steve
>
>
>
> I would have though this would work:
>
> if(auto x = foo(), !x.empty)
>

That's because it means this:

if(auto x = (foo(), !x.empty))

which I think would be invalid since you are using x before assignment.

-Steve


More information about the Digitalmars-d mailing list