diff --git a/include/boost/intrusive/circular_slist_algorithms.hpp b/include/boost/intrusive/circular_slist_algorithms.hpp index fb5f75a..d41dac4 100644 --- a/include/boost/intrusive/circular_slist_algorithms.hpp +++ b/include/boost/intrusive/circular_slist_algorithms.hpp @@ -250,33 +250,21 @@ class circular_slist_algorithms { if (other_node == this_node) return; - bool this_inited = base_t::inited(this_node); - bool other_inited = base_t::inited(other_node); - if(this_inited){ - base_t::init_header(this_node); - } - if(other_inited){ - base_t::init_header(other_node); - } + const node_ptr this_next = NodeTraits::get_next(this_node); + const node_ptr other_next = NodeTraits::get_next(other_node); + const bool this_null = !this_next; + const bool other_null = !other_next; + const bool this_empty = this_next == this_node; + const bool other_empty = other_next == other_node; - bool empty1 = base_t::unique(this_node); - bool empty2 = base_t::unique(other_node); - node_ptr prev_this (get_previous_node(this_node)); - node_ptr prev_other(get_previous_node(other_node)); - - node_ptr this_next (NodeTraits::get_next(this_node)); - node_ptr other_next(NodeTraits::get_next(other_node)); - NodeTraits::set_next(this_node, other_next); - NodeTraits::set_next(other_node, this_next); - NodeTraits::set_next(empty1 ? other_node : prev_this, other_node); - NodeTraits::set_next(empty2 ? this_node : prev_other, this_node); - - if(this_inited){ - base_t::init(other_node); + if(!(other_null || other_empty)){ + NodeTraits::set_next(this_next == other_node ? other_node : get_previous_node(other_node), this_node ); } - if(other_inited){ - base_t::init(this_node); + if(!(this_null | this_empty)){ + NodeTraits::set_next(other_next == this_node ? this_node : get_previous_node(this_node), other_node ); } + NodeTraits::set_next(this_node, other_empty ? this_node : (other_next == this_node ? other_node : other_next) ); + NodeTraits::set_next(other_node, this_empty ? other_node : (this_next == other_node ? this_node : this_next ) ); } //! Effects: Reverses the order of elements in the list. diff --git a/include/boost/intrusive/detail/common_slist_algorithms.hpp b/include/boost/intrusive/detail/common_slist_algorithms.hpp index a5433bb..0adbd50 100644 --- a/include/boost/intrusive/detail/common_slist_algorithms.hpp +++ b/include/boost/intrusive/detail/common_slist_algorithms.hpp @@ -43,9 +43,6 @@ class common_slist_algorithms return p; } - static void init_header(const node_ptr & this_node) - { NodeTraits::set_next(this_node, this_node); } - static void init(const node_ptr & this_node) { NodeTraits::set_next(this_node, node_ptr()); } diff --git a/include/boost/intrusive/hashtable.hpp b/include/boost/intrusive/hashtable.hpp index c046095..607e80d 100644 --- a/include/boost/intrusive/hashtable.hpp +++ b/include/boost/intrusive/hashtable.hpp @@ -2711,15 +2711,16 @@ class hashtable_impl static std::size_t priv_stored_hash(slist_node_ptr n, detail::false_ false_value) { return bucket_plus_vtraits::priv_stored_hash(n, false_value); } - void priv_clear_buckets(bucket_ptr buckets_ptr, size_type bucket_cnt) + void priv_clear_buckets(const bucket_ptr buckets_ptr, const size_type bucket_cnt) { - for(; bucket_cnt--; ++buckets_ptr){ + bucket_ptr buckets_it = buckets_ptr; + for(size_type bucket_i = 0; bucket_i != bucket_cnt; ++buckets_it, ++bucket_i){ if(safemode_or_autounlink){ - bucket_plus_vtraits_t::priv_clear_group_nodes(*buckets_ptr, optimize_multikey_t()); - buckets_ptr->clear_and_dispose(detail::init_disposer()); + bucket_plus_vtraits_t::priv_clear_group_nodes(*buckets_it, optimize_multikey_t()); + buckets_it->clear_and_dispose(detail::init_disposer()); } else{ - buckets_ptr->clear(); + buckets_it->clear(); } } this->priv_initialize_cache(); diff --git a/include/boost/intrusive/pointer_traits.hpp b/include/boost/intrusive/pointer_traits.hpp index 660420d..839c47e 100644 --- a/include/boost/intrusive/pointer_traits.hpp +++ b/include/boost/intrusive/pointer_traits.hpp @@ -159,10 +159,10 @@ struct pointer_traits //priv_pointer_to static pointer priv_pointer_to(boost::true_type, typename boost::intrusive::detail::unvoid::type& r) - { return Ptr::pointer_to(r); } + { return Ptr::pointer_to(r); } static pointer priv_pointer_to(boost::false_type, typename boost::intrusive::detail::unvoid::type& r) - { return pointer(boost::intrusive::detail::addressof(r)); } + { return pointer(boost::intrusive::detail::addressof(r)); } //priv_static_cast_from template @@ -189,7 +189,15 @@ struct pointer_traits template static pointer priv_dynamic_cast_from(boost::false_type, const UPtr &uptr) - { return pointer_to(*dynamic_cast(&*uptr)); } + { + element_type *p = dynamic_cast(&*uptr); + if(!p){ + return pointer(); + } + else{ + return pointer_to(*p); + } + } ///@endcond }; diff --git a/test/itestvalue.hpp b/test/itestvalue.hpp index 37059ac..d13a2c0 100644 --- a/test/itestvalue.hpp +++ b/test/itestvalue.hpp @@ -52,8 +52,8 @@ struct testvalue // have to be handled appropriately when copied: testvalue & operator= (const testvalue& src) { - Hooks::base_hook_type::operator=(src); - Hooks::auto_base_hook_type::operator=(src); + Hooks::base_hook_type::operator=(static_cast(src)); + Hooks::auto_base_hook_type::operator=(static_cast(src)); this->node_ = src.node_; this->auto_node_ = src.auto_node_; value_ = src.value_; @@ -62,8 +62,8 @@ struct testvalue void swap_nodes(testvalue &other) { - Hooks::base_hook_type::swap_nodes(other); - Hooks::auto_base_hook_type::swap_nodes(other); + Hooks::base_hook_type::swap_nodes(static_cast(other)); + Hooks::auto_base_hook_type::swap_nodes(static_cast(other)); node_.swap_nodes(other.node_); auto_node_.swap_nodes(other.auto_node_); } diff --git a/test/slist_test.cpp b/test/slist_test.cpp index de04865..ac9a635 100644 --- a/test/slist_test.cpp +++ b/test/slist_test.cpp @@ -456,23 +456,32 @@ void test_slist } if(!list_type::linear) { - list_type testlist1 (&values[0], &values[1]); - + list_type testlist1 (&values[0], &values[0]+1); + if(testlist1.size() != 1){ + abort(); + } { int init_values [] = { 1 }; TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } values[1].swap_nodes(values[2]); + BOOST_TEST(testlist1.size() == 1); + BOOST_TEST(!values[1].is_linked()); + BOOST_TEST(!values[2].is_linked()); { int init_values [] = { 1 }; TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } values[0].swap_nodes(values[2]); - + BOOST_TEST(testlist1.size() == 1); + BOOST_TEST(values[2].is_linked()); + BOOST_TEST(!values[0].is_linked()); { int init_values [] = { 3 }; TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } values[0].swap_nodes(values[2]); - + BOOST_TEST(testlist1.size() == 1); + BOOST_TEST(!values[2].is_linked()); + BOOST_TEST(values[0].is_linked()); { int init_values [] = { 1 }; TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } } @@ -730,207 +739,3 @@ int main(int, char* []) return boost::report_errors(); } #include - -/* -#include -#include -#include -#include -#include - -namespace intrusive = boost::intrusive; - -class object : public boost::noncopyable -{ -public: - int o; - object() - { - } - virtual ~object() - { - } -}; - - -class signal : virtual public object -{ -public: - signal() - { - } - virtual ~signal() - { - } -}; - - -class set_item : public signal -{ -public: - set_item() - { - } - virtual ~set_item() - { - } - -public: - virtual const std::string& get_buffer() const - { - return m_buffer; - } - - typedef intrusive::set_member_hook< - intrusive::link_mode - > hook; - hook m_hook; - - std::string m_buffer; -}; - - -template -struct member_comparator -{ - bool operator()(const T& t1, const T& t2) const - { - return (t1.*V) < (t2.*V); - } - bool operator()(const M& m, const T& t) const - { - return m < (t.*V); - } - bool operator()(const T& t, const M& m) const - { - return (t.*V) < m; - } -}; - -class kk{ int a; float f; }; - -class list_item : public kk, virtual public object -{ -public: - list_item() - { - } - virtual ~list_item() - { - } - - virtual void f() - { - } - - typedef intrusive::list_member_hook< - intrusive::link_mode - > hook; - hook m_hook; -}; - -set_item srec; -list_item lrec; - -const set_item::hook set_item::* sptr_to_member = &set_item::m_hook; -const list_item::hook list_item::* lptr_to_member = &list_item::m_hook; - -int main(int argc, char** argv) -{ - int a = sizeof(sptr_to_member); - int b = sizeof(lptr_to_member); - const std::type_info &ta = typeid(set_item); - const std::type_info &tb = typeid(list_item); - - const set_item::hook &sh = srec.*sptr_to_member; - const list_item::hook &l2 = lrec.*lptr_to_member; - - { - typedef member_comparator< - set_item, - std::string, - &set_item::m_buffer - > set_item_comparator; - - typedef intrusive::set< - set_item, - intrusive::compare, - intrusive::member_hook< - set_item, - set_item::hook, - &set_item::m_hook - >, - intrusive::constant_time_size - > set_items - ; - - union - { - int as_int[2]; - const set_item::hook set_item::* ptr_to_member; - } - sss; - sss.ptr_to_member = &set_item::m_hook; - - std::cout << "set offsets: " << sss.as_int[0] << ":" << sss.as_int[1] << " and " << offsetof(set_item,m_hook) << std::endl; - - set_items rr; - - std::string key = "123"; - set_items::insert_commit_data icd; - std::pair ir = rr.insert_check( - key, - set_item_comparator(), - icd - ); - - if ( !ir.second ) - { - throw std::exception(); - } - - set_item rec; - rec.m_buffer = key; - set_items::iterator i = rr.insert_commit( rec, icd ); - - set_item* rrr = &(*i); - - std::cout << "set pointers: " << ((void*)rrr) << " and " << ((void*)&rec) << std::endl; - } - - { - typedef intrusive::list< - list_item, - intrusive::member_hook< - list_item, - list_item::hook, - &list_item::m_hook - >, - intrusive::constant_time_size - > list_items - ; - - union - { - int as_int[2]; - const list_item::hook list_item::* ptr_to_member; - } - sss; - sss.ptr_to_member = &list_item::m_hook; - - std::cout << "list offsets: " << sss.as_int[0] << ":" << sss.as_int[1] << " and " << offsetof(list_item,m_hook) << std::endl; - - list_items rr; - - list_item rec; - const list_item::hook &h = rec.*sss.ptr_to_member; - rr.push_back( rec ); - - list_item* rrr = &rr.front(); - - std::cout << "list pointers: " << ((void*)rrr) << " and " << ((void*)&rec) << std::endl; - } - - return 0; -} -*/ \ No newline at end of file diff --git a/test/smart_ptr.hpp b/test/smart_ptr.hpp index c226b5b..8387d14 100644 --- a/test/smart_ptr.hpp +++ b/test/smart_ptr.hpp @@ -261,38 +261,6 @@ inline void swap (smart_ptr &pt, pt2 = ptr; } -//!Simulation of static_cast between pointers. Never throws. -template -inline smart_ptr - static_pointer_cast(const smart_ptr & r) -{ - return smart_ptr(r, detail::static_cast_tag()); -} - -//!Simulation of const_cast between pointers. Never throws. -template -inline smart_ptrconst_pointer_cast(smart_ptr const & r) -{ - return smart_ptr(r, detail::const_cast_tag()); -} - -//!Simulation of dynamic_cast between pointers. Never throws. -template -inline smart_ptr - dynamic_pointer_cast(smart_ptr const & r) -{ - return smart_ptr - (r, detail::dynamic_cast_tag()); -} - -//!Simulation of reinterpret_cast between pointers. Never throws. -template -inline smart_ptr - reinterpret_pointer_cast(smart_ptr const & r) -{ - return smart_ptr(r, detail::reinterpret_cast_tag()); -} - } //namespace intrusive { } //namespace boost { diff --git a/test/test_macros.hpp b/test/test_macros.hpp index 09aae3e..9abf12a 100644 --- a/test/test_macros.hpp +++ b/test/test_macros.hpp @@ -13,14 +13,33 @@ #ifndef BOOST_INTRUSIVE_TEST_TEST_MACROS_HPP #define BOOST_INTRUSIVE_TEST_TEST_MACROS_HPP +namespace boost{ +namespace intrusive{ + +template +bool test_equal(It1 f1, It1 l1, It2 f2) +{ + while(f1 != l1){ + if(*f1 != *f2){ + return false; + } + ++f1; + ++f2; + } + return true; +} + #define TEST_INTRUSIVE_SEQUENCE( INTVALUES, ITERATOR )\ { \ - BOOST_TEST (std::equal(&INTVALUES[0], &INTVALUES[0] + sizeof(INTVALUES)/sizeof(INTVALUES[0]), ITERATOR) ); \ + BOOST_TEST (boost::intrusive::test_equal(&INTVALUES[0], &INTVALUES[0] + sizeof(INTVALUES)/sizeof(INTVALUES[0]), ITERATOR) ); \ } #define TEST_INTRUSIVE_SEQUENCE_EXPECTED( EXPECTEDVECTOR, ITERATOR )\ { \ - BOOST_TEST (std::equal(EXPECTEDVECTOR.begin(), EXPECTEDVECTOR.end(), ITERATOR) ); \ + BOOST_TEST (boost::intrusive::test_equal(EXPECTEDVECTOR.begin(), EXPECTEDVECTOR.end(), ITERATOR) ); \ } +} //namespace boost{ +} //namespace intrusive{ + #endif