Question

tuples are similar to structs (discussed here: Boost::Tuples vs Structs for return values). it seems that the only advantage is it's more convenient to write struct because it's shorter and by key rather than a number.

one can also use fusion map and structs to access by key Boost::Tuples vs Structs for return values to simulate structures. it's a bit more writing.

it seems that there is no penalty in performance either. well, fusion may be faster since it uses views.

so the only reason to use structs is if you don't want to write few more lines of code and to keep the code readable?

Was it helpful?

Solution

so the only reason to use structs is if you don't want to write few more lines of code and to keep the code readable?

Also, there is an extendability/maintainability - it would be quite hard to put/modify/remove any additional positional argument in tuple, yet it's much easy with "key-value" struct lookup.

Code quality is a composition of performance, readability, clearness, extendability etc. Disregarding of any this values will make your code worse. And this is a bad thing.

OTHER TIPS

Structs can be subclassed, and can contain methods, virtual functions, enumerations, typedefs, sub-structs, and more.

Tuples can only represent the very most trivial functionality of struct, that is, a collection of values. And it can't even give them proper names. They are a very poor substitute.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top