if auto and method call
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Apr 17 22:35:06 PDT 2017
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<t>.),").empty())
> {
> // Need the result of match to do things!
> }
>
> but this doesn't work:
>
>
> if (!(auto r = match(s, "\s*(?P<t>.),")).empty())
> {
>
> }
Stanislav Blinov has shown how overloading `cast(bool)` can help here.
In fact, std.regex.RegexMatch does just that. So this works:
----
if (auto r = match(s, "\s*(?P<t>.),"))
{
/* ... use r here ... */
}
----
More information about the Digitalmars-d-learn
mailing list