February 06, 2021 Tuple or struct as return type? | ||||
---|---|---|---|---|
| ||||
Hi, lets say i want to create a function that returns multiple values - e.g. Tuple!(string,string). Why/when i should prefer Tuple as a return type over returning a struct (or even string[2] in this case)? Thank you |
February 06, 2021 Re: Tuple or struct as return type? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin | On Saturday, 6 February 2021 at 18:02:46 UTC, Martin wrote:
> Why/when i should prefer Tuple as a return type over returning a struct (or even string[2] in this case)?
A Tuple is just a struct declared inlined. I personally use struct every single time - structs can be separately documented and be custom tailored to other situation, more compatible if you change your mind and add stuff later - but I guess if it is utterly trivial the inline definition of Tuple might be convenient.
|
Copyright © 1999-2021 by the D Language Foundation