mirror of
https://github.com/boostorg/intrusive.git
synced 2025-08-02 22:14:35 +02:00
Fixed stateful value traits and iterator_to.
This commit is contained in:
@@ -36,11 +36,11 @@ struct stateful_value_traits
|
||||
{}
|
||||
|
||||
///Note: non static functions!
|
||||
node_ptr to_node_ptr (value_type &value)
|
||||
node_ptr to_node_ptr (value_type &value) const
|
||||
{ return this->nodes_ + (&value - this->ids_); }
|
||||
const_node_ptr to_node_ptr (const value_type &value) const
|
||||
{ return this->nodes_ + (&value - this->ids_); }
|
||||
pointer to_value_ptr(node_ptr n)
|
||||
pointer to_value_ptr(node_ptr n) const
|
||||
{ return this->ids_ + (n - this->nodes_); }
|
||||
const_pointer to_value_ptr(const_node_ptr n) const
|
||||
{ return this->ids_ + (n - this->nodes_); }
|
||||
|
@@ -188,10 +188,10 @@ struct bstbase3
|
||||
}
|
||||
|
||||
iterator iterator_to(reference value)
|
||||
{ return iterator (value_traits::to_node_ptr(value), this->value_traits_ptr()); }
|
||||
{ return iterator (this->get_value_traits().to_node_ptr(value), this->value_traits_ptr()); }
|
||||
|
||||
const_iterator iterator_to(const_reference value) const
|
||||
{ return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), this->value_traits_ptr()); }
|
||||
{ return const_iterator (this->get_value_traits().to_node_ptr(const_cast<reference> (value)), this->value_traits_ptr()); }
|
||||
|
||||
static void init_node(reference value)
|
||||
{ node_algorithms::init(value_traits::to_node_ptr(value)); }
|
||||
|
@@ -1228,8 +1228,8 @@ class list_impl
|
||||
//! <b>Note</b>: Iterators and references are not invalidated.
|
||||
iterator iterator_to(reference value)
|
||||
{
|
||||
BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(value_traits::to_node_ptr(value)));
|
||||
return iterator(value_traits::to_node_ptr(value), value_traits_ptr());
|
||||
BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(this->priv_value_traits().to_node_ptr(value)));
|
||||
return iterator(this->priv_value_traits().to_node_ptr(value), value_traits_ptr());
|
||||
}
|
||||
|
||||
//! <b>Requires</b>: value must be a const reference to a value inserted in a list.
|
||||
@@ -1243,8 +1243,8 @@ class list_impl
|
||||
//! <b>Note</b>: Iterators and references are not invalidated.
|
||||
const_iterator iterator_to(const_reference value) const
|
||||
{
|
||||
BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(value_traits::to_node_ptr(const_cast<reference> (value))));
|
||||
return const_iterator(value_traits::to_node_ptr(const_cast<reference> (value)), value_traits_ptr());
|
||||
BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(this->priv_value_traits().to_node_ptr(const_cast<reference> (value))));
|
||||
return const_iterator(this->priv_value_traits().to_node_ptr(const_cast<reference> (value)), value_traits_ptr());
|
||||
}
|
||||
|
||||
/// @cond
|
||||
|
@@ -1669,7 +1669,6 @@ class slist_impl
|
||||
static iterator s_iterator_to(reference value)
|
||||
{
|
||||
BOOST_STATIC_ASSERT((!stateful_value_traits));
|
||||
//BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(value)));
|
||||
return iterator (value_traits::to_node_ptr(value), const_value_traits_ptr());
|
||||
}
|
||||
|
||||
@@ -1687,8 +1686,7 @@ class slist_impl
|
||||
static const_iterator s_iterator_to(const_reference value)
|
||||
{
|
||||
BOOST_STATIC_ASSERT((!stateful_value_traits));
|
||||
//BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(const_cast<reference> (value))));
|
||||
return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), const_value_traits_ptr());
|
||||
return const_iterator(value_traits::to_node_ptr(const_cast<reference> (value)), const_value_traits_ptr());
|
||||
}
|
||||
|
||||
//! <b>Requires</b>: value must be a reference to a value inserted in a list.
|
||||
@@ -1702,8 +1700,8 @@ class slist_impl
|
||||
//! <b>Note</b>: Iterators and references are not invalidated.
|
||||
iterator iterator_to(reference value)
|
||||
{
|
||||
//BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(value)));
|
||||
return iterator (value_traits::to_node_ptr(value), this->value_traits_ptr());
|
||||
BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(this->priv_value_traits().to_node_ptr(value)));
|
||||
return iterator (this->priv_value_traits().to_node_ptr(value), this->value_traits_ptr());
|
||||
}
|
||||
|
||||
//! <b>Requires</b>: value must be a const reference to a value inserted in a list.
|
||||
@@ -1717,8 +1715,8 @@ class slist_impl
|
||||
//! <b>Note</b>: Iterators and references are not invalidated.
|
||||
const_iterator iterator_to(const_reference value) const
|
||||
{
|
||||
//BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(const_cast<reference> (value))));
|
||||
return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), this->value_traits_ptr());
|
||||
BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(this->priv_value_traits().to_node_ptr(const_cast<reference> (value))));
|
||||
return const_iterator(this->priv_value_traits().to_node_ptr(const_cast<reference> (value)), this->value_traits_ptr());
|
||||
}
|
||||
|
||||
//! <b>Returns</b>: The iterator to the element before i in the list.
|
||||
|
@@ -172,6 +172,12 @@ void test_generic_set<ValueTraits, ContainerDefiner>::test_insert(std::vector<ty
|
||||
i = set_type::s_iterator_to(values[2]);
|
||||
BOOST_TEST (&*i == &values[2]);
|
||||
|
||||
typename set_type::const_iterator ic;
|
||||
ic = testset.iterator_to (const_cast<const value_type &>(values[2]));
|
||||
BOOST_TEST (&*ic == &values[2]);
|
||||
ic = set_type::s_iterator_to (const_cast<const value_type &>(values[2]));
|
||||
BOOST_TEST (&*ic == &values[2]);
|
||||
|
||||
testset.erase (i);
|
||||
{ int init_values [] = { 1, 3, 5 };
|
||||
TEST_INTRUSIVE_SEQUENCE( init_values, testset.begin() ); }
|
||||
|
@@ -234,6 +234,13 @@ void test_list<ValueTraits>
|
||||
i = list_type::s_iterator_to (values[4]);
|
||||
BOOST_TEST (&*i == &values[4]);
|
||||
|
||||
typename list_type::const_iterator ic;
|
||||
ic = testlist.iterator_to (const_cast<const value_type &>(values[4]));
|
||||
BOOST_TEST (&*ic == &values[4]);
|
||||
|
||||
ic = list_type::s_iterator_to (const_cast<const value_type &>(values[4]));
|
||||
BOOST_TEST (&*ic == &values[4]);
|
||||
|
||||
i = testlist.erase (i);
|
||||
BOOST_TEST (i == testlist.end());
|
||||
|
||||
|
@@ -275,6 +275,13 @@ void test_slist<ValueTraits, Linear, CacheLast>
|
||||
BOOST_TEST (&*i == &values[4]);
|
||||
i = list_type::s_iterator_to (values[4]);
|
||||
BOOST_TEST (&*i == &values[4]);
|
||||
|
||||
typename list_type::const_iterator ic;
|
||||
ic = testlist.iterator_to (const_cast<const value_type &>(values[4]));
|
||||
BOOST_TEST (&*ic == &values[4]);
|
||||
ic = list_type::s_iterator_to (const_cast<const value_type &>(values[4]));
|
||||
BOOST_TEST (&*ic == &values[4]);
|
||||
|
||||
i = testlist.previous (i);
|
||||
BOOST_TEST (&*i == &values[0]);
|
||||
|
||||
|
@@ -57,16 +57,16 @@ struct stateful_value_traits
|
||||
: values_(vals), node_array_(node_array)
|
||||
{}
|
||||
|
||||
node_ptr to_node_ptr (value_type &value)
|
||||
node_ptr to_node_ptr (value_type &value) const
|
||||
{ return node_array_ + (&value - values_); }
|
||||
|
||||
const_node_ptr to_node_ptr (const value_type &value) const
|
||||
{ return node_array_ + (&value - values_); }
|
||||
|
||||
pointer to_value_ptr(node_ptr n)
|
||||
pointer to_value_ptr(const node_ptr &n) const
|
||||
{ return values_ + (n - node_array_); }
|
||||
|
||||
const_pointer to_value_ptr(const_node_ptr n) const
|
||||
const_pointer to_value_ptr(const const_node_ptr &n) const
|
||||
{ return values_ + (n - node_array_); }
|
||||
|
||||
pointer values_;
|
||||
@@ -123,9 +123,18 @@ int main()
|
||||
; it != itend
|
||||
; ++it){
|
||||
my_list.push_front(*it);
|
||||
if(&*my_list.iterator_to(*it) != &my_list.front())
|
||||
return 1;
|
||||
my_slist.push_front(*it);
|
||||
my_set.insert(*it);
|
||||
if(&*my_slist.iterator_to(*it) != &my_slist.front())
|
||||
return 1;
|
||||
Set::iterator sit = my_set.insert(*it).first;
|
||||
if(&*my_set.iterator_to(*it) != &*sit)
|
||||
return 1;
|
||||
Uset::iterator uit = my_uset.insert(*it).first;
|
||||
my_uset.insert(*it);
|
||||
if(&*my_uset.iterator_to(*it) != &*uit)
|
||||
return 1;
|
||||
}
|
||||
|
||||
//Now test lists
|
||||
|
Reference in New Issue
Block a user