From 154d6bb19872f513b08d0fc51716fbe6c10c2a03 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Mon, 26 Jan 2004 11:29:07 +0000 Subject: [PATCH] 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] --- include/boost/detail/compressed_pair.hpp | 14 +++++++++----- include/boost/detail/ob_compressed_pair.hpp | 12 +++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/boost/detail/compressed_pair.hpp b/include/boost/detail/compressed_pair.hpp index 9c9ac7e..af1e9bd 100644 --- a/include/boost/detail/compressed_pair.hpp +++ b/include/boost/detail/compressed_pair.hpp @@ -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&) {} private: + T2 m_second; }; // 5 T1 == T2 and are not empty: //JM diff --git a/include/boost/detail/ob_compressed_pair.hpp b/include/boost/detail/ob_compressed_pair.hpp index c316a06..727acab 100644 --- a/include/boost/detail/ob_compressed_pair.hpp +++ b/include/boost/detail/ob_compressed_pair.hpp @@ -292,22 +292,24 @@ public: typedef typename call_traits::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& 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