diff --git a/doc/intrusive.qbk b/doc/intrusive.qbk index 516b044..6f72da3 100644 --- a/doc/intrusive.qbk +++ b/doc/intrusive.qbk @@ -3035,8 +3035,7 @@ Let's explain each type and function: as `node_ptr`: If `node_ptr` is `node*`, `pointer` must be `value_type*`. If `node_ptr` is `smart_ptr`, `pointer` must be `smart_ptr`. This can be generically achieved using `boost::intrusive::pointer_traits` (portable implementation of C++11 - `std::pointer_traits`) or `boost::pointer_to_other` utility from [*Boost SmartPointers] - defined in ``. + `std::pointer_traits`). * [*['const_pointer]]: The type of a pointer to a `const value_type`. It must be the same pointer type as `node_ptr`: If `node_ptr` is `node*`, `const_pointer` must be `const value_type*`. If @@ -3101,14 +3100,7 @@ intrusive containers, so [*Boost.Intrusive] offers a templatized [classref boost::intrusive::trivial_value_traits trivial_value_traits] class that does exactly what we want: -[c++] - - #include - - //Now we can define legacy_value_traits just with a single line - using namespace boost::intrusive; - typedef trivial_value_traits legacy_value_traits; - +[doc_value_traits_trivial] Now we can just define the containers that will store the legacy abi objects and write a little test: @@ -3160,30 +3152,15 @@ The previous example can be further simplified using the class to define a value traits class with a value that stores the `simple_node` as a base class: -[c++] - - #include - - //value_1, value_2, simple_node and simple_node_traits are defined - //as in the previous example... - //... - - using namespace boost::intrusive; - - //Now define the needed value traits using - typedef derivation_value_traits ValueTraits1; - typedef derivation_value_traits ValueTraits2; - - //Now define the containers - typedef list > Value1List; - typedef list > Value2List; +[import ../example/doc_derivation_value_traits.cpp] +[doc_derivation_value_traits_value_traits] We can even choose to store `simple_node` as a member of `value_1` and `value_2` classes and use [classref boost::intrusive::member_value_traits member_value_traits] to define the needed value traits classes: -[import ../example/doc_advanced_value_traits2.cpp] -[doc_advanced_value_traits2_value_traits] +[import ../example/doc_member_value_traits.cpp] +[doc_member_value_traits_value_traits] [endsect] diff --git a/example/doc_derivation_value_traits.cpp b/example/doc_derivation_value_traits.cpp new file mode 100644 index 0000000..e900657 --- /dev/null +++ b/example/doc_derivation_value_traits.cpp @@ -0,0 +1,94 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2006-2014 +// +// 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) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// +#include +#include +#include +#include + +struct simple_node +{ + simple_node *prev_; + simple_node *next_; +}; + +//Define the node traits. A single node_traits will be enough. +struct simple_node_traits +{ + typedef simple_node node; + typedef node * node_ptr; + typedef const node * const_node_ptr; + static node *get_next(const node *n) { return n->next_; } + static void set_next(node *n, node *next) { n->next_ = next; } + static node *get_previous(const node *n) { return n->prev_; } + static void set_previous(node *n, node *prev) { n->prev_ = prev; } +}; + +//[doc_derivation_value_traits_value_traits +class base_1{}; +class base_2{}; + +struct value_1 : public base_1, public simple_node +{ + int id_; + simple_node node_; +}; + +struct value_2 : public base_1, public base_2, public simple_node +{ + simple_node node_; + float id_; +}; + +using namespace boost::intrusive; + +//Now define the needed value traits using derivation_value_traits +typedef derivation_value_traits ValueTraits1; +typedef derivation_value_traits ValueTraits2; + +//Now define two intrusive lists. Both lists will use the same algorithms: +// circular_list_algorithms +typedef list > Value1List; +typedef list > Value2List; +//] + +//[doc_derivation_value_traits_test +int main() +{ + typedef std::vector Vect1; + typedef std::vector Vect2; + + //Create values, with a different internal number + Vect1 values1; + Vect2 values2; + for(int i = 0; i < 100; ++i){ + value_1 v1; v1.id_ = i; values1.push_back(v1); + value_2 v2; v2.id_ = (float)i; values2.push_back(v2); + } + + //Create the lists with the objects + Value1List list1(values1.begin(), values1.end()); + Value2List list2(values2.begin(), values2.end()); + + //Now test both lists + Value1List::const_iterator bit1(list1.begin()), bitend1(list1.end()); + Value2List::const_iterator bit2(list2.begin()), bitend2(list2.end()); + + Vect1::const_iterator it1(values1.begin()), itend1(values1.end()); + Vect2::const_iterator it2(values2.begin()), itend2(values2.end()); + + //Test the objects inserted in our lists + for(; it1 != itend1; ++it1, ++bit1, ++it2, ++bit2){ + if(&*bit1 != &*it1 || &*bit2 != &*it2) return false; + } + return 0; +} +//] diff --git a/example/doc_how_to_use.cpp b/example/doc_how_to_use.cpp index dcd893e..05d9887 100644 --- a/example/doc_how_to_use.cpp +++ b/example/doc_how_to_use.cpp @@ -36,7 +36,6 @@ typedef list MemberList; int main() { typedef std::vector::iterator VectIt; - typedef std::vector::reverse_iterator VectRit; //Create several MyClass objects, each one with a different value std::vector values; diff --git a/example/doc_advanced_value_traits2.cpp b/example/doc_member_value_traits.cpp similarity index 96% rename from example/doc_advanced_value_traits2.cpp rename to example/doc_member_value_traits.cpp index 1104530..45d1f1d 100644 --- a/example/doc_advanced_value_traits2.cpp +++ b/example/doc_member_value_traits.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2006-2013 +// (C) Copyright Ion Gaztanaga 2006-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -32,7 +32,7 @@ struct simple_node_traits static void set_previous(node *n, node *prev) { n->prev_ = prev; } }; -//[doc_advanced_value_traits2_value_traits +//[doc_member_value_traits_value_traits class base_1{}; class base_2{}; @@ -61,7 +61,7 @@ typedef list > Value1List; typedef list > Value2List; //] -//[doc_advanced_value_traits2_test +//[doc_member_value_traits_test int main() { typedef std::vector Vect1; diff --git a/example/doc_value_traits.cpp b/example/doc_value_traits.cpp index e8209a2..52b9f81 100644 --- a/example/doc_value_traits.cpp +++ b/example/doc_value_traits.cpp @@ -13,6 +13,9 @@ #include #include #include +//<- +#include +//-> #include //This node is the legacy type we can't modify and we want to insert in @@ -66,11 +69,21 @@ struct legacy_value_traits //] +//[doc_value_traits_trivial + +typedef bi::trivial_value_traits trivial_legacy_value_traits; + +//] + //[doc_value_traits_test //Now define an intrusive list and slist that will store legacy_value objects -typedef bi::value_traits ValueTraitsOption; -typedef bi::list LegacyAbiList; -typedef bi::slist LegacyAbiSlist; +typedef bi::value_traits ValueTraitsOption; +typedef bi::value_traits TrivialValueTraitsOption; + +typedef bi::list LegacyAbiList; +typedef bi::slist LegacyAbiSlist; +typedef bi::list TrivialLegacyAbiList; +typedef bi::slist TrivialLegacyAbiSlist; template bool test_list() @@ -98,6 +111,8 @@ bool test_list() int main() { - return test_list() && test_list() ? 0 : 1; + return test_list() && test_list() && + test_list() && test_list() + ? 0 : 1; } //] diff --git a/include/boost/intrusive/derivation_value_traits.hpp b/include/boost/intrusive/derivation_value_traits.hpp index 5581ab6..b55c968 100644 --- a/include/boost/intrusive/derivation_value_traits.hpp +++ b/include/boost/intrusive/derivation_value_traits.hpp @@ -15,11 +15,8 @@ #include #include - #include -#include -#include -#include +#include namespace boost { namespace intrusive { @@ -41,8 +38,10 @@ struct derivation_value_traits typedef typename node_traits::node node; typedef typename node_traits::node_ptr node_ptr; typedef typename node_traits::const_node_ptr const_node_ptr; - typedef typename boost::pointer_to_other::type pointer; - typedef typename boost::pointer_to_other::type const_pointer; + typedef typename pointer_traits:: + template rebind_pointer::type pointer; + typedef typename pointer_traits:: + template rebind_pointer::type const_pointer; typedef typename boost::intrusive:: pointer_traits::reference reference; typedef typename boost::intrusive:: @@ -57,18 +56,12 @@ struct derivation_value_traits static pointer to_value_ptr(const node_ptr &n) { -// This still fails in gcc < 4.4 so forget about it -// using ::boost::static_pointer_cast; -// return static_pointer_cast(n)); - return pointer(&static_cast(*n)); + return pointer_traits::pointer_to(static_cast(*n)); } static const_pointer to_value_ptr(const const_node_ptr &n) { -// This still fails in gcc < 4.4 so forget about it -// using ::boost::static_pointer_cast; -// return static_pointer_cast(n)); - return const_pointer(&static_cast(*n)); + return pointer_traits::pointer_to(static_cast(*n)); } }; diff --git a/include/boost/intrusive/detail/any_node_and_algorithms.hpp b/include/boost/intrusive/detail/any_node_and_algorithms.hpp index 899023d..8b51099 100644 --- a/include/boost/intrusive/detail/any_node_and_algorithms.hpp +++ b/include/boost/intrusive/detail/any_node_and_algorithms.hpp @@ -19,7 +19,6 @@ #include #include #include -#include namespace boost { namespace intrusive { diff --git a/include/boost/intrusive/detail/hashtable_node.hpp b/include/boost/intrusive/detail/hashtable_node.hpp index 4702e98..3e06b47 100644 --- a/include/boost/intrusive/detail/hashtable_node.hpp +++ b/include/boost/intrusive/detail/hashtable_node.hpp @@ -20,13 +20,11 @@ #include #include #include -#include //remove-me -#include +#include //make_slist #include #include #include #include -#include #include diff --git a/include/boost/intrusive/hashtable.hpp b/include/boost/intrusive/hashtable.hpp index ac3c566..73de3e2 100644 --- a/include/boost/intrusive/hashtable.hpp +++ b/include/boost/intrusive/hashtable.hpp @@ -23,7 +23,6 @@ #include #include #include -#include //General intrusive utilities #include #include diff --git a/include/boost/intrusive/trivial_value_traits.hpp b/include/boost/intrusive/trivial_value_traits.hpp index 2505e08..7615f16 100644 --- a/include/boost/intrusive/trivial_value_traits.hpp +++ b/include/boost/intrusive/trivial_value_traits.hpp @@ -15,7 +15,6 @@ #include #include - #include #include diff --git a/include/boost/intrusive/unordered_set_hook.hpp b/include/boost/intrusive/unordered_set_hook.hpp index fb17a33..7de0526 100644 --- a/include/boost/intrusive/unordered_set_hook.hpp +++ b/include/boost/intrusive/unordered_set_hook.hpp @@ -16,12 +16,10 @@ #include #include -#include #include #include #include #include -#include #include namespace boost { diff --git a/test/smart_ptr.hpp b/test/smart_ptr.hpp index 8387d14..2800430 100644 --- a/test/smart_ptr.hpp +++ b/test/smart_ptr.hpp @@ -13,7 +13,6 @@ #include #include -#include #include #if (defined _MSC_VER)