Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r48998 - in sandbox/shifted_ptr: bits boost boost/detail libs/smart_ptr/example
From: phil_at_[hidden]
Date: 2008-09-29 05:44:29


Author: pbouchard
Date: 2008-09-29 05:44:28 EDT (Mon, 29 Sep 2008)
New Revision: 48998
URL: http://svn.boost.org/trac/boost/changeset/48998

Log:
New version of _List_base::_M_clear()
Text files modified:
   sandbox/shifted_ptr/bits/list.tcc | 20 +-
   sandbox/shifted_ptr/bits/list.tcc.patch | 31 +--
   sandbox/shifted_ptr/bits/stl_list.h | 2
   sandbox/shifted_ptr/bits/stl_list.h.patch | 6
   sandbox/shifted_ptr/boost/detail/shifted_ptr_base.hpp | 256 ++++++++++++++++++++++++++++++++-------
   sandbox/shifted_ptr/boost/shifted_allocator.hpp | 24 ++-
   sandbox/shifted_ptr/boost/shifted_ptr.hpp | 3
   sandbox/shifted_ptr/libs/smart_ptr/example/shifted_ptr_test2.cpp | 4
   8 files changed, 245 insertions(+), 101 deletions(-)

Modified: sandbox/shifted_ptr/bits/list.tcc
==============================================================================
--- sandbox/shifted_ptr/bits/list.tcc (original)
+++ sandbox/shifted_ptr/bits/list.tcc 2008-09-29 05:44:28 EDT (Mon, 29 Sep 2008)
@@ -71,11 +71,6 @@
         static_cast<_List_node_base &>(*__position)._M_prev = this->_M_prev;
         this->_M_prev->_M_next = __position;
         this->_M_prev = __position;
-
-// this->_M_next = __position;
-// this->_M_prev = __position->_M_prev;
-// __position->_M_prev->_M_next = this;
-// __position->_M_prev = this;
     }
 
   template<typename _Alloc>
@@ -93,17 +88,18 @@
     _List_base<_Tp,_Alloc>::
     _M_clear()
     {
-/* typedef _List_node<_Tp,_Alloc> _Node;
+ typedef _List_node<_Tp,_Alloc> _Node;
       typedef _List_node_base<_Alloc> _Node_base;
       typename _Node_base::pointer* __cur = & this->_M_impl._M_node->_M_next;
- while (__cur != & this->_M_impl._M_node)
+ while (__cur != (typename _Node_base::pointer*) & this->_M_impl._M_node)
       {
- typename _Node_base::pointer* __tmp = __cur;
- __cur = & (*__cur)->_M_next;
- _M_impl._Node_Alloc_type::destroy(*(typename _Node::pointer*) __tmp);
- _M_put_node(*(typename _Node::pointer*) __tmp);
+ typename _Node_base::pointer* __next = & (*__cur)->_M_next;
+ _M_impl._Node_Alloc_type::destroy(*(typename _Node::pointer*) __cur);
+ _M_put_node(*(typename _Node::pointer*) __cur);
+ if (! *__cur) break;
+ __cur = __next;
       }
-*/ }
+ }
 
   template<typename _Tp, typename _Alloc>
     typename list<_Tp,_Alloc>::iterator

Modified: sandbox/shifted_ptr/bits/list.tcc.patch
==============================================================================
--- sandbox/shifted_ptr/bits/list.tcc.patch (original)
+++ sandbox/shifted_ptr/bits/list.tcc.patch 2008-09-29 05:44:28 EDT (Mon, 29 Sep 2008)
@@ -1,6 +1,6 @@
 --- /local/include/c++/3.4.5/bits/list.tcc Wed Jan 18 11:06:46 2006
-+++ list.tcc Tue Aug 12 02:58:56 2008
-@@ -61,25 +61,51 @@
++++ list.tcc Mon Sep 29 02:41:26 2008
+@@ -61,23 +61,45 @@
  #ifndef _LIST_TCC
  #define _LIST_TCC 1
  
