Compared with pair, is there any performance loss for tuple with only 2 elements?
Asked
Active
Viewed 207 times
0
-
6When you profiled it, what result did you get? – JBentley Mar 27 '13 at 19:36
-
1Benchmark it. It should be exactly the same using a modern compiler. But if you want to be 100% sure, test it. – mfontanini Mar 27 '13 at 19:37
-
5Use the right tool for the job. Pair is for mapping something to something else; e.g. for use in `std::map`. Tuple is for holding a set of completely unrelated values, e.g. so that a function can return multiple things. Perf wise they should be essentially identical. – Billy ONeal Mar 27 '13 at 19:38
2 Answers
2
I very much doubt whatever system you are designing is going to grind to a halt because you chose to use tuple
over pair
. In fact, I'd be very surprised if the compiler generated anything more or less for a 2-value tuple than it would do for a pair as they're (almost) equivalent.
I can assure you that, if your application grinds to a halt and your PC begins to melt - it won't be due to your choice of tuple over pair, or vice-versa.

Moo-Juice
- 38,257
- 10
- 78
- 128
1
You would have to profile it. Besides, why risking extended use for something intended to be used with only two elements. Personal preference is not enough. Pair is easily usable with Maps, while tuple is a collection of its own.

Claudiordgz
- 3,023
- 1
- 21
- 48