From 14e0e1afc27dc24261e1974dfb8934b7f9fd142a Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sat, 13 Nov 2010 12:31:54 +0000 Subject: [PATCH] Less use of the ampersand operator in unordered. [SVN r66557] --- include/boost/unordered/detail/buckets.hpp | 2 +- include/boost/unordered/detail/fwd.hpp | 10 ++++++++-- include/boost/unordered/detail/util.hpp | 4 ++-- test/objects/minimal.hpp | 20 ++++++++++++++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/include/boost/unordered/detail/buckets.hpp b/include/boost/unordered/detail/buckets.hpp index b1dee5cf..913dbcd2 100644 --- a/include/boost/unordered/detail/buckets.hpp +++ b/include/boost/unordered/detail/buckets.hpp @@ -64,7 +64,7 @@ namespace boost { namespace unordered_detail { inline void hash_buckets::delete_node(node_ptr b) { node* raw_ptr = static_cast(&*b); - boost::unordered_detail::destroy(&raw_ptr->value()); + boost::unordered_detail::destroy(raw_ptr->value_ptr()); real_node_ptr n(node_alloc().address(*raw_ptr)); node_alloc().destroy(n); node_alloc().deallocate(n, 1); diff --git a/include/boost/unordered/detail/fwd.hpp b/include/boost/unordered/detail/fwd.hpp index 274af519..34e72a49 100644 --- a/include/boost/unordered/detail/fwd.hpp +++ b/include/boost/unordered/detail/fwd.hpp @@ -231,6 +231,9 @@ namespace boost { namespace unordered_detail { value_type& value() { return *(ValueType*) this; } + value_type* value_ptr() { + return (ValueType*) this; + } private: value_base& operator=(value_base const&); }; @@ -249,6 +252,9 @@ namespace boost { namespace unordered_detail { static value_type& get_value(node_ptr p) { return static_cast(*p).value(); } + static value_type* get_value_ptr(node_ptr p) { + return static_cast(*p).value_ptr(); + } private: hash_node& operator=(hash_node const&); }; @@ -719,7 +725,7 @@ namespace boost { namespace unordered_detail { return node::get_value(ptr_); } value_type* operator->() const { - return &node::get_value(ptr_); + return node::get_value_ptr(ptr_); } hash_local_iterator& operator++() { ptr_ = ptr_->next_; return *this; @@ -769,7 +775,7 @@ namespace boost { namespace unordered_detail { return node::get_value(ptr_); } value_type const* operator->() const { - return &node::get_value(ptr_); + return node::get_value_ptr(ptr_); } hash_const_local_iterator& operator++() { ptr_ = ptr_->next_; return *this; diff --git a/include/boost/unordered/detail/util.hpp b/include/boost/unordered/detail/util.hpp index 55409651..989883e0 100644 --- a/include/boost/unordered/detail/util.hpp +++ b/include/boost/unordered/detail/util.hpp @@ -299,7 +299,7 @@ namespace boost { namespace unordered_detail { #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613)) struct dummy { hash_node x; }; #endif - boost::unordered_detail::destroy(&node_->value()); + boost::unordered_detail::destroy(node_->value_ptr()); } if (node_constructed_) @@ -322,7 +322,7 @@ namespace boost { namespace unordered_detail { } else { BOOST_ASSERT(node_constructed_ && value_constructed_); - boost::unordered_detail::destroy(&node_->value()); + boost::unordered_detail::destroy(node_->value_ptr()); value_constructed_ = false; } } diff --git a/test/objects/minimal.hpp b/test/objects/minimal.hpp index 4f8680fb..1cd8a2d3 100644 --- a/test/objects/minimal.hpp +++ b/test/objects/minimal.hpp @@ -26,6 +26,8 @@ namespace minimal class default_copy_constructible; class assignable; + struct ampersand_operator_used {}; + template class hash; template class equal_to; template class ptr; @@ -63,6 +65,7 @@ namespace minimal copy_constructible_equality_comparable& operator=( copy_constructible_equality_comparable const&); copy_constructible_equality_comparable() {} + ampersand_operator_used operator&() const { return ampersand_operator_used(); } }; bool operator==( @@ -98,9 +101,11 @@ namespace minimal ~default_copy_constructible() { } + private: default_copy_constructible& operator=( default_copy_constructible const&); + ampersand_operator_used operator&() const { return ampersand_operator_used(); } }; class assignable @@ -110,8 +115,11 @@ namespace minimal assignable(assignable const&) {} assignable& operator=(assignable const&) { return *this; } ~assignable() {} + private: assignable() {} + // TODO: This messes up a concept check in the tests. + //ampersand_operator_used operator&() const { return ampersand_operator_used(); } }; template @@ -125,6 +133,8 @@ namespace minimal ~hash() {} std::size_t operator()(T const&) const { return 0; } + private: + ampersand_operator_used operator&() const { return ampersand_operator_used(); } }; template @@ -138,6 +148,8 @@ namespace minimal ~equal_to() {} bool operator()(T const&, T const&) const { return true; } + private: + ampersand_operator_used operator&() const { return ampersand_operator_used(); } }; template class ptr; @@ -182,6 +194,9 @@ namespace minimal bool operator>(const_ptr const& x) const { return ptr_ > x.ptr_; } bool operator<=(const_ptr const& x) const { return ptr_ <= x.ptr_; } bool operator>=(const_ptr const& x) const { return ptr_ >= x.ptr_; } + private: + // TODO: + //ampersand_operator_used operator&() const { return ampersand_operator_used(); } }; template @@ -221,6 +236,9 @@ namespace minimal bool operator>(const_ptr const& x) const { return ptr_ > x.ptr_; } bool operator<=(const_ptr const& x) const { return ptr_ <= x.ptr_; } bool operator>=(const_ptr const& x) const { return ptr_ >= x.ptr_; } + private: + // TODO: + //ampersand_operator_used operator&() const { return ampersand_operator_used(); } }; template @@ -278,6 +296,8 @@ namespace minimal #else private: allocator& operator=(allocator const&); #endif + private: + ampersand_operator_used operator&() const { return ampersand_operator_used(); } }; template