digitalmars.D.learn - Tuple or struct as return type?
- Martin (6/6) Feb 06 2021 Hi,
- Adam D. Ruppe (7/9) Feb 06 2021 A Tuple is just a struct declared inlined. I personally use
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
Feb 06 2021
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.
Feb 06 2021