|
Boost-Commit : |
From: phil_at_[hidden]
Date: 2008-07-31 05:36:17
Author: pbouchard
Date: 2008-07-31 05:36:16 EDT (Thu, 31 Jul 2008)
New Revision: 47905
URL: http://svn.boost.org/trac/boost/changeset/47905
Log:
STL support works at 90%!!
Text files modified:
sandbox/shifted_ptr/bits/list.tcc | 8
sandbox/shifted_ptr/bits/list.tcc.patch | 53 ++++++++----
sandbox/shifted_ptr/bits/stl_list.h | 16 +--
sandbox/shifted_ptr/bits/stl_list.h.patch | 162 ++++++++++++++++++++++++++++-----------
sandbox/shifted_ptr/boost/detail/sh_owned_base_nt.hpp | 23 ++--
sandbox/shifted_ptr/boost/shifted_allocator.hpp | 19 ----
sandbox/shifted_ptr/boost/shifted_ptr.hpp | 56 ++++++-------
sandbox/shifted_ptr/libs/smart_ptr/example/shifted_ptr_test2.cpp | 8 +
8 files changed, 204 insertions(+), 141 deletions(-)
Modified: sandbox/shifted_ptr/bits/list.tcc
==============================================================================
--- sandbox/shifted_ptr/bits/list.tcc (original)
+++ sandbox/shifted_ptr/bits/list.tcc 2008-07-31 05:36:16 EDT (Thu, 31 Jul 2008)
@@ -76,7 +76,7 @@
{
template<typename _Alloc>
void
- _List_node_base<_Alloc>::hook(pointer const & __position)
+ _List_node_base<_Alloc>::hook(_List_node_base * const __position)
{
this->_M_next = __position;
this->_M_prev = __position->_M_prev;
@@ -88,8 +88,8 @@
void
_List_node_base<_Alloc>::unhook()
{
- pointer const __next_node = this->_M_next;
- pointer const __prev_node = this->_M_prev;
+ _List_node_base* __next_node = this->_M_next;
+ _List_node_base* __prev_node = this->_M_prev;
__prev_node->_M_next = __next_node;
__next_node->_M_prev = __prev_node;
}
@@ -116,7 +116,7 @@
list<_Tp,_Alloc>::
insert(iterator __position, const value_type& __x)
{
- typename _Node::pointer __tmp = _M_create_node(__x);
+ _Node* __tmp = _M_create_node(__x);
__tmp->hook(__position._M_node);
return __tmp;
}
Modified: sandbox/shifted_ptr/bits/list.tcc.patch
==============================================================================
--- sandbox/shifted_ptr/bits/list.tcc.patch (original)
+++ sandbox/shifted_ptr/bits/list.tcc.patch 2008-07-31 05:36:16 EDT (Thu, 31 Jul 2008)
@@ -1,6 +1,6 @@
--- /local/include/c++/3.4.5/bits/list.tcc Wed Jan 18 11:06:46 2006
-+++ list.tcc Tue Jul 22 23:41:23 2008
-@@ -51,42 +51,74 @@
++++ list.tcc Thu Jul 31 02:28:37 2008
+@@ -51,31 +51,63 @@
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
@@ -29,7 +29,7 @@
{
+ template<typename _Alloc>
+ void
-+ _List_node_base<_Alloc>::hook(pointer const & __position)
++ _List_node_base<_Alloc>::hook(_List_node_base * const __position)
+ {
+ this->_M_next = __position;
+ this->_M_prev = __position->_M_prev;
@@ -41,8 +41,8 @@
+ void
+ _List_node_base<_Alloc>::unhook()
+ {
-+ pointer const __next_node = this->_M_next;
-+ pointer const __prev_node = this->_M_prev;
++ _List_node_base* __next_node = this->_M_next;
++ _List_node_base* __prev_node = this->_M_prev;
+ __prev_node->_M_next = __next_node;
+ __next_node->_M_prev = __prev_node;
+ }
@@ -54,10 +54,11 @@
{
- typedef _List_node<_Tp> _Node;
- _Node* __cur = static_cast<_Node*>(this->_M_impl._M_node._M_next);
+- while (__cur != &this->_M_impl._M_node)
+ typedef _List_node<_Tp,_Alloc> _Node;
+ typedef _List_node_base<_Alloc> _Node_base;
-+ _Node* __cur = static_cast<_Node*>(static_cast<_Node_base*>(&*this->_M_impl._M_node._M_next));
- while (__cur != &this->_M_impl._M_node)
++ _Node* __cur = static_cast<_Node*>(static_cast<_Node_base*>(&*this->_M_impl._M_node->_M_next));
++ while (__cur != &*this->_M_impl._M_node)
{
_Node* __tmp = __cur;
- __cur = static_cast<_Node*>(__cur->_M_next);
@@ -67,15 +68,33 @@
}
}
- template<typename _Tp, typename _Alloc>
- typename list<_Tp,_Alloc>::iterator
+@@ -235,12 +267,12 @@
+ void
list<_Tp,_Alloc>::
- insert(iterator __position, const value_type& __x)
+ sort()
{
-- _Node* __tmp = _M_create_node(__x);
-+ typename _Node::pointer __tmp = _M_create_node(__x);
- __tmp->hook(__position._M_node);
- return __tmp;
- }
-
- template<typename _Tp, typename _Alloc>
+ // Do nothing if the list has length 0 or 1.
+- if (this->_M_impl._M_node._M_next != &this->_M_impl._M_node
+- && this->_M_impl._M_node._M_next->_M_next != &this->_M_impl._M_node)
++ if (this->_M_impl._M_node->_M_next != this->_M_impl._M_node
++ && this->_M_impl._M_node->_M_next->_M_next != this->_M_impl._M_node)
+ {
+ list __carry;
+ list __tmp[64];
+ list * __fill = &__tmp[0];
+ list * __counter;
+@@ -339,12 +371,12 @@
+ void
+ list<_Tp,_Alloc>::
+ sort(_StrictWeakOrdering __comp)
+ {
+ // Do nothing if the list has length 0 or 1.
+- if (this->_M_impl._M_node._M_next != &this->_M_impl._M_node
+- && this->_M_impl._M_node._M_next->_M_next != &this->_M_impl._M_node)
++ if (this->_M_impl._M_node->_M_next != this->_M_impl._M_node
++ && this->_M_impl._M_node->_M_next->_M_next != this->_M_impl._M_node)
+ {
+ list __carry;
+ list __tmp[64];
+ list * __fill = &__tmp[0];
+ list * __counter;
Modified: sandbox/shifted_ptr/bits/stl_list.h
==============================================================================
--- sandbox/shifted_ptr/bits/stl_list.h (original)
+++ sandbox/shifted_ptr/bits/stl_list.h 2008-07-31 05:36:16 EDT (Thu, 31 Jul 2008)
@@ -99,14 +99,14 @@
swap(_List_node_base& __x, _List_node_base& __y);
void
- transfer(pointer const & __first,
- pointer const & __last);
+ transfer(_List_node_base * const __first,
+ _List_node_base * const __last);
void
reverse();
void
- hook(pointer const & __position);
+ hook(_List_node_base * const __position);
void
unhook();
@@ -124,6 +124,8 @@
typedef typename _Node_Alloc_type::const_reference const_reference;
_Tp _M_data; ///< User's data.
+
+ _List_node(const _Tp& __x = _Tp()) : _M_data(__x) {}
};
/**
@@ -461,7 +463,7 @@
_Node* __p = this->_M_get_node();
try
{
- std::_Construct(&__p->_M_data, __x);
+ _M_impl._Base::_Node_Alloc_type::construct(__p, _Node(__x));
}
catch(...)
{
@@ -483,7 +485,7 @@
_Node* __p = this->_M_get_node();
try
{
- std::_Construct(&__p->_M_data);
+ _M_impl._Base::_Node_Alloc_type::construct(__p, _Node());
}
catch(...)
{
@@ -1195,13 +1197,9 @@
_M_erase(iterator __position)
{
__position._M_node->unhook();
-/**
- FIXME: distinguish with raw pointers
-
_Node* __n = static_cast<_Node*>(__position._M_node);
std::_Destroy(&__n->_M_data);
_M_put_node(__n);
-*/
}
};
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-07-31 05:36:16 EDT (Thu, 31 Jul 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 Wed Jul 23 00:33:26 2008
++++ stl_list.h Thu Jul 31 02:32:03 2008
@@ -51,10 +51,21 @@
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
@@ -22,7 +22,7 @@
* You should not attempt to use it directly.
*/
-@@ -69,62 +80,77 @@
+@@ -69,14 +80,22 @@
// latter publicly inherits from the former in an effort to reduce code
// duplication. This results in some "needless" static_cast'ing later on,
// but it's all safe downcasting.
@@ -47,18 +47,7 @@
swap(_List_node_base& __x, _List_node_base& __y);
void
-- transfer(_List_node_base * const __first,
-- _List_node_base * const __last);
-+ transfer(pointer const & __first,
-+ pointer const & __last);
-
- void
- reverse();
-
- void
-- hook(_List_node_base * const __position);
-+ hook(pointer const & __position);
-
+@@ -92,39 +111,48 @@
void
unhook();
};
@@ -77,6 +66,8 @@
+ typedef typename _Node_Alloc_type::const_reference const_reference;
+
_Tp _M_data; ///< User's data.
++
++ _List_node(const _Tp& __x = _Tp()) : _M_data(__x) {}
};
/**
@@ -111,7 +102,7 @@
// Must downcast from List_node_base to _List_node to get to _M_data.
reference
operator*() const
-@@ -171,37 +197,37 @@
+@@ -171,37 +199,37 @@
bool
operator!=(const _Self& __x) const
{ return _M_node != __x._M_node; }
@@ -155,7 +146,7 @@
_List_const_iterator(const iterator& __x)
: _M_node(__x._M_node) { }
-@@ -216,11 +242,11 @@
+@@ -216,11 +244,11 @@
{ return &static_cast<_Node*>(_M_node)->_M_data; }
_Self&
@@ -168,7 +159,7 @@
_Self
operator++(int)
-@@ -252,23 +278,23 @@
+@@ -252,23 +280,23 @@
bool
operator!=(const _Self& __x) const
{ return _M_node != __x._M_node; }
@@ -199,14 +190,14 @@
/**
* @if maint
-@@ -290,41 +316,47 @@
+@@ -290,41 +318,41 @@
//
// We put this to the test in the constructors and in
// get_allocator, where we use conversions between
// allocator_type and _Node_Alloc_type. The conversion is
// required by table 32 in [20.1.5].
- typedef typename _Alloc::template rebind<_List_node<_Tp> >::other
-+ typedef typename _Alloc::template rebind<_List_node<_Tp, _Alloc> >::other
++ typedef typename _Alloc::template rebind<_List_node<_Tp, _Alloc> >::other
_Node_Alloc_type;
@@ -215,16 +206,10 @@
- _List_node_base _M_node;
- _List_impl (const _Node_Alloc_type& __a)
- : _Node_Alloc_type(__a)
-+ _List_base & _M_base;
-+ _List_node_base<_Alloc> & _M_node;
++ typename _List_node_base<_Alloc>::pointer _M_node;
+ _List_impl (const _Node_Alloc_type& __a, _List_base& __b)
-+ : _Node_Alloc_type(__a), _M_base(__b), _M_node(* new (_M_base._M_get_node()) _List_node_base<_Alloc>())
++ : _Node_Alloc_type(__a), _M_node(new (__b._M_get_node()) _List_node_base<_Alloc>())
{ }
-+ ~_List_impl ()
-+ {
-+ _M_node.~_List_node_base<_Alloc>();
-+ _M_base._M_put_node(static_cast<_List_node<_Tp, _Alloc> *>(&_M_node));
-+ }
};
_List_impl _M_impl;
@@ -255,7 +240,22 @@
// This is what actually destroys the list.
~_List_base()
{ _M_clear(); }
-@@ -393,26 +425,26 @@
+@@ -333,12 +361,12 @@
+ _M_clear();
+
+ void
+ _M_init()
+ {
+- this->_M_impl._M_node._M_next = &this->_M_impl._M_node;
+- this->_M_impl._M_node._M_prev = &this->_M_impl._M_node;
++ this->_M_impl._M_node->_M_next = this->_M_impl._M_node;
++ this->_M_impl._M_node->_M_prev = this->_M_impl._M_node;
+ }
+ };
+
+ /**
+ * @brief A standard container with linear time access to elements,
+@@ -393,26 +421,26 @@
typedef _List_base<_Tp, _Alloc> _Base;
@@ -289,14 +289,40 @@
* One data member plus two memory-handling functions. If the
* _Alloc type requires separate instances, then one of those
* will also be included, accumulated from the topmost parent.
-@@ -595,20 +627,20 @@
+@@ -433,11 +461,11 @@
+ _M_create_node(const value_type& __x)
+ {
+ _Node* __p = this->_M_get_node();
+ try
+ {
+- std::_Construct(&__p->_M_data, __x);
++ _M_impl._Base::_Node_Alloc_type::construct(__p, _Node(__x));
+ }
+ catch(...)
+ {
+ _M_put_node(__p);
+ __throw_exception_again;
+@@ -455,11 +483,11 @@
+ _M_create_node()
+ {
+ _Node* __p = this->_M_get_node();
+ try
+ {
+- std::_Construct(&__p->_M_data);
++ _M_impl._Base::_Node_Alloc_type::construct(__p, _Node());
+ }
+ catch(...)
+ {
+ _M_put_node(__p);
+ __throw_exception_again;
+@@ -595,37 +623,37 @@
* Returns a read/write iterator that points to the first element in the
* %list. Iteration is done in ordinary element order.
*/
iterator
begin()
- { return this->_M_impl._M_node._M_next; }
-+ { return iterator(&*this->_M_impl._M_node._M_next); }
++ { return iterator(&*this->_M_impl._M_node->_M_next); }
/**
* Returns a read-only (constant) iterator that points to the
@@ -306,13 +332,58 @@
const_iterator
begin() const
- { return this->_M_impl._M_node._M_next; }
-+ { return const_iterator(&*this->_M_impl._M_node._M_next); }
++ { return const_iterator(&*this->_M_impl._M_node->_M_next); }
/**
* Returns a read/write iterator that points one past the last
* element in the %list. Iteration is done in ordinary element
* order.
-@@ -908,11 +940,11 @@
+ */
+ iterator
+- end() { return &this->_M_impl._M_node; }
++ end() { return &*this->_M_impl._M_node; }
+
+ /**
+ * Returns a read-only (constant) iterator that points one past
+ * the last element in the %list. Iteration is done in ordinary
+ * element order.
+ */
+ const_iterator
+ end() const
+- { return &this->_M_impl._M_node; }
++ { return &*this->_M_impl._M_node; }
+
+ /**
+ * Returns a read/write reverse iterator that points to the last
+ * element in the %list. Iteration is done in reverse element
+ * order.
+@@ -666,11 +694,11 @@
+ * Returns true if the %list is empty. (Thus begin() would equal
+ * end().)
+ */
+ bool
+ empty() const
+- { return this->_M_impl._M_node._M_next == &this->_M_impl._M_node; }
++ { return this->_M_impl._M_node->_M_next == this->_M_impl._M_node; }
+
+ /** Returns the number of elements in the %list. */
+ size_type
+ size() const
+ { return std::distance(begin(), end()); }
+@@ -795,11 +823,11 @@
+ * Note that no data is returned, and if the last element's data
+ * is needed, it should be retrieved before pop_back() is called.
+ */
+ void
+ pop_back()
+- { this->_M_erase(this->_M_impl._M_node._M_prev); }
++ { this->_M_erase(this->_M_impl._M_node->_M_prev); }
+
+ /**
+ * @brief Inserts given value into %list before specified iterator.
+ * @param position An iterator into the %list.
+ * @param x Data to be inserted.
+@@ -908,11 +936,11 @@
* specialized such that std::swap(l1,l2) will feed to this
* function.
*/
@@ -325,21 +396,16 @@
* Erases all the elements. Note that this function only erases
* the elements, and that if the elements themselves are
* pointers, the pointed-to memory is not touched in any way.
-@@ -1167,13 +1199,17 @@
- // Erases element at position given.
+@@ -1071,11 +1099,11 @@
+ *
+ * Reverse the order of elements in the list in linear time.
+ */
void
- _M_erase(iterator __position)
- {
- __position._M_node->unhook();
-+/**
-+ FIXME: distinguish with raw pointers
-+
- _Node* __n = static_cast<_Node*>(__position._M_node);
- std::_Destroy(&__n->_M_data);
- _M_put_node(__n);
-+*/
- }
- };
+ reverse()
+- { this->_M_impl._M_node.reverse(); }
++ { this->_M_impl._M_node->reverse(); }
- /**
- * @brief List equality comparison.
+ /**
+ * @brief Sort the elements.
+ *
+ * Sorts the elements of this list in NlogN time. Equivalent
Modified: sandbox/shifted_ptr/boost/detail/sh_owned_base_nt.hpp
==============================================================================
--- sandbox/shifted_ptr/boost/detail/sh_owned_base_nt.hpp (original)
+++ sandbox/shifted_ptr/boost/detail/sh_owned_base_nt.hpp 2008-07-31 05:36:16 EDT (Thu, 31 Jul 2008)
@@ -95,7 +95,6 @@
if (i->first <= q && q <= i->second)
break;
-//std::cout << __FUNCTION__ << ": " << &* i.base() << " - " << &* alloc_.get()->end() << std::endl;
alloc_.get()->erase(i.base(), alloc_.get()->end());
return (owned_base *)(i->first);
@@ -103,7 +102,7 @@
lpp & construct()
{
- return * constr_.get();
+ return * alloc_.get();
}
void * allocate(std::size_t s)
@@ -112,8 +111,6 @@
alloc_.get()->push_back(std::make_pair(p, p + s));
-//std::cout << __FUNCTION__ << ": " << (void *) p << " - " << (void *) (p + s) << std::endl;
-
return p;
}
@@ -121,8 +118,6 @@
{
char * const q = static_cast<char *>(p);
-//std::cout << __FUNCTION__ << ": " << (void *) q << " - " << (void *) (q + s) << std::endl;
-
lpp::reverse_iterator i;
for (i = alloc_.get()->rbegin(); i != alloc_.get()->rend(); i ++)
if (i->first <= q && q <= i->second)
@@ -152,11 +147,12 @@
{
template <typename U> friend class shifted_allocator;
- intrusive_stack ptrs_;
- intrusive_list inits_;
+ bool init_;
+ intrusive_stack ptrs_;
+ intrusive_list inits_;
protected:
- owned_base()
+ owned_base() : init_(false)
{
inits_.push_back(& init_tag_);
}
@@ -165,11 +161,14 @@
intrusive_list::node set_tag_;
intrusive_list::node init_tag_;
- intrusive_stack * ptrs() { return & ptrs_; }
- intrusive_list * inits() { return & inits_; }
+ intrusive_stack * ptrs() { return & ptrs_; }
+ intrusive_list * inits() { return & inits_; }
intrusive_list::node * set_tag() { return & set_tag_; }
intrusive_list::node * init_tag() { return & init_tag_; }
+ bool init() { return init_; }
+ void init(bool b) { init_ = b; }
+
static pool pool_;
private:
@@ -204,7 +203,7 @@
class roofof;
friend class roofof;
- shifted() : e_() {}
+ shifted() : e_() {}
BOOST_PP_REPEAT_FROM_TO(1, 10, CONSTRUCT_OWNED, shifted)
Modified: sandbox/shifted_ptr/boost/shifted_allocator.hpp
==============================================================================
--- sandbox/shifted_ptr/boost/shifted_allocator.hpp (original)
+++ sandbox/shifted_ptr/boost/shifted_allocator.hpp 2008-07-31 05:36:16 EDT (Thu, 31 Jul 2008)
@@ -40,7 +40,6 @@
STL compliant allocator.
*/
-//! FIXME
template <typename T>
class shifted_allocator
{
@@ -68,43 +67,29 @@
pointer address(reference x) const { return & x; }
const_pointer address(const_reference x) const { return & x; }
- //! FIXME
value_type * allocate(size_type s, const void * = 0)
{
- //return static_cast<shifted<T> *>(::new (shifted<T>::operator new(s)) owned_base)->element();
shifted<T> * p = (shifted<T> *) shifted<T>::operator new(sizeof(shifted<T>));
-std::cout << __FUNCTION__ << ": " << (void *) p << " - " << (void *)((char *) p + sizeof(shifted<T>)) << ", " << (void *) p->element() << std::endl;
-
return static_cast<shifted<T> *>(::new (p) owned_base)->element();
}
- //! FIXME
void deallocate(value_type * p, size_type)
{
-/*
- owned_base * const q = (typename shifted<value_type>::roofof) static_cast<value_type *>(rootof<is_polymorphic<value_type>::value>::get(p));
-
- q->~owned_base();
-
- shifted<T>::operator delete(q);
-*/
}
- //! FIXME
size_type max_size() const throw()
{
return size_t(-1) / sizeof(T);
}
- void construct(pointer p, const T & x)
+ void construct(value_type * p, const value_type & x)
{
::new (p) T(x);
}
- void destroy(pointer p)
+ void destroy(value_type * p)
{
- p->~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-07-31 05:36:16 EDT (Thu, 31 Jul 2008)
@@ -72,8 +72,6 @@
set() : count_(1), redir_(this)
{
-std::cout << __FUNCTION__ << ": " << this << std::endl;
-
includes_.push_back(& tag_);
}
@@ -104,8 +102,6 @@
set * redir() const
{
-//std::cout << __FUNCTION__ << ": " << this << std::endl;
-
if (redir_ == this) return redir_;
else return redir_ = redir_->redir();
}
@@ -128,9 +124,7 @@
void * operator new (size_t s)
{
- void * p = pool_.allocate(s);
-
-std::cout << __FUNCTION__ << ": " << (void *) p << " - " << (void *)((char *) p + sizeof(set)) << std::endl;
+ char * p = reinterpret_cast<char *>(pool_.allocate(s));
return p;
}
@@ -142,13 +136,10 @@
void operator delete (void * p)
{
-//std::cout << __FUNCTION__ << ": " << p << std::endl;
-
pool_.deallocate(static_cast<set *>(p), sizeof(set));
}
};
-
fast_pool_allocator<set> set::pool_;
@@ -177,7 +168,6 @@
shifted_ptr() : ps_(0)
{
-std::cout << __FUNCTION__ << ": " << this << std::endl;
if (! owned_base::pool_.is_from(this))
ps_ = new set();
else
@@ -208,7 +198,8 @@
else
owned_base::pool_.top(this)->ptrs()->push(& pn_);
- ps_->redir(p.ps_);
+ if (init())
+ ps_->redir(p.ps_);
}
shifted_ptr(shifted_ptr<T> const & p) : base(p)
@@ -218,14 +209,14 @@
else
owned_base::pool_.top(this)->ptrs()->push(& pn_);
- ps_->redir(p.ps_);
+ if (init())
+ ps_->redir(p.ps_);
}
template <typename V>
shifted_ptr & operator = (shifted<V> * p)
{
- // initialized yet or not?
- if (ps_ && ! owned_base::pool_.is_from(ps_))
+ if (init())
{
release();
init(p);
@@ -240,15 +231,10 @@
{
if (p.po_ != base::po_)
{
- // initialized yet or not?
-std::cout << ps_ << ": " << p.ps_ << std::endl;
- if (ps_ && ! owned_base::pool_.is_from(ps_) && p.ps_ && ! owned_base::pool_.is_from(p.ps_))
+ if (init() && ps_->redir() != p.ps_->redir())
{
- if (ps_->redir() != p.ps_->redir())
- {
- release();
- ps_->redir(p.ps_);
- }
+ release();
+ ps_->redir(p.ps_);
}
base::operator = (p);
}
@@ -287,8 +273,7 @@
{
shifted<element_type> * const q = (typename shifted<element_type>::roofof) static_cast<element_type *>(rootof<is_polymorphic<element_type>::value>::get(p));
- // initialized yet or not?
- if (ps_ && ! owned_base::pool_.is_from(ps_))
+ if (init())
{
release();
init(q);
@@ -310,6 +295,11 @@
}
private:
+ bool init()
+ {
+ return ps_ && ! owned_base::pool_.is_from(ps_);
+ }
+
void release(bool d = false)
{
if (! owned_base::pool_.is_from(this))
@@ -337,15 +327,19 @@
void init(owned_base * p)
{
- for (intrusive_list::iterator<owned_base, & owned_base::init_tag_> i = p->inits()->begin(), j; j = i, ++ j, i != p->inits()->end(); i = j)
+ if (! p->init())
{
- ps_->elements()->push_back(i->set_tag());
+ for (intrusive_list::iterator<owned_base, & owned_base::init_tag_> i = p->inits()->begin(), j; j = i, ++ j, i != p->inits()->end(); i = j)
+ {
+ ps_->elements()->push_back(i->set_tag());
- for (intrusive_stack::iterator<shifted_ptr, & shifted_ptr::pn_> m = p->ptrs()->begin(), n; n = m, ++ n, m != p->ptrs()->end(); m = n)
- m->ps_ = ps_;
- }
+ for (intrusive_stack::iterator<shifted_ptr, & shifted_ptr::pn_> m = p->ptrs()->begin(), n; n = m, ++ n, m != p->ptrs()->end() && ! m->init(); m = n)
+ m->ps_ = ps_;
+ }
- owned_base::pool_.construct().clear();
+ p->init(true);
+ owned_base::pool_.construct().clear();
+ }
}
};
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-07-31 05:36:16 EDT (Thu, 31 Jul 2008)
@@ -65,6 +65,7 @@
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; //! FIXME
};
@@ -77,7 +78,6 @@
};
int main() {
-/*
count = 0;
{
list l;
@@ -89,20 +89,22 @@
}
}
std::cout << count << std::endl;
-*/
+
count = 0;
{
shifted_ptr<vector> v = new shifted<vector>();
v->elements.push_back(v);
}
std::cout << count << std::endl;
-/*
+
+ count = 0;
{
vector v;
v.elements.push_back(new shifted<vector>());
}
std::cout << count << std::endl;
+/*
count = 0;
{
shifted_ptr<int> test = new shifted<int>(5);
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