0

Is there any advantage of using std::pair over std::tuple (or vice versa) when I need only two different types?

For example:

std::pair<int,double> foo;
std::tuple<int,double> bar;

I can name one advantage is that if I need, in future, to add a third type, std::tuple can serve me better than pair because I have to change the std::pair to std::tuple or to work around it (like making a struct that contains two of them).

By advantages, I mean performance, readability, usability, maintainability or anything...

EDIT: I am seeking an answer that address performance, readability, usability, maintainability. All of these aspects were not addressed in the answers of that question which this question is marked as duplicated of it.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Humam Helfawi
  • 19,566
  • 15
  • 85
  • 160
  • Performance depends on use case (if there is a difference) - you need to benchmark. The other three are subjective. – Mat Jan 03 '16 at 18:18
  • 1
    Well, the answers list all the differences. And (partly implicitly, partly explicitly) their possible impact on those acpects. Though how to assess and weigh them is partly subjective. – Deduplicator Jan 03 '16 at 18:20

0 Answers0