Why use tuples instead of objects?

First of all, a tuple is quick and easy: instead of writing a class for every time you want to put 2 things together, there’s a template that does it for you.

Second of all, they’re generic. For example, in C++ the std::map uses an std::pair of key and value. Thus ANY pair can be used, instead of having to make some kind of wrapper class with accessor methods for every permutation of two types.

Finally, they’re useful for returning multiple values. There’s really no reason to make a class specifically for a function’s multiple return values, and they shouldn’t be treated as one object if they’re unrelated.

To be fair, the code you pasted is a bad use of a pair.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)