Re: if auto and method call

2017-04-18 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 18 April 2017 at 09:05:10 UTC, Andrea Fontana wrote: 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()).val

Re: if auto and method call

2017-04-18 Thread Andrea Fontana via Digitalmars-d-learn
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

Re: if auto and method call

2017-04-17 Thread ag0aep6g via Digitalmars-d-learn
On 04/18/2017 02:48 AM, Jethro wrote: I generally need this for regex stuff and it's quite annoying it doesn't work. if (!match(s, "\s*(?P.),").empty()) { // Need the result of match to do things! } but this doesn't work: if (!(auto r = match(s, "\s*(?P.),")).empty()) { } Stanislav Blinov

Re: if auto and method call

2017-04-17 Thread Stanislav Blinov via Digitalmars-d-learn
Would be prettier as a language feature, but still: template test(alias pred) { import std.functional : unaryFun; alias P = unaryFun!pred; auto test(R)(R r) { struct Test { R v; string toString() { import std.co

if auto and method call

2017-04-17 Thread Jethro via Digitalmars-d-learn
How to combine the need to localize a result for an if statement and have to call a method to get proper comparison: if (((auto x = X.value()).empty()) { } instead of having to do the long and winded way auto x = X.value(); if (x.empty()) { } Many times I need the result of a function insid