@@ -14,11 +14,6 @@
 + static_cast<_List_node_base &>(*__position)._M_prev = this->_M_prev;
 + this->_M_prev->_M_next = __position;
 + this->_M_prev = __position;
-+
-+// this->_M_next = __position;
-+// this->_M_prev = __position->_M_prev;
-+// __position->_M_prev->_M_next = this;
-+// __position->_M_prev = this;
 + }
 +
 + template<typename _Alloc>
@@ -44,24 +39,22 @@
 - __cur = static_cast<_Node*>(__cur->_M_next);
 - std::_Destroy(&__tmp->_M_data);
 - _M_put_node(__tmp);
-- }
-+/* typedef _List_node<_Tp,_Alloc> _Node;
++ typedef _List_node<_Tp,_Alloc> _Node;
 + typedef _List_node_base<_Alloc> _Node_base;
 + typename _Node_base::pointer* __cur = & this->_M_impl._M_node->_M_next;
-+ while (__cur != & this->_M_impl._M_node)
++ while (__cur != (typename _Node_base::pointer*) & this->_M_impl._M_node)
 + {
-+ typename _Node_base::pointer* __tmp = __cur;
-+ __cur = & (*__cur)->_M_next;
-+ _M_impl._Node_Alloc_type::destroy(*(typename _Node::pointer*) __tmp);
-+ _M_put_node(*(typename _Node::pointer*) __tmp);
++ typename _Node_base::pointer* __next = & (*__cur)->_M_next;
++ _M_impl._Node_Alloc_type::destroy(*(typename _Node::pointer*) __cur);
++ _M_put_node(*(typename _Node::pointer*) __cur);
++ if (! *__cur) break;
++ __cur = __next;
+ }
      }
-+*/ }
  
    template<typename _Tp, typename _Alloc>
      typename list<_Tp,_Alloc>::iterator
- list<_Tp,_Alloc>::
- insert(iterator __position, const value_type& __x)
-@@ -235,12 +261,12 @@
+@@ -235,12 +257,12 @@
      void
      list<_Tp,_Alloc>::
      sort()
@@ -76,7 +69,7 @@
          list __tmp[64];
          list * __fill = &__tmp[0];
          list * __counter;
-@@ -339,12 +365,12 @@
+@@ -339,12 +361,12 @@
        void
        list<_Tp,_Alloc>::
        sort(_StrictWeakOrdering __comp)

Modified: sandbox/shifted_ptr/bits/stl_list.h
==============================================================================
--- sandbox/shifted_ptr/bits/stl_list.h (original)
+++ sandbox/shifted_ptr/bits/stl_list.h 2008-09-29 05:44:28 EDT (Mon, 29 Sep 2008)
@@ -1183,8 +1183,6 @@
       _M_insert(iterator __position, const value_type& __x)
       {
         __position._M_node->hook(reinterpret_cast<typename _List_node_base<_Alloc>::value_type*>(_M_create_node(__x)));
- //typename _Base::_Node_Alloc_type::value_type* __tmp = _M_create_node(__x);
- //static_cast<_Node &>(*__tmp).hook(__position._M_node);
       }
 
       // Erases element at position given.

Modified: sandbox/shifted_ptr/bits/stl_list.h.patch
==============================================================================
--- sandbox/shifted_ptr/bits/stl_list.h.patch (original)
+++ sandbox/shifted_ptr/bits/stl_list.h.patch 2008-09-29 05:44:28 EDT (Mon, 29 Sep 2008)
@@ -1,5 +1,5 @@
 --- /local/include/c++/3.4.5/bits/stl_list.h Wed Jan 18 11:06:54 2006
-+++ stl_list.h Tue Aug 12 02:58:50 2008
++++ stl_list.h Mon Sep 29 02:26:16 2008
 @@ -69,62 +69,82 @@
    // latter publicly inherits from the former in an effort to reduce code
    // duplication. This results in some "needless" static_cast'ing later on,
