When we have a compressed pair of two types that are the same, and both empty, then we must still have two distict objects in the pair.

[SVN r21958]
This commit is contained in:
John Maddock 2004-01-26 11:29:07 +00:00
parent 0dde936e61
commit 154d6bb198
2 changed files with 16 additions and 10 deletions

View File

@ -8,6 +8,9 @@
// compressed_pair: pair that "compresses" empty members
// (see libs/utility/compressed_pair.htm)
//
// JM changes 25 Jan 2004:
// For the case where T1 == T2 and both are empty, then first() and second()
// should return different objects.
// JM changes 25 Jan 2000:
// Removed default arguments from compressed_pair_switch to get
// C++ Builder 4 to accept them
@ -268,20 +271,21 @@ namespace details
compressed_pair_imp() {}
compressed_pair_imp(first_param_type x, second_param_type)
: first_type(x) {}
compressed_pair_imp(first_param_type x, second_param_type y)
: first_type(x), m_second(y) {}
compressed_pair_imp(first_param_type x)
: first_type(x) {}
: first_type(x), m_second(x) {}
first_reference first() {return *this;}
first_const_reference first() const {return *this;}
second_reference second() {return *this;}
second_const_reference second() const {return *this;}
second_reference second() {return m_second;}
second_const_reference second() const {return m_second;}
void swap(::boost::compressed_pair<T1,T2>&) {}
private:
T2 m_second;
};
// 5 T1 == T2 and are not empty: //JM

View File

@ -292,22 +292,24 @@ public:
typedef typename call_traits<second_type>::const_reference second_const_reference;
compressed_pair_4() : T1() {}
compressed_pair_4(first_param_type x, second_param_type) : T1(x) {}
compressed_pair_4(first_param_type x, second_param_type y) : T1(x), m_second(y) {}
// only one single argument constructor since T1 == T2
explicit compressed_pair_4(first_param_type x) : T1(x) {}
explicit compressed_pair_4(first_param_type x) : T1(x), m_second(x) {}
compressed_pair_4(const ::boost::compressed_pair<T1,T2>& x)
: T1(x.first()){}
: T1(x.first()), m_second(x.second()) {}
first_reference first() { return *this; }
first_const_reference first() const { return *this; }
second_reference second() { return *this; }
second_const_reference second() const { return *this; }
second_reference second() { return m_second; }
second_const_reference second() const { return m_second; }
void swap(compressed_pair_4& y)
{
// no need to swap empty base classes:
}
private:
T2 m_second;
};
// T1 == T2, not empty