Bug or logic error in if with auto?

Peter Alexander peter.alexander.au at gmail.com
Sun Dec 2 07:56:43 PST 2012


On Sunday, 2 December 2012 at 15:09:17 UTC, js.mdnq wrote:
> Can this be made to work in D?
>
> Error in D, x not found:
>
> if (auto x = "thing" in arr && x == 45)
> {
>
> }

You can't have both a declaration and expression in an 
if-statement.

http://dlang.org/statement.html#IfStatement

IfStatement:
     if ( IfCondition ) ThenStatement
     if ( IfCondition ) ThenStatement else ElseStatement

IfCondition:
     Expression
     auto Identifier = Expression
     BasicType Declarator = Expression



More information about the Digitalmars-d mailing list