@@ -431,7 +431,7 @@
         * @brief Sort the elements.
         *
         * Sorts the elements of this list in NlogN time. Equivalent
-@@ -1158,12 +1180,13 @@
+@@ -1158,12 +1180,11 @@
  
        // Inserts new element at position given and with value given.
        void
@@ -440,8 +440,6 @@
 - _Node* __tmp = _M_create_node(__x);
 - __tmp->hook(__position._M_node);
 + __position._M_node->hook(reinterpret_cast<typename _List_node_base<_Alloc>::value_type*>(_M_create_node(__x)));
-+ //typename _Base::_Node_Alloc_type::value_type* __tmp = _M_create_node(__x);
-+ //static_cast<_Node &>(*__tmp).hook(__position._M_node);
        }
  
        // Erases element at position given.

Modified: sandbox/shifted_ptr/boost/detail/shifted_ptr_base.hpp
==============================================================================
--- sandbox/shifted_ptr/boost/detail/shifted_ptr_base.hpp (original)
+++ sandbox/shifted_ptr/boost/detail/shifted_ptr_base.hpp 2008-09-29 05:44:28 EDT (Mon, 29 Sep 2008)
@@ -41,17 +41,30 @@
 template <typename T>
         class shifted_ptr_base
         {
- typedef T element_type;
+ typedef T value_type;
+ typedef shifted<value_type> element_type;
+
                 template <typename> friend class shifted_ptr_base;
 
+ // Borland 5.5.1 specific workaround
+ typedef shifted_ptr_base<value_type> this_type;
+
         protected:
- element_type * po_;
+ value_type * po_;
 
         public:
                 shifted_ptr_base() : po_(0)
                 {
                 }
 
+ ~shifted_ptr_base()
+ {
+ if (po_)
+ {
+ header()->release();
+ }
+ }
+
                 template <typename V>
                         shifted_ptr_base(detail::sh::shifted<V> * p) : po_(p->element())
                         {
@@ -62,7 +75,7 @@
                         {
                         }
 
- shifted_ptr_base(shifted_ptr_base<element_type> const & p) : po_(p.share())
+ shifted_ptr_base(shifted_ptr_base<value_type> const & p) : po_(p.share())
                         {
                         }
 
@@ -84,27 +97,27 @@
                                 return * this;
                         }
 
- shifted_ptr_base & operator = (shifted_ptr_base<element_type> const & p)
+ shifted_ptr_base & operator = (shifted_ptr_base<value_type> const & p)
                         {
- return operator = <element_type>(p);
+ return operator = <value_type>(p);
                         }
 
- element_type & operator * () const
+ value_type & operator * () const
                 {
                         return * po_;
                 }
 
- element_type * operator -> () const
+ value_type * operator -> () const
                 {
                         return po_;
                 }
 
- element_type * get() const
+ value_type * get() const
                 {
                         return po_;
                 }
 
- element_type * share() const
+ value_type * share() const
                 {
                         if (po_)
                         {
@@ -113,7 +126,7 @@
                         return po_;
                 }
 
- void reset(element_type * p = 0)
+ void reset(value_type * p = 0)
                 {
                         if (po_)
                         {
@@ -122,19 +135,58 @@
                         po_ = p;
                 }
 
- ~shifted_ptr_base()
- {
- if (po_)
- {
- header()->release();
- }
- }
+#if ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570) ) || defined(__CINT__)
+ operator bool () const
+ {
+ return po_ != 0;
+ }
+#elif defined( _MANAGED )
+ static void unspecified_bool( this_type*** )
+ {
+ }
+
+ typedef void (*unspecified_bool_type)( this_type*** );
+
+ operator unspecified_bool_type() const // never throws
+ {
+ return po_ == 0? 0: unspecified_bool;
+ }
+#elif \
+ ( defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \
+ ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) || \
+ ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) )
+
+ typedef value_type * (this_type::*unspecified_bool_type)() const;
+
+ operator unspecified_bool_type() const // never throws
+ {
+ return po_ == 0? 0: &this_type::get;
+ }
+#else
+ typedef value_type * this_type::*unspecified_bool_type;
+
+ operator unspecified_bool_type() const // never throws
+ {
+ return po_ == 0? 0: &this_type::po_;
+ }
+#endif
+
+ // operator! is redundant, but some compilers need it
 
+ bool operator! () const // never throws
+ {
+ return po_ == 0;
+ }
+
+ long use_count() const // never throws
+ {
+ return header()->use_count();
+ }
 
         protected:
                 detail::sh::owned_base * header() const
                 {
- detail::sh::owned_base * p = (shifted<element_type> *) (typename shifted<element_type>::roofof) static_cast<element_type *>(rootof<is_polymorphic<element_type>::value>::get(po_));
+ detail::sh::owned_base * p = (shifted<value_type> *) (typename shifted<value_type>::roofof) static_cast<value_type *>(rootof<is_polymorphic<value_type>::value>::get(po_));
                         return p;
                 }
         };
