Less use of the ampersand operator in unordered.

[SVN r66557]
This commit is contained in:
Daniel James
2010-11-13 12:31:54 +00:00
parent 2c1a8894cb
commit 14e0e1afc2
4 changed files with 31 additions and 5 deletions

View File

@ -64,7 +64,7 @@ namespace boost { namespace unordered_detail {
inline void hash_buckets<A, G>::delete_node(node_ptr b) inline void hash_buckets<A, G>::delete_node(node_ptr b)
{ {
node* raw_ptr = static_cast<node*>(&*b); node* raw_ptr = static_cast<node*>(&*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)); real_node_ptr n(node_alloc().address(*raw_ptr));
node_alloc().destroy(n); node_alloc().destroy(n);
node_alloc().deallocate(n, 1); node_alloc().deallocate(n, 1);

View File

@ -231,6 +231,9 @@ namespace boost { namespace unordered_detail {
value_type& value() { value_type& value() {
return *(ValueType*) this; return *(ValueType*) this;
} }
value_type* value_ptr() {
return (ValueType*) this;
}
private: private:
value_base& operator=(value_base const&); value_base& operator=(value_base const&);
}; };
@ -249,6 +252,9 @@ namespace boost { namespace unordered_detail {
static value_type& get_value(node_ptr p) { static value_type& get_value(node_ptr p) {
return static_cast<hash_node&>(*p).value(); return static_cast<hash_node&>(*p).value();
} }
static value_type* get_value_ptr(node_ptr p) {
return static_cast<hash_node&>(*p).value_ptr();
}
private: private:
hash_node& operator=(hash_node const&); hash_node& operator=(hash_node const&);
}; };
@ -719,7 +725,7 @@ namespace boost { namespace unordered_detail {
return node::get_value(ptr_); return node::get_value(ptr_);
} }
value_type* operator->() const { value_type* operator->() const {
return &node::get_value(ptr_); return node::get_value_ptr(ptr_);
} }
hash_local_iterator& operator++() { hash_local_iterator& operator++() {
ptr_ = ptr_->next_; return *this; ptr_ = ptr_->next_; return *this;
@ -769,7 +775,7 @@ namespace boost { namespace unordered_detail {
return node::get_value(ptr_); return node::get_value(ptr_);
} }
value_type const* operator->() const { value_type const* operator->() const {
return &node::get_value(ptr_); return node::get_value_ptr(ptr_);
} }
hash_const_local_iterator& operator++() { hash_const_local_iterator& operator++() {
ptr_ = ptr_->next_; return *this; ptr_ = ptr_->next_; return *this;

View File

@ -299,7 +299,7 @@ namespace boost { namespace unordered_detail {
#if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613)) #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613))
struct dummy { hash_node<Alloc, Grouped> x; }; struct dummy { hash_node<Alloc, Grouped> x; };
#endif #endif
boost::unordered_detail::destroy(&node_->value()); boost::unordered_detail::destroy(node_->value_ptr());
} }
if (node_constructed_) if (node_constructed_)
@ -322,7 +322,7 @@ namespace boost { namespace unordered_detail {
} }
else { else {
BOOST_ASSERT(node_constructed_ && value_constructed_); BOOST_ASSERT(node_constructed_ && value_constructed_);
boost::unordered_detail::destroy(&node_->value()); boost::unordered_detail::destroy(node_->value_ptr());
value_constructed_ = false; value_constructed_ = false;
} }
} }

View File

@ -26,6 +26,8 @@ namespace minimal
class default_copy_constructible; class default_copy_constructible;
class assignable; class assignable;
struct ampersand_operator_used {};
template <class T> class hash; template <class T> class hash;
template <class T> class equal_to; template <class T> class equal_to;
template <class T> class ptr; template <class T> class ptr;
@ -63,6 +65,7 @@ namespace minimal
copy_constructible_equality_comparable& operator=( copy_constructible_equality_comparable& operator=(
copy_constructible_equality_comparable const&); copy_constructible_equality_comparable const&);
copy_constructible_equality_comparable() {} copy_constructible_equality_comparable() {}
ampersand_operator_used operator&() const { return ampersand_operator_used(); }
}; };
bool operator==( bool operator==(
@ -98,9 +101,11 @@ namespace minimal
~default_copy_constructible() ~default_copy_constructible()
{ {
} }
private: private:
default_copy_constructible& operator=( default_copy_constructible& operator=(
default_copy_constructible const&); default_copy_constructible const&);
ampersand_operator_used operator&() const { return ampersand_operator_used(); }
}; };
class assignable class assignable
@ -110,8 +115,11 @@ namespace minimal
assignable(assignable const&) {} assignable(assignable const&) {}
assignable& operator=(assignable const&) { return *this; } assignable& operator=(assignable const&) { return *this; }
~assignable() {} ~assignable() {}
private: private:
assignable() {} assignable() {}
// TODO: This messes up a concept check in the tests.
//ampersand_operator_used operator&() const { return ampersand_operator_used(); }
}; };
template <class T> template <class T>
@ -125,6 +133,8 @@ namespace minimal
~hash() {} ~hash() {}
std::size_t operator()(T const&) const { return 0; } std::size_t operator()(T const&) const { return 0; }
private:
ampersand_operator_used operator&() const { return ampersand_operator_used(); }
}; };
template <class T> template <class T>
@ -138,6 +148,8 @@ namespace minimal
~equal_to() {} ~equal_to() {}
bool operator()(T const&, T const&) const { return true; } bool operator()(T const&, T const&) const { return true; }
private:
ampersand_operator_used operator&() const { return ampersand_operator_used(); }
}; };
template <class T> class ptr; template <class T> class ptr;
@ -182,6 +194,9 @@ namespace minimal
bool operator>(const_ptr<T> const& x) const { return ptr_ > x.ptr_; } bool operator>(const_ptr<T> const& x) const { return ptr_ > x.ptr_; }
bool operator<=(const_ptr<T> const& x) const { return ptr_ <= x.ptr_; } bool operator<=(const_ptr<T> const& x) const { return ptr_ <= x.ptr_; }
bool operator>=(const_ptr<T> const& x) const { return ptr_ >= x.ptr_; } bool operator>=(const_ptr<T> const& x) const { return ptr_ >= x.ptr_; }
private:
// TODO:
//ampersand_operator_used operator&() const { return ampersand_operator_used(); }
}; };
template <class T> template <class T>
@ -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_; } 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 <class T> template <class T>
@ -278,6 +296,8 @@ namespace minimal
#else #else
private: allocator& operator=(allocator const&); private: allocator& operator=(allocator const&);
#endif #endif
private:
ampersand_operator_used operator&() const { return ampersand_operator_used(); }
}; };
template <class T> template <class T>