C Pair

closed account (S6k9GNh0)
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
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);
closed account (S6k9GNh0)
But from that view, it's no different from making a 2-member structure...I can't picture many people using it...
You are right, but in this case your structure should be template.

1
2
3
4
5
6
template <typename firstType, typename secondType>
struct Pair
{
    firstType first;
    secondType second;
};


And std::pair has a swap method
Oh, I use it all the time. Specially when I'm too lazy to declare yet another structure just to accommodate a pair.
closed account (S6k9GNh0)
So it's just a helper utility. That clears that up. *checks answered*
Topic archived. No new replies allowed.