@@ -144,17 +196,30 @@
 template <typename T, size_t N>
         class shifted_ptr_base<T [N]>
         {
- typedef T element_type[N];
+ typedef T value_type[N];
+ typedef shifted<value_type> element_type;
+
                 template <typename> friend class shifted_ptr_base;
 
+ // Borland 5.5.1 specific workaround
+ typedef shifted_ptr_base<value_type> this_type;
+
         protected:
- element_type * po_;
+ value_type * po_;
 
         public:
                 shifted_ptr_base() : po_(0)
                 {
                 }
 
+ ~shifted_ptr_base()
+ {
+ if (po_)
+ {
+ header()->release();
+ }
+ }
+
                 template <typename V>
                         shifted_ptr_base(detail::sh::shifted<V> * p) : po_(p->element())
                         {
@@ -165,7 +230,7 @@
                         {
                         }
 
- shifted_ptr_base(shifted_ptr_base<element_type> const & p) : po_(p.share())
+ shifted_ptr_base(shifted_ptr_base<value_type> const & p) : po_(p.share())
                         {
                         }
 
@@ -187,9 +252,9 @@
                                 return * this;
                         }
 
- shifted_ptr_base & operator = (shifted_ptr_base<element_type> const & p)
+ shifted_ptr_base & operator = (shifted_ptr_base<value_type> const & p)
                         {
- return operator = <element_type>(p);
+ return operator = <value_type>(p);
                         }
 
                 T & operator [] (std::size_t n)
@@ -202,12 +267,12 @@
                         return ** (po_ + n);
                 }
 
- element_type * get() const
+ value_type * get() const
                 {
                         return po_;
                 }
 
- element_type * share() const
+ value_type * share() const
                 {
                         if (po_)
                         {
@@ -216,7 +281,7 @@
                         return po_;
                 }
 
- void reset(element_type * p = 0)
+ void reset(value_type * p = 0)
                 {
                         if (po_)
                         {
@@ -225,19 +290,58 @@
                         po_ = p;
                 }
 
- ~shifted_ptr_base()
- {
- if (po_)
- {
- header()->release();
- }
- }
+#if ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570) ) || defined(__CINT__)
+ operator bool () const
+ {
+ return po_ != 0;
+ }
+#elif defined( _MANAGED )
+ static void unspecified_bool( this_type*** )
+ {
+ }
+
+ typedef void (*unspecified_bool_type)( this_type*** );
+
+ operator unspecified_bool_type() const // never throws
+ {
+ return po_ == 0? 0: unspecified_bool;
+ }
+#elif \
+ ( defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \
+ ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) || \
+ ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) )
+
+ typedef value_type * (this_type::*unspecified_bool_type)() const;
+
+ operator unspecified_bool_type() const // never throws
+ {
+ return po_ == 0? 0: &this_type::get;
+ }
+#else
+ typedef value_type * this_type::*unspecified_bool_type;
+
+ operator unspecified_bool_type() const // never throws
+ {
+ return po_ == 0? 0: &this_type::po_;
+ }
+#endif
+
+ // operator! is redundant, but some compilers need it
 
