if auto and method call

Andrea Fontana via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 18 02:05:10 PDT 2017


On Tuesday, 18 April 2017 at 00:48:05 UTC, Jethro wrote:
> How to combine the need to localize a result for an if 
> statement and have to call a method to get proper comparison:
> [...]
> which should simplify to
>
> if ((auto x = foo()).valid())
> {
>
> }
>
> but this code does not work.
> [...]


for(auto x = foo(); foo.valid();)
{
    ... your code here ...
    break;
}

it would be useful if this syntax was supported:

for(auto x = foo(); foo.valid(); break)
{

}


Andrea


More information about the Digitalmars-d-learn mailing list