Multiple return type or callback function
Basile B. via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jan 23 09:47:01 PST 2017
On Monday, 23 January 2017 at 15:15:35 UTC, aberba wrote:
> I'm creating a function to authenticate user login. I want to
> determine login failure (Boolean) and error message (will be
> sent to frontend) but D does have multiple return type
> [...]
Yes, MRV can be done with a tuple
auto foo()
{
import std.typecons;
return tuple(true, "123456");
}
void main(string[] args)
{
auto auth = foo;
if (auth[0])
auth[1].writeln;
}
It's more or less like returning a Voldemort struct.
More information about the Digitalmars-d-learn
mailing list