Description
I think F.41 ("Prefer to return tuples to multiple out-parameters") should become "Prefer returning aggregate class types to multiple out-parameters" (or something like that, what I mean is "prefer returning a struct
").
Structs have names and their fields have names, which helps understanding and reasoning about code. The variables used in std::tie()
have names too, but the user needs to declare those names consistently and meaningfully at every point of use; this is error-prone. Also, those variables must be pre-declared, and two-step initialization is not idiomatic in C++ (and particularly ugly if default-construction is not an option).
Tuples might be a better option for certain kinds of generic code, but I don't see them as a candidate for a default guideline on returning multiple values.