diff --git a/include/boost/intrusive/bstree.hpp b/include/boost/intrusive/bstree.hpp index 4335d76..f2cdb42 100644 --- a/include/boost/intrusive/bstree.hpp +++ b/include/boost/intrusive/bstree.hpp @@ -838,6 +838,27 @@ class bstree_impl //! Throws: Nothing. const_reverse_iterator crend() const; + //! Effects: Returns a iterator pointing to the root node of the container or end() if not present. + //! + //! Complexity: Constant. + //! + //! Throws: Nothing. + iterator root(); + + //! Effects: Returns a const_iterator pointing to the root node of the container or cend() if not present. + //! + //! Complexity: Constant. + //! + //! Throws: Nothing. + const_iterator root() const; + + //! Effects: Returns a const_iterator pointing to the root node of the container or cend() if not present. + //! + //! Complexity: Constant. + //! + //! Throws: Nothing. + const_iterator croot() const; + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED //! Precondition: end_iterator must be a valid end iterator diff --git a/test/generic_assoc_test.hpp b/test/generic_assoc_test.hpp index 5c64b4f..c3d81b6 100644 --- a/test/generic_assoc_test.hpp +++ b/test/generic_assoc_test.hpp @@ -38,6 +38,7 @@ struct test_generic_assoc typedef typename ContainerDefiner::value_cont_type value_cont_type; static void test_all(value_cont_type&); + static void test_root(value_cont_type&); static void test_clone(value_cont_type&); static void test_insert_erase_burst(); static void test_container_from_end(value_cont_type&, detail::true_type); @@ -135,6 +136,7 @@ void test_generic_assoc::test_all(value_cont_type& values) { typedef typename ContainerDefiner::template container <>::type assoc_type; + test_root(values); test_clone(values); test_container_from_end(values, detail::bool_< assoc_type::has_container_from_iterator >()); test_splay_up(values, detail::bool_< has_splay< assoc_type >::value >()); @@ -146,8 +148,37 @@ void test_generic_assoc::test_all(value_cont_type& values) } template -void test_generic_assoc - ::test_clone(value_cont_type& values) +void test_generic_assoc::test_root(value_cont_type& values) +{ + typedef typename ContainerDefiner::template container<>::type assoc_type; + typedef typename assoc_type::iterator iterator; + typedef typename assoc_type::const_iterator const_iterator; + + assoc_type testset1; + const assoc_type &ctestset1 = testset1;; + + BOOST_TEST( testset1.root() == testset1.end()); + BOOST_TEST(ctestset1.root() == ctestset1.cend()); + BOOST_TEST( testset1.croot() == ctestset1.cend()); + + + testset1.insert(values.begin(), values.begin() + values.size()); + + iterator i = testset1.root(); + iterator i2(i); + BOOST_TEST( i.go_parent().go_parent() == i2); + + const_iterator ci = ctestset1.root(); + const_iterator ci2(ci); + BOOST_TEST( ci.go_parent().go_parent() == ci2); + + ci = testset1.croot(); + ci2 = ci; + BOOST_TEST( ci.go_parent().go_parent() == ci2); +} + +template +void test_generic_assoc::test_clone(value_cont_type& values) { { typedef typename ContainerDefiner::template container