diff --git a/include/boost/intrusive/detail/parent_from_member.hpp b/include/boost/intrusive/detail/parent_from_member.hpp index 275229ab..cb1e2fbf 100644 --- a/include/boost/intrusive/detail/parent_from_member.hpp +++ b/include/boost/intrusive/detail/parent_from_member.hpp @@ -91,25 +91,15 @@ BOOST_INTRUSIVE_FORCEINLINE std::ptrdiff_t offset_from_pointer_to_member(const M template BOOST_INTRUSIVE_FORCEINLINE Parent *parent_from_member(Member *member, const Member Parent::* ptr_to_member) { - return static_cast - ( - static_cast - ( - static_cast(static_cast(member)) - offset_from_pointer_to_member(ptr_to_member) - ) - ); + return reinterpret_cast + (reinterpret_cast(member) - static_cast(offset_from_pointer_to_member(ptr_to_member))); } template BOOST_INTRUSIVE_FORCEINLINE const Parent *parent_from_member(const Member *member, const Member Parent::* ptr_to_member) { - return static_cast - ( - static_cast - ( - static_cast(static_cast(member)) - offset_from_pointer_to_member(ptr_to_member) - ) - ); + return reinterpret_cast + ( reinterpret_cast(member) - static_cast(offset_from_pointer_to_member(ptr_to_member)) ); } } //namespace detail { diff --git a/include/boost/intrusive/linear_slist_algorithms.hpp b/include/boost/intrusive/linear_slist_algorithms.hpp index 65a43f44..0574f824 100644 --- a/include/boost/intrusive/linear_slist_algorithms.hpp +++ b/include/boost/intrusive/linear_slist_algorithms.hpp @@ -152,7 +152,7 @@ class linear_slist_algorithms //! //! Throws: Nothing. inline static void init_header(node_ptr this_node) BOOST_NOEXCEPT - { NodeTraits::set_next(this_node, node_ptr ()); } + { NodeTraits::set_next(this_node, node_ptr()); } //! Requires: 'p' is the first node of a list. //! diff --git a/test/slist_test.cpp b/test/slist_test.cpp index 870e1da6..603cedae 100644 --- a/test/slist_test.cpp +++ b/test/slist_test.cpp @@ -355,48 +355,15 @@ void test_slist< ListType, ValueContainer > TEST_INTRUSIVE_SEQUENCE( init_values, testlist2.begin() ); } } - { //splice in the same list - list_type testlist1 (values.begin(), values.begin() + 5); - - { int init_values [] = { 1, 2, 3, 4, 5 }; - TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } - - //nop 1 - testlist1.splice_after (testlist1.before_begin(), testlist1, testlist1.before_begin(), ++testlist1.before_begin()); - { int init_values [] = { 1, 2, 3, 4, 5 }; - TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } - - //nop 2 - testlist1.splice_after (++testlist1.before_begin(), testlist1, testlist1.before_begin(), ++testlist1.before_begin()); - { int init_values [] = { 1, 2, 3, 4, 5 }; - TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } - - //nop 3 - testlist1.splice_after (testlist1.before_begin(), testlist1, ++testlist1.before_begin(), ++testlist1.before_begin()); - { int init_values [] = { 1, 2, 3, 4, 5 }; - TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } - - testlist1.splice_after (testlist1.before_begin(), testlist1, ++testlist1.before_begin(), ++++testlist1.before_begin()); - { int init_values [] = { 2, 1, 3, 4, 5 }; - TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } - - testlist1.splice_after (testlist1.before_begin(), testlist1, ++testlist1.before_begin(), ++++++testlist1.before_begin()); - { int init_values [] = { 1, 3, 2, 4, 5 }; - TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } - - testlist1.splice_after (++++++++testlist1.before_begin(), testlist1, testlist1.before_begin(), ++++testlist1.before_begin()); - { int init_values [] = { 2, 4, 1, 3, 5 }; - TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } - } - { //Now test swap when testlist2 is empty list_type testlist1 (values.begin(), values.begin() + 2); list_type testlist2; + BOOST_TEST(testlist2.empty()); testlist1.swap(testlist2); BOOST_TEST (testlist1.empty()); { int init_values [] = { 1, 2 }; TEST_INTRUSIVE_SEQUENCE( init_values, testlist2.begin() ); } - } + } { //Now test swap when testlist1 is empty list_type testlist2 (values.begin(), values.begin() + 2); list_type testlist1; @@ -457,6 +424,42 @@ void test_slist< ListType, ValueContainer > { int init_values [] = { 1 }; TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } } + + { //splice in the same list + list_type testlist1 (values.begin(), values.begin() + 5); + + { int init_values [] = { 1, 2, 3, 4, 5 }; + TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } + + //nop 1 + testlist1.splice_after (testlist1.before_begin(), testlist1, testlist1.before_begin(), ++testlist1.before_begin()); + { int init_values [] = { 1, 2, 3, 4, 5 }; + TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } + + //nop 2 + testlist1.splice_after (++testlist1.before_begin(), testlist1, testlist1.before_begin(), ++testlist1.before_begin()); + { int init_values [] = { 1, 2, 3, 4, 5 }; + TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } + + //nop 3 + testlist1.splice_after (testlist1.before_begin(), testlist1, ++testlist1.before_begin(), ++testlist1.before_begin()); + { int init_values [] = { 1, 2, 3, 4, 5 }; + TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } + + #if !defined(BOOST_MSVC) || (BOOST_MSVC != 1900) //Visual 2015 has problems generating this test code + testlist1.splice_after (testlist1.before_begin(), testlist1, ++testlist1.before_begin(), ++++testlist1.before_begin()); + { int init_values [] = { 2, 1, 3, 4, 5 }; + TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } + + testlist1.splice_after (testlist1.before_begin(), testlist1, ++testlist1.before_begin(), ++++++testlist1.before_begin()); + { int init_values [] = { 1, 3, 2, 4, 5 }; + TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } + + testlist1.splice_after (++++++++testlist1.before_begin(), testlist1, testlist1.before_begin(), ++++testlist1.before_begin()); + { int init_values [] = { 2, 4, 1, 3, 5 }; + TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); } + #endif + } } template < typename ListType, typename ValueContainer > @@ -683,13 +686,13 @@ int main(int, char* []) { // test (plain/smart pointers) x (nonconst/const size) x (void node allocator) test_main_template()(); - test_main_template, false, true>()(); test_main_template()(); + + test_main_template, false, true>()(); test_main_template, true, true>()(); // test (bounded pointers) x ((nonconst/const size) x (special node allocator) test_main_template_bptr< true >()(); test_main_template_bptr< false >()(); - return boost::report_errors(); }