Multiple return type or callback function
pineapple via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jan 23 08:34:58 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 (IMO
> could use struct but will make code dirty with too much custom
> types).
>
> struct Result
> {
> bool success = false
> string message;
> }
> Result authen(){}
> auto r = authen()
> if (r.success) writeln(r.message);
I use structs like this quite frequently, myself. It works well
and I don't think it's particularly ugly. And if you don't want
to pollute the namespace with one-off structs, you can also place
them inside the function that's returning them (making them
voledmort types).
More information about the Digitalmars-d-learn
mailing list