I know it's mentioned specially in the article but the C programmer in me immediately wants to use structs. They don't need to be complex or long lived or even initialized. And as a bonus there's no heap involved anywhere.
Either that or just bail out of c++ and use go.
Yeah, same here, a president of a local Duff's decice fanclub, but you have to admit that proposed C++ 17 feature is pretty nice:
... foo()
{
return { 1, "bar", false };
}
auto { i, s, b } = foo();
It's a syntax sugar, granted, and they could push it further by adopting tuples as a native language construct with some shorthand notation (e.g. [...]), but the idea is nice.
That's rarely a problem where MRV makes sense. Though you could always fix it by using anonymous structs whose fields are both named and positional (similar to Python's namedtuples)
I prefer to use generic structures (tuples, pairs etc.) or return proper type. One time structs are usually redeclared on multiple places. It is really hard maintain such code.
> One time structs are usually redeclared on multiple places. It is really hard maintain such code.
Well, if you don't need forward declarations, you can define structs inline in function signature:
#include <stdio.h>
struct ret { int a; int b} hello(int c) {
return (struct ret){ c, c + 1 };
}
int main(int argc, char **argv) {
struct ret result = hello(2);
printf("%d %d", result.a, result.b);
}
I'm not sure how portable it is though, works in gcc and in whatever ideone is using: https://ideone.com/bgZUPS