Boost logo

Boost-Commit :

From: daniel_james_at_[hidden]
Date: 2008-01-08 06:53:02


Author: danieljames
Date: 2008-01-08 06:53:02 EST (Tue, 08 Jan 2008)
New Revision: 42610
URL: http://svn.boost.org/trac/boost/changeset/42610

Log:
Don't use the safe bool idiom in the minimal pointer objects - and fix allocator.hpp to work with dangerous bool conversions.

Text files modified:
   branches/unordered/trunk/boost/unordered/detail/allocator.hpp | 2 +-
   branches/unordered/trunk/libs/unordered/test/objects/minimal.hpp | 27 +++++++++------------------
   2 files changed, 10 insertions(+), 19 deletions(-)

Modified: branches/unordered/trunk/boost/unordered/detail/allocator.hpp
==============================================================================
--- branches/unordered/trunk/boost/unordered/detail/allocator.hpp (original)
+++ branches/unordered/trunk/boost/unordered/detail/allocator.hpp 2008-01-08 06:53:02 EST (Tue, 08 Jan 2008)
@@ -207,7 +207,7 @@
                 BOOST_ASSERT(!ptr_);
                 length_ = l;
                 ptr_ = alloc_.allocate(length_);
- pointer end = ptr_ + length_;
+ pointer end = ptr_ + static_cast<std::ptrdiff_t>(length_);
                 for(constructed_ = ptr_; constructed_ != end; ++constructed_)
                     alloc_.construct(constructed_, v);
             }

Modified: branches/unordered/trunk/libs/unordered/test/objects/minimal.hpp
==============================================================================
--- branches/unordered/trunk/libs/unordered/test/objects/minimal.hpp (original)
+++ branches/unordered/trunk/libs/unordered/test/objects/minimal.hpp 2008-01-08 06:53:02 EST (Tue, 08 Jan 2008)
@@ -3,6 +3,10 @@
 // Distributed under the Boost Software License, Version 1.0. (See accompanying
 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
+// Define some minimal classes which provide the bare minimum concepts to
+// test that the containers don't rely on something that they shouldn't.
+// They are not intended to be good examples of how to implement the concepts.
+
 #if !defined(BOOST_UNORDERED_OBJECTS_MINIMAL_HEADER)
 #define BOOST_UNORDERED_OBJECTS_MINIMAL_HEADER
 
@@ -100,9 +104,6 @@
     public:
         ptr() : ptr_(0) {}
 
- typedef void (ptr::*bool_type)() const;
- void this_type_does_not_support_comparisons() const {}
-
         T& operator*() const { return *ptr_; }
         T* operator->() const { return ptr_; }
         ptr& operator++() { ++ptr_; return *this; }
@@ -111,12 +112,10 @@
         friend ptr operator+(std::ptrdiff_t s, ptr p) { return ptr<T>(s + p.ptr_); }
         T& operator[](std::ptrdiff_t s) const { return ptr_[s]; }
         bool operator!() const { return !ptr_; }
-
- operator bool_type() const {
- return ptr_ ?
- &ptr::this_type_does_not_support_comparisons
- : 0;
- }
+
+ // I'm not using the safe bool idiom because the containers should be
+ // able to cope with bool conversions.
+ operator bool() const { return !!ptr_; }
 
         bool operator==(ptr const& x) const { return ptr_ == x.ptr_; }
         bool operator!=(ptr const& x) const { return ptr_ != x.ptr_; }
@@ -145,9 +144,6 @@
         const_ptr() : ptr_(0) {}
         const_ptr(ptr<T> const& x) : ptr_(x.ptr_) {}
 
- typedef void (const_ptr::*bool_type)() const;
- void this_type_does_not_support_comparisons() const {}
-
         T const& operator*() const { return *ptr_; }
         T const* operator->() const { return ptr_; }
         const_ptr& operator++() { ++ptr_; return *this; }
@@ -156,12 +152,7 @@
         friend const_ptr operator+(std::ptrdiff_t s, const_ptr p) { return ptr<T>(s + p.ptr_); }
         T const& operator[](int s) const { return ptr_[s]; }
         bool operator!() const { return !ptr_; }
-
- operator bool_type() const {
- return ptr_ ?
- &const_ptr::this_type_does_not_support_comparisons
- : 0;
- }
+ operator bool() const { return !!ptr_; }
 
         bool operator==(ptr<T> const& x) const { return ptr_ == x.ptr_; }
         bool operator!=(ptr<T> const& x) const { return ptr_ != x.ptr_; }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk