Bug or logic error in if with auto?

Nick Treleaven ntrel-public at yahoo.co.uk
Tue Dec 4 05:32:01 PST 2012


On 03/12/2012 20:17, Rob T wrote:
> On Monday, 3 December 2012 at 14:22:28 UTC, Nick Treleaven wrote:
>
>> Most programmers would probably just pollute the existing scope:
>>
>> auto x = "thing" in arr;
>> if (x && *x == 45)
>> {
>>     ...
>> }
>>
>
> You can always wrap it inside its own scope

Yes, that's why I wrote:

 > I expect this is because wrapping the above in {} for a new scope is
 > just too ugly, introducing more nesting and indentation.

;-)

 >    // temp scope
 >    {
 >      auto x = "thing" in arr;
 >      if (x && *x == 45)
 >      {
 >         ...
 >      }
 >    }

I would much prefer this:

with (auto x = "thing" in arr)
if (x && *x == 45)
{
     ...
}


More information about the Digitalmars-d mailing list