merged from trunk to branch

[SVN r33545]
This commit is contained in:
Joaquín M. López Muñoz 2006-04-05 07:28:50 +00:00
parent 37ac7c0377
commit 3a663bd7c4
7 changed files with 62 additions and 21 deletions

View File

@ -396,7 +396,7 @@ section</a>. The complexity signature of ordered indices is:
<li>insertion: <code>i(n)=log(n)</code>,</li>
<li>hinted insertion: <code>h(n)=1</code> (constant) if the hint element
precedes the point of insertion, <code>h(n)=log(n)</code> otherwise,</li>
<li>deletion: <code>d(n)=1</code> (constant),</li>
<li>deletion: <code>d(n)=1</code> (amortized constant),</li>
<li>replacement: <code>r(n)=1</code> (constant) if the element position does not
change, <code>r(n)=log(n)</code> otherwise,</li>
<li>modifying: <code>m(n)=1</code> (constant) if the element position does not
@ -954,7 +954,7 @@ Hashed indices
<br>
<p>Revised February 6th 2006</p>
<p>Revised March 31st 2006</p>
<p>&copy; Copyright 2003-2006 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
Distributed under the Boost Software

View File

@ -251,6 +251,8 @@ inline void detach_equivalent_iterators(Iterator& it)
}
}
template<typename Container> class safe_container; /* fwd decl. */
} /* namespace multi_index::safe_mode */
namespace detail{
@ -308,6 +310,7 @@ BOOST_MULTI_INDEX_PRIVATE_IF_MEMBER_TEMPLATE_FRIENDS:
friend class safe_container_base;
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
template<typename> friend class safe_mode::safe_container;
template<typename Iterator> friend
void safe_mode::detach_equivalent_iterators(Iterator&);
#endif
@ -324,13 +327,20 @@ class safe_container_base:private noncopyable
public:
safe_container_base(){}
BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
friend class safe_iterator_base;
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
template<typename Iterator> friend
void safe_mode::detach_equivalent_iterators(Iterator&);
#endif
~safe_container_base()
{
detach_all_iterators();
}
/* Detaches all remaining iterators, which by now will
* be those pointing to the end of the container.
*/
void detach_all_iterators()
{
for(safe_iterator_base* it=header.next;it;it=it->next)it->cont=0;
header.next=0;
}
@ -343,14 +353,6 @@ public:
std::swap(header.next,x.header.next);
}
BOOST_MULTI_INDEX_PRIVATE_IF_MEMBER_TEMPLATE_FRIENDS:
friend class safe_iterator_base;
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
template<typename Iterator> friend
void safe_mode::detach_equivalent_iterators(Iterator&);
#endif
safe_iterator_base header;
#if defined(BOOST_HAS_THREADS)
@ -532,6 +534,23 @@ class safe_container:public detail::safe_container_base
typedef detail::safe_container_base super;
public:
void detach_dereferenceable_iterators()
{
typedef typename Container::iterator iterator;
iterator end_=static_cast<Container*>(this)->end();
iterator *prev_,*next_;
for(
prev_=static_cast<iterator*>(&this->header);
(next_=static_cast<iterator*>(prev_->next))!=0;){
if(*next_!=end_){
prev_->next=next_->next;
next_->cont=0;
}
else prev_=next_;
}
}
void swap(safe_container<Container>& x)
{
super::swap(x);

View File

@ -1,4 +1,4 @@
/* Copyright 2003-2005 Joaquín M López Muñoz.
/* Copyright 2003-2006 Joaquín M López Muñoz.
* 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)
@ -671,7 +671,7 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
first_bucket=buckets.size();
#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
safe_super::detach_all_iterators();
safe_super::detach_dereferenceable_iterators();
#endif
}

View File

@ -1,4 +1,4 @@
/* Copyright 2003-2005 Joaquín M López Muñoz.
/* Copyright 2003-2006 Joaquín M López Muñoz.
* 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)
@ -593,7 +593,7 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
empty_initialize();
#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
safe_super::detach_all_iterators();
safe_super::detach_dereferenceable_iterators();
#endif
}

View File

@ -675,7 +675,7 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
ptrs.clear();
#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
safe_super::detach_all_iterators();
safe_super::detach_dereferenceable_iterators();
#endif
}

View File

@ -1,4 +1,4 @@
/* Copyright 2003-2005 Joaquín M López Muñoz.
/* Copyright 2003-2006 Joaquín M López Muñoz.
* 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)
@ -577,7 +577,7 @@ BOOST_MULTI_INDEX_PROTECTED_IF_MEMBER_TEMPLATE_FRIENDS:
empty_initialize();
#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
safe_super::detach_all_iterators();
safe_super::detach_dereferenceable_iterators();
#endif
}

View File

@ -124,6 +124,16 @@ static void local_test_safe_mode(
i3.erase(it);
CATCH_SAFE_MODE(safe_mode::invalid_iterator)
TRY_SAFE_MODE
iterator it;
{
container c3;
index_type& i3=Policy::index_from_container(c3);
it=i3.end();
}
it=it;
CATCH_SAFE_MODE(safe_mode::invalid_iterator)
TRY_SAFE_MODE
iterator it;
{
@ -190,6 +200,18 @@ static void local_test_safe_mode(
i3.clear();
it=i3.end();
}
/* testcase for doppelganger bug of that discovered for STLport at
* http://lists.boost.org/Archives/boost/2006/04/102740.php
*/
{
container c3;
index_type& i3=Policy::index_from_container(c3);
iterator it=i3.end();
i3.clear();
it=it;
BOOST_CHECK(it==i3.end());
}
}
template<typename Policy>