+ bool operator! () const // never throws
+ {
+ return po_ == 0;
+ }
+
+ long use_count() const // never throws
+ {
+ return header()->use_count();
+ }
 
         protected:
                 detail::sh::owned_base * header() const
                 {
- return (shifted<element_type> *) (typename shifted<element_type>::roofof) static_cast<element_type *>(rootof<is_polymorphic<element_type>::value>::get(po_));
+ return (shifted<value_type> *) (typename shifted<value_type>::roofof) static_cast<value_type *>(rootof<is_polymorphic<value_type>::value>::get(po_));
                 }
         };
 #endif
@@ -246,17 +350,30 @@
 template <>
         class shifted_ptr_base<void>
         {
- typedef void element_type;
+ typedef void value_type;
+ typedef shifted<value_type> element_type;
+
                 template <typename> friend class shifted_ptr_base;
 
+ // Borland 5.5.1 specific workaround
+ typedef shifted_ptr_base<value_type> this_type;
+
         protected:
- element_type * po_;
+ value_type * po_;
 
         public:
                 shifted_ptr_base() : po_(0)
                 {
                 }
 
+ ~shifted_ptr_base()
+ {
+ if (po_)
+ {
+ header()->release();
+ }
+ }
+
                 template <typename V>
                         shifted_ptr_base(detail::sh::shifted<V> * p) : po_(p->element())
                         {
@@ -267,7 +384,7 @@
                         {
                         }
 
- shifted_ptr_base(shifted_ptr_base<element_type> const & p) : po_(p.share())
+ shifted_ptr_base(shifted_ptr_base<value_type> const & p) : po_(p.share())
                         {
                         }
 
@@ -289,17 +406,17 @@
                                 return * this;
                         }
 
- shifted_ptr_base & operator = (shifted_ptr_base<element_type> const & p)
+ shifted_ptr_base & operator = (shifted_ptr_base<value_type> const & p)
                         {
- return operator = <element_type>(p);
+ return operator = <value_type>(p);
                         }
 
- element_type * get() const
+ value_type * get() const
                 {
                         return po_;
                 }
 
- element_type * share() const
+ value_type * share() const
                 {
                         if (po_)
                         {
@@ -308,7 +425,7 @@
                         return po_;
                 }
 
- void reset(element_type * p = 0)
+ void reset(value_type * p = 0)
                 {
                         if (po_)
                         {
@@ -317,19 +434,58 @@
                         po_ = p;
                 }
 
- ~shifted_ptr_base()
- {
- if (po_)
- {
- header()->release();
- }
- }
+#if ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570) ) || defined(__CINT__)
+ operator bool () const
+ {
+ return po_ != 0;
+ }
+#elif defined( _MANAGED )
+ static void unspecified_bool( this_type*** )
+ {
+ }
+
+ typedef void (*unspecified_bool_type)( this_type*** );
+
+ operator unspecified_bool_type() const // never throws
+ {
+ return po_ == 0? 0: unspecified_bool;
+ }
+#elif \
+ ( defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \
+ ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) || \
+ ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) )
+
+ typedef value_type * (this_type::*unspecified_bool_type)() const;
+
+ operator unspecified_bool_type() const // never throws
+ {
+ return po_ == 0? 0: &this_type::get;
+ }
+#else
+ typedef value_type * this_type::*unspecified_bool_type;
+
+ operator unspecified_bool_type() const // never throws
+ {
+ return po_ == 0? 0: &this_type::po_;
+ }
+#endif
+
+ // operator! is redundant, but some compilers need it
 
+ bool operator! () const // never throws
+ {
+ return po_ == 0;
+ }
+
+ long use_count() const // never throws
+ {
+ return header()->use_count();
+ }
 
         protected:
                 detail::sh::owned_base * header() const
                 {
- return (shifted<element_type> *) (shifted<element_type>::roofof) static_cast<element_type *>(rootof<is_polymorphic<element_type>::value>::get(po_));
+ return (shifted<value_type> *) (shifted<value_type>::roofof) static_cast<value_type *>(rootof<is_polymorphic<value_type>::value>::get(po_));
                 }
         };
 

Modified: sandbox/shifted_ptr/boost/shifted_allocator.hpp
==============================================================================
--- sandbox/shifted_ptr/boost/shifted_allocator.hpp (original)
+++ sandbox/shifted_ptr/boost/shifted_allocator.hpp 2008-09-29 05:44:28 EDT (Mon, 29 Sep 2008)
@@ -46,14 +46,16 @@
 template <typename T>
     class shifted_allocator
     {
+ typedef T element_type;
+
     public:
         typedef shifted<T> value_type;
         typedef size_t size_type;
         typedef ptrdiff_t difference_type;
         typedef shifted_ptr<T> pointer;
         typedef shifted_ptr<const T> const_pointer;
- typedef value_type & reference;
- typedef const value_type & const_reference;
+ typedef element_type & reference;
+ typedef const element_type & const_reference;
 
         template <typename U>
             struct rebind
@@ -70,6 +72,11 @@
         pointer address(reference x) const { return & x; }
         const_pointer address(const_reference x) const { return & x; }
 
+ size_type max_size() const throw()
+ {
+ return size_t(-1) / sizeof(T);
+ }
+
         value_type * allocate(size_type s, const void * = 0)
         {
             //value_type * p = (value_type *) value_type::operator new(sizeof(value_type));
@@ -78,15 +85,6 @@
             return p;
         }
 
- void deallocate(pointer & p, size_type)
- {
- }
-
- size_type max_size() const throw()
- {
- return size_t(-1) / sizeof(T);
- }
-
         void construct(value_type * p, const T & x)
         {
             //::new (p) owned_base;
@@ -97,6 +95,10 @@
         {
             p.reset();
         }
+
+ void deallocate(pointer & p, size_type)
+ {
+ }
     };
 
 template <typename T>

Modified: sandbox/shifted_ptr/boost/shifted_ptr.hpp
==============================================================================
--- sandbox/shifted_ptr/boost/shifted_ptr.hpp (original)
+++ sandbox/shifted_ptr/boost/shifted_ptr.hpp 2008-09-29 05:44:28 EDT (Mon, 29 Sep 2008)
@@ -162,7 +162,8 @@
         };
 
     public:
- typedef T element_type;
+ typedef T value_type;
+ typedef shifted<value_type> element_type;
 
 
         shifted_ptr() : ps_(0)

Modified: sandbox/shifted_ptr/libs/smart_ptr/example/shifted_ptr_test2.cpp
==============================================================================
--- sandbox/shifted_ptr/libs/smart_ptr/example/shifted_ptr_test2.cpp (original)
+++ sandbox/shifted_ptr/libs/smart_ptr/example/shifted_ptr_test2.cpp 2008-09-29 05:44:28 EDT (Mon, 29 Sep 2008)
@@ -65,8 +65,8 @@
     vector() { ++count; }
     ~vector() { --count; }
     vector(const vector& other) : elements(other.elements) { ++count; }
- std::vector<shifted_ptr<vector> > elements;
- //std::list<shifted_ptr<vector>, shifted_allocator< shifted_ptr<vector> > > elements; //! works fine
+ //std::vector<shifted_ptr<vector> > elements;
+ std::list<shifted_ptr<vector>, shifted_allocator< shifted_ptr<vector> > > elements; //! works fine
 };
 
 struct create_type {


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