AFAIK, boost::compressed_pair is supposed to ensure that the address of the first and second memebrs are different while it does its magic of compressing the pair. It says so here. Seems like it is not the case and its behavior is different on different compilers. I'm using boost v 1.47. What am I missing?
struct E1 {};
struct E2 {};
boost::compressed_pair<E1, E2> diff_pair;
boost::compressed_pair<E1, E1> same_pair;
// clang++ and g++ 4.7 print the same address but VC2010 prints different addresses.
printf("different pairs = %p, %p
", &diff_pair.first(), &diff_pair.second());
// clang++ and g++ 4.7 print different addresses but VC2010 prints the same address.
printf("different pairs = %p, %p
", &same_pair.first(), &same_pair.second());
See Question&Answers more detail:os