May 22, 2009 at 1:57pm UTC
Don't know if this is a nub question or not but what's the difference between a C Pair and a two-member struct?
Or should I say what are the advantages of a pair?
Last edited on May 22, 2009 at 1:58pm UTC
May 22, 2009 at 4:14pm UTC
If you mean std::pair then it a template structure, and you can use it with different types
for example:
std::pair<int , int> intPair(100, 12);
std::pair<std::string, int> stringPair("one" , 1);
For more easy using you can use typedef
typedef std::pair<int, int> myPair;
myPair intPair(100, 12);
May 22, 2009 at 4:16pm UTC
But from that view, it's no different from making a 2-member structure...I can't picture many people using it...
May 22, 2009 at 4:45pm UTC
Oh, I use it all the time. Specially when I'm too lazy to declare yet another structure just to accommodate a pair.
May 22, 2009 at 5:49pm UTC
So it's just a helper utility. That clears that up. *checks answered*