www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Tuple or struct as return type?

reply Martin <martin.brzenska googlemail.com> writes:
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
parent Adam D. Ruppe <destructionator gmail.com> writes:
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