diff --git a/doc/intrusive.qbk b/doc/intrusive.qbk index 4c14d1c..f459c5f 100644 --- a/doc/intrusive.qbk +++ b/doc/intrusive.qbk @@ -1,5 +1,5 @@ [/ - / Copyright (c) 2007-2009 Ion Gaztanaga + / Copyright (c) 2007-2010 Ion Gaztanaga / / 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) @@ -8,7 +8,7 @@ [library Boost.Intrusive [quickbook 1.4] [authors [Krzikalla, Olaf], [Gaztanaga, Ion]] - [copyright 2005 Olaf Krzikalla, 2006-2009 Ion Gaztanaga] + [copyright 2005 Olaf Krzikalla, 2006-2010 Ion Gaztanaga] [id intrusive] [dirname intrusive] [purpose Intrusive containers] @@ -198,7 +198,7 @@ Intrusive containers have also downsides: swapping can be used to implement move capabilities. To ease the implementation of copy constructors and assignment operators of classes storing [*Boost.Intrusive] containers, [*Boost.Intrusive] offers special cloning functions. See - [link intrusive.clone_from Cloning [*Boost.Intrusive] containers] section for more information. + [link intrusive.clone_from Cloning Boost.Intrusive containers] section for more information. * Analyzing the thread safety of a program that uses containers is harder with intrusive containers, because the container might be modified indirectly without an explicit call to a container member. @@ -246,7 +246,10 @@ just include: Every class to be inserted in an intrusive container, needs to contain a hook that will offer the necessary data and resources to be insertable in the container. With [*Boost.Intrusive] you just choose the hook to be a public base class or -a public member of the class to be inserted. +a public member of the class to be inserted. [*Boost.Intrusive] also offers +more flexible hooks for advanced users, as explained in the chapter +[link intrusive.function_hooks Using function hooks], but usually base or member +hooks are good enough for most users. [section:usage_base_hook Using base hooks] @@ -451,6 +454,7 @@ stored object is not bound to or managed by the container: [endsect] + [endsect] [section:usage_when When to use?] @@ -2147,7 +2151,7 @@ that erase an element from the container. [endsect] -[section:clone_from Cloning [*Boost.Intrusive] containers] +[section:clone_from Cloning Boost.Intrusive containers] As previously mentioned, [*Boost.Intrusive] containers are [*non-copyable and non-assignable], because intrusive containers don't allocate memory at all. To implement a copy-constructor or assignment operator, @@ -2190,6 +2194,105 @@ Here is an example of `clone_from`: [endsect] +[section:function_hooks Using function hooks] + +A programmer might find that base or member hooks are not flexible enough in some situations. +In some applications it would be optimal to put a hook deep inside a member of a class or just outside the class. +[*Boost.Intrusive] has an easy option to allow such cases: [classref boost::intrusive::function_hook function_hook]. + +This option is similar to [classref boost::intrusive::member_hook member_hook] or +[classref boost::intrusive::base_hook base_hook], but the programmer can specify a function +object that tells the container how to obtain a hook from a value and vice versa. +The programmer just needs to define the following function object: + +[c++] + + //This functor converts between value_type and a hook_type + struct Functor + { + //Required types + typedef /*impl-defined*/ hook_type; + typedef /*impl-defined*/ hook_ptr; + typedef /*impl-defined*/ const_hook_ptr; + typedef /*impl-defined*/ value_type; + typedef /*impl-defined*/ pointer; + typedef /*impl-defined*/ const_pointer; + //Required static functions + static hook_ptr to_hook_ptr (value_type &value); + static const_hook_ptr to_hook_ptr(const value_type &value); + static pointer to_value_ptr(hook_ptr n); + static const_pointer to_value_ptr(const_hook_ptr n); + }; + +Converting from values to hooks is generally easy, since most hooks are +in practice members or base classes of class data members. The inverse operation +is a bit more complicated, but [*Boost.Intrusive] offers a bit of help with the function +[funcref boost::intrusive::get_parent_from_member get_parent_from_member], +which allows easy conversions from the address of a data member to the address of +the parent holding that member. Let's see a little example of +[classref boost::intrusive::function_hook function_hook]: + +[import ../example/doc_function_hooks.cpp] +[doc_function_hooks] + +[endsect] + + +[section:recursive Recursive Boost.Intrusive containers] + +[*Boost.Intrusive] containers can be used to define recursive structures very easily, +allowing complex data structures with very low overhead. Let's see an example: + +[import ../example/doc_recursive.cpp] +[doc_recursive] + +Recursive data structures using [*Boost.Intrusive] containers must avoid using hook deduction to avoid early type +instantiation: + +[c++] + + //This leads to compilation error (Recursive is instantiated by + //'list' to deduce hook properties (pointer type, tag, safe-mode...) + class Recursive + { //... + + list< Recursive > l; + //... + }; + + //Ok, programmer must specify the hook type to avoid early Recursive instantiation + class Recursive + { //... + list< Recursive, base_hook > l; + //... + }; + + +Member hooks are not suitable for recursive structures: + +[c++] + + class Recursive + { + private: + Recursive(const Recursive&); + Recursive & operator=(const Recursive&); + + public: + list_member_hook<> memhook; + list< Recursive, member_hook, &Recursive::memhook> > children; + }; + +Specifying `&Recursive::memhook` (that is, the offset between memhook and Recursive) provokes an early +instantiation of `Recursive`. To define recursive structures using member hooks, a programmer should use +[classref ::boost::interprocess::function_hook function_hook]: + +[import ../example/doc_recursive_member.cpp] +[doc_recursive_member] + +[endsect] + + [section:using_smart_pointers Using smart pointers with Boost.Intrusive containers] [*Boost.Intrusive] hooks can be configured to use other pointers than raw pointers. @@ -3313,7 +3416,7 @@ If you are concerned with file sizes and compilation times, this option is your When designing [*Boost.Intrusive] the following guidelines have been taken into account: -[section: Boost.Intrusive in performance sensitive environments] +[section:performance_sensitive Boost.Intrusive in performance sensitive environments] [*Boost.Intrusive] should be a valuable tool in performance sensitive environments, and following this guideline, [*Boost.Intrusive] has been designed to offer well @@ -3327,7 +3430,7 @@ constructions. [endsect] -[section: Boost.Intrusive in space constrained environments] +[section:space_constrained Boost.Intrusive in space constrained environments] [*Boost.Intrusive] should be useful in space constrained environments, and following this guideline [*Boost.Intrusive] separates node algorithms @@ -3344,7 +3447,7 @@ when the container is empty or contains few values. [endsect] -[section: Boost.Intrusive as a basic building block] +[section:basic_building_block Boost.Intrusive as a basic building block] [*Boost.Intrusive] can be a basic building block to build more complex containers and this potential has motivated many design decisions. For example, the ability @@ -3358,7 +3461,7 @@ functions come in handy when implementing non-intrusive containers [endsect] -[section: Extending Boost.Intrusive] +[section:extending_intrusive Extending Boost.Intrusive] [*Boost.Intrusive] offers a wide range of containers but also allows the construction of custom containers reusing [*Boost.Intrusive] elements. @@ -3728,6 +3831,28 @@ all the objects to be inserted in intrusive containers in containers like `std:: [section:release_notes Release Notes] +[section:release_notes_boost_1_45_00 Boost 1.45 Release] + +* Added `function_hook` option. +* Fixed bugs + [@https://svn.boost.org/trac/boost/ticket/3668 #3668], + [@https://svn.boost.org/trac/boost/ticket/3339 #3688], + [@https://svn.boost.org/trac/boost/ticket/3698 #3698], + [@https://svn.boost.org/trac/boost/ticket/3706 #3706], + [@https://svn.boost.org/trac/boost/ticket/3721 #3721]. + [@https://svn.boost.org/trac/boost/ticket/3729 #3729], + [@https://svn.boost.org/trac/boost/ticket/3746 #3746], + [@https://svn.boost.org/trac/boost/ticket/3781 #3781], + [@https://svn.boost.org/trac/boost/ticket/3829 #3829], + [@https://svn.boost.org/trac/boost/ticket/3840 #3840], + [@https://svn.boost.org/trac/boost/ticket/3339 #3339], + [@https://svn.boost.org/trac/boost/ticket/3419 #3419], + [@https://svn.boost.org/trac/boost/ticket/3431 #3431], + [@https://svn.boost.org/trac/boost/ticket/4021 #4021], + +[endsect] + + [section:release_notes_boost_1_40_00 Boost 1.40 Release] * Code cleanup in tree_algorithms.hpp and avl_tree_algorithms.hpp @@ -3849,29 +3974,4 @@ helpful discussions. [endsect] -[xinclude autodoc.xml] - -[section:license_notices License notices] - -Most of the internal implementation of red-black trees is based on that of SGI STL stl_tree.h file: - -['Copyright (c) 1996,1997 Silicon Graphics Computer Systems, Inc. -Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. Silicon Graphics makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.] - -['Copyright (c) 1994 Hewlett-Packard Company -Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. Hewlett-Packard Company makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.] - -The tree destruction algorithm is based on Julienne Walker and The EC Team code: - -['This code is in the public domain. Anyone may -use it or change it in any way that they see -fit. The author assumes no responsibility for -damages incurred through use of the original -code or any variations thereof.] - -['It is requested, but not required, that due -credit is given to the original author and -anyone who has modified the code through -a header comment, such as this one.] - -[endsect] +[xinclude autodoc.xml] \ No newline at end of file diff --git a/example/doc_function_hooks.cpp b/example/doc_function_hooks.cpp new file mode 100644 index 0000000..f7b6a87 --- /dev/null +++ b/example/doc_function_hooks.cpp @@ -0,0 +1,76 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2010-2010 +// +// 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 +//[doc_function_hooks +#include +#include + +using namespace boost::intrusive; + +struct MyClass +{ + int dummy; + //This internal type has a member hook + struct InnerNode + { + int dummy; + list_member_hook<> hook; + } inner; +}; + +//This functor converts between MyClass and InnerNode's member hook +struct Functor +{ + //Required types + typedef list_member_hook<> hook_type; + typedef hook_type* hook_ptr; + typedef const hook_type* const_hook_ptr; + typedef MyClass value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + + //Required static functions + static hook_ptr to_hook_ptr (value_type &value) + { return &value.inner.hook; } + static const_hook_ptr to_hook_ptr(const value_type &value) + { return &value.inner.hook; } + static pointer to_value_ptr(hook_ptr n) + { + return get_parent_from_member + (get_parent_from_member(n, &MyClass::InnerNode::hook) + ,&MyClass::inner + ); + } + static const_pointer to_value_ptr(const_hook_ptr n) + { + return get_parent_from_member + (get_parent_from_member(n, &MyClass::InnerNode::hook) + ,&MyClass::inner + ); + } +}; + +//Define a list that will use the hook accessed through the function object +typedef list< MyClass, function_hook< Functor> > List; + +int main() +{ + MyClass n; + List l; + //Insert the node in both lists + l.insert(l.begin(), n); + assert(l.size() == 1); + return 0; +} +//] + +#include diff --git a/example/doc_recursive.cpp b/example/doc_recursive.cpp new file mode 100644 index 0000000..c161e14 --- /dev/null +++ b/example/doc_recursive.cpp @@ -0,0 +1,53 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2006-2009 +// +// 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. +// +///////////////////////////////////////////////////////////////////////////// +//[doc_recursive +#include +#include + +using namespace boost::intrusive; + +typedef list_base_hook<> BaseHook; + +//A recursive class +class Recursive : public BaseHook +{ + private: + Recursive(const Recursive&); + Recursive & operator=(const Recursive&); + + public: + Recursive() : BaseHook(), children(){} + list< Recursive, base_hook > children; +}; + +int main() +{ + Recursive f, f2; + //A recursive list of Recursive + list< Recursive, base_hook > l; + + //Insert a node in parent list + l.insert(l.begin(), f); + + //Insert a node in child list + l.begin()->children.insert(l.begin()->children.begin(), f2); + + //Objects properly inserted + assert(l.size() == l.begin()->children.size()); + assert(l.size() == 1); + + //Clear both lists + l.begin()->children.clear(); + l.clear(); + return 0; +} +//] diff --git a/example/doc_recursive_member.cpp b/example/doc_recursive_member.cpp new file mode 100644 index 0000000..042acbe --- /dev/null +++ b/example/doc_recursive_member.cpp @@ -0,0 +1,86 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2010-2010 +// +// 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 +//[doc_recursive_member +#include +#include + +using namespace boost::intrusive; + +class Recursive; + +//Declaration of the functor that converts betwen the Recursive +//class and the hook +struct Functor +{ + //Required types + typedef list_member_hook<> hook_type; + typedef hook_type* hook_ptr; + typedef const hook_type* const_hook_ptr; + typedef Recursive value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + + //Required static functions + static hook_ptr to_hook_ptr (value_type &value); + static const_hook_ptr to_hook_ptr(const value_type &value); + static pointer to_value_ptr(hook_ptr n); + static const_pointer to_value_ptr(const_hook_ptr n); +}; + +//Define the recursive class +class Recursive +{ + private: + Recursive(const Recursive&); + Recursive & operator=(const Recursive&); + + public: + Recursive() : hook(), children() {} + list_member_hook<> hook; + list< Recursive, function_hook< Functor> > children; +}; + +//Definition of Functor functions +inline Functor::hook_ptr Functor::to_hook_ptr (Functor::value_type &value) + { return &value.hook; } +inline Functor::const_hook_ptr Functor::to_hook_ptr(const Functor::value_type &value) + { return &value.hook; } +inline Functor::pointer Functor::to_value_ptr(Functor::hook_ptr n) + { return get_parent_from_member(n, &Recursive::hook); } +inline Functor::const_pointer Functor::to_value_ptr(Functor::const_hook_ptr n) + { return get_parent_from_member(n, &Recursive::hook); } + +int main() +{ + Recursive f, f2; + //A recursive list of Recursive + list< Recursive, function_hook< Functor> > l; + + //Insert a node in parent list + l.insert(l.begin(), f); + + //Insert a node in child list + l.begin()->children.insert(l.begin()->children.begin(), f2); + + //Objects properly inserted + assert(l.size() == l.begin()->children.size()); + assert(l.size() == 1); + + //Clear both lists + l.begin()->children.clear(); + l.clear(); + return 0; +} +//] + +#include diff --git a/proj/vc7ide/Intrusive.sln b/proj/vc7ide/Intrusive.sln index 4726fdc..3192a45 100644 --- a/proj/vc7ide/Intrusive.sln +++ b/proj/vc7ide/Intrusive.sln @@ -91,13 +91,19 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "treap_multiset", "treap_mul ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "recursive", "recursive\recursive.vcproj", "{7679B41B-F2B4-9176-CB81-35449467B435}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "function_hook", "function_hook\function_hook.vcproj", "{761A79B4-9968-CB81-F02B-2A4497345475}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject Global GlobalSection(SolutionConfiguration) = preSolution Debug = Debug Release = Release EndGlobalSection - GlobalSection(ProjectDependencies) = postSolution - EndGlobalSection GlobalSection(ProjectConfiguration) = postSolution {977B61B4-9968-497C-9F0B-24A8145473B8}.Debug.ActiveCfg = Debug|Win32 {977B61B4-9968-497C-9F0B-24A8145473B8}.Debug.Build.0 = Debug|Win32 @@ -191,6 +197,14 @@ Global {16E09E95-F4A2-C971-BC76-9BA407191C59}.Debug.Build.0 = Debug|Win32 {16E09E95-F4A2-C971-BC76-9BA407191C59}.Release.ActiveCfg = Release|Win32 {16E09E95-F4A2-C971-BC76-9BA407191C59}.Release.Build.0 = Release|Win32 + {7679B41B-F2B4-9176-CB81-35449467B435}.Debug.ActiveCfg = Debug|Win32 + {7679B41B-F2B4-9176-CB81-35449467B435}.Debug.Build.0 = Debug|Win32 + {7679B41B-F2B4-9176-CB81-35449467B435}.Release.ActiveCfg = Release|Win32 + {7679B41B-F2B4-9176-CB81-35449467B435}.Release.Build.0 = Release|Win32 + {761A79B4-9968-CB81-F02B-2A4497345475}.Debug.ActiveCfg = Debug|Win32 + {761A79B4-9968-CB81-F02B-2A4497345475}.Debug.Build.0 = Debug|Win32 + {761A79B4-9968-CB81-F02B-2A4497345475}.Release.ActiveCfg = Release|Win32 + {761A79B4-9968-CB81-F02B-2A4497345475}.Release.Build.0 = Release|Win32 EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection diff --git a/proj/vc7ide/_intrusivelib/_intrusivelib.vcproj b/proj/vc7ide/_intrusivelib/_intrusivelib.vcproj index 8501d3b..d7f2673 100644 --- a/proj/vc7ide/_intrusivelib/_intrusivelib.vcproj +++ b/proj/vc7ide/_intrusivelib/_intrusivelib.vcproj @@ -156,6 +156,9 @@ + + @@ -373,6 +376,9 @@ + + @@ -394,6 +400,12 @@ + + + + diff --git a/proj/vc7ide/any_test/any_test.vcproj b/proj/vc7ide/any_test/any_test.vcproj index e99365d..b053349 100644 --- a/proj/vc7ide/any_test/any_test.vcproj +++ b/proj/vc7ide/any_test/any_test.vcproj @@ -27,7 +27,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/avl_multiset/avl_multiset.vcproj b/proj/vc7ide/avl_multiset/avl_multiset.vcproj index a2d2cb1..2a80b81 100644 --- a/proj/vc7ide/avl_multiset/avl_multiset.vcproj +++ b/proj/vc7ide/avl_multiset/avl_multiset.vcproj @@ -25,7 +25,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/avl_set/avl_set.vcproj b/proj/vc7ide/avl_set/avl_set.vcproj index e5df0b2..9ecd59d 100644 --- a/proj/vc7ide/avl_set/avl_set.vcproj +++ b/proj/vc7ide/avl_set/avl_set.vcproj @@ -24,7 +24,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/custom_bucket_traits/custom_bucket_traits.vcproj b/proj/vc7ide/custom_bucket_traits/custom_bucket_traits.vcproj index 2c873b8..a396174 100644 --- a/proj/vc7ide/custom_bucket_traits/custom_bucket_traits.vcproj +++ b/proj/vc7ide/custom_bucket_traits/custom_bucket_traits.vcproj @@ -27,7 +27,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/default_hook/default_hook.vcproj b/proj/vc7ide/default_hook/default_hook.vcproj index e6c1b7f..9c26fb7 100644 --- a/proj/vc7ide/default_hook/default_hook.vcproj +++ b/proj/vc7ide/default_hook/default_hook.vcproj @@ -27,7 +27,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/external_value_traits/external_value_traits.vcproj b/proj/vc7ide/external_value_traits/external_value_traits.vcproj index 6f0b875..87ebd51 100644 --- a/proj/vc7ide/external_value_traits/external_value_traits.vcproj +++ b/proj/vc7ide/external_value_traits/external_value_traits.vcproj @@ -27,7 +27,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/function_hook/function_hook.vcproj b/proj/vc7ide/function_hook/function_hook.vcproj new file mode 100644 index 0000000..0fd863c --- /dev/null +++ b/proj/vc7ide/function_hook/function_hook.vcproj @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/proj/vc7ide/list/list.vcproj b/proj/vc7ide/list/list.vcproj index 8f5817b..e5e510b 100644 --- a/proj/vc7ide/list/list.vcproj +++ b/proj/vc7ide/list/list.vcproj @@ -27,7 +27,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/make_functions/make_functions.vcproj b/proj/vc7ide/make_functions/make_functions.vcproj index 572aa02..cf926ce 100644 --- a/proj/vc7ide/make_functions/make_functions.vcproj +++ b/proj/vc7ide/make_functions/make_functions.vcproj @@ -27,7 +27,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/multiset/multiset.vcproj b/proj/vc7ide/multiset/multiset.vcproj index 8828607..423d48e 100644 --- a/proj/vc7ide/multiset/multiset.vcproj +++ b/proj/vc7ide/multiset/multiset.vcproj @@ -24,7 +24,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/recursive/recursive.vcproj b/proj/vc7ide/recursive/recursive.vcproj new file mode 100644 index 0000000..1e4b6db --- /dev/null +++ b/proj/vc7ide/recursive/recursive.vcproj @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/proj/vc7ide/set/set.vcproj b/proj/vc7ide/set/set.vcproj index 85dff59..f7a9976 100644 --- a/proj/vc7ide/set/set.vcproj +++ b/proj/vc7ide/set/set.vcproj @@ -24,7 +24,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/sg_multiset/sg_multiset.vcproj b/proj/vc7ide/sg_multiset/sg_multiset.vcproj index fab36dc..b14f697 100644 --- a/proj/vc7ide/sg_multiset/sg_multiset.vcproj +++ b/proj/vc7ide/sg_multiset/sg_multiset.vcproj @@ -25,7 +25,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/sg_set/sg_set.vcproj b/proj/vc7ide/sg_set/sg_set.vcproj index 222fffc..7910d1b 100644 --- a/proj/vc7ide/sg_set/sg_set.vcproj +++ b/proj/vc7ide/sg_set/sg_set.vcproj @@ -24,7 +24,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/slist/slist.vcproj b/proj/vc7ide/slist/slist.vcproj index 3d118f5..14d5ca7 100644 --- a/proj/vc7ide/slist/slist.vcproj +++ b/proj/vc7ide/slist/slist.vcproj @@ -24,7 +24,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/splay_multiset/splay_multiset.vcproj b/proj/vc7ide/splay_multiset/splay_multiset.vcproj index 8239a8f..3bbce26 100644 --- a/proj/vc7ide/splay_multiset/splay_multiset.vcproj +++ b/proj/vc7ide/splay_multiset/splay_multiset.vcproj @@ -25,7 +25,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/splay_set/splay_set.vcproj b/proj/vc7ide/splay_set/splay_set.vcproj index 63a9d43..2bccaa2 100644 --- a/proj/vc7ide/splay_set/splay_set.vcproj +++ b/proj/vc7ide/splay_set/splay_set.vcproj @@ -24,7 +24,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/stateful_value_traits/stateful_value_traits.vcproj b/proj/vc7ide/stateful_value_traits/stateful_value_traits.vcproj index a5b898e..72cbe3b 100644 --- a/proj/vc7ide/stateful_value_traits/stateful_value_traits.vcproj +++ b/proj/vc7ide/stateful_value_traits/stateful_value_traits.vcproj @@ -27,7 +27,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/to-do.txt b/proj/vc7ide/to-do.txt index 6cda9e3..4a5777f 100644 --- a/proj/vc7ide/to-do.txt +++ b/proj/vc7ide/to-do.txt @@ -14,3 +14,4 @@ -> Non-array buckets -> Document incremental<> option better -> Assure stable order for optimize_multikey and inverse order otherwise +-> add an option to unordered containers to get O(1) traversal and begin()/end() even with very low load factors diff --git a/proj/vc7ide/treap_multiset/treap_multiset.vcproj b/proj/vc7ide/treap_multiset/treap_multiset.vcproj index b0b1edd..af29eb2 100644 --- a/proj/vc7ide/treap_multiset/treap_multiset.vcproj +++ b/proj/vc7ide/treap_multiset/treap_multiset.vcproj @@ -24,7 +24,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/treap_set/treap_set.vcproj b/proj/vc7ide/treap_set/treap_set.vcproj index a6d68a3..5d438fe 100644 --- a/proj/vc7ide/treap_set/treap_set.vcproj +++ b/proj/vc7ide/treap_set/treap_set.vcproj @@ -24,7 +24,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/unordered_multiset/unordered_multiset.vcproj b/proj/vc7ide/unordered_multiset/unordered_multiset.vcproj index 2559e0c..2a8ec4a 100644 --- a/proj/vc7ide/unordered_multiset/unordered_multiset.vcproj +++ b/proj/vc7ide/unordered_multiset/unordered_multiset.vcproj @@ -25,7 +25,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/unordered_set/unordered_set.vcproj b/proj/vc7ide/unordered_set/unordered_set.vcproj index 1496175..a3bb584 100644 --- a/proj/vc7ide/unordered_set/unordered_set.vcproj +++ b/proj/vc7ide/unordered_set/unordered_set.vcproj @@ -25,7 +25,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/proj/vc7ide/virtual_base/virtual_base.vcproj b/proj/vc7ide/virtual_base/virtual_base.vcproj index 7d87163..b5f6f66 100644 --- a/proj/vc7ide/virtual_base/virtual_base.vcproj +++ b/proj/vc7ide/virtual_base/virtual_base.vcproj @@ -27,7 +27,7 @@ MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" - DisableLanguageExtensions="TRUE" + DisableLanguageExtensions="FALSE" TreatWChar_tAsBuiltInType="TRUE" ForceConformanceInForLoopScope="TRUE" UsePrecompiledHeader="0" diff --git a/test/function_hook_test.cpp b/test/function_hook_test.cpp new file mode 100644 index 0000000..5b9e570 --- /dev/null +++ b/test/function_hook_test.cpp @@ -0,0 +1,152 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2010-2010 +// +// 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 +#include +#include +#include + +using namespace boost::intrusive; + +struct MyClass +{ + MyClass() : order(0) {} + int order; + + //This internal type has two hooks + struct InnerNode : public list_base_hook<>, public slist_base_hook<> + , public set_base_hook<>, public unordered_set_base_hook<> + { + list_member_hook<> listhook; + slist_member_hook<> slisthook; + set_member_hook<> sethook; + unordered_set_member_hook<> usethook; + } inner; + + friend bool operator < (const MyClass &l, const MyClass &r) + { return l.order < r.order; } + friend bool operator == (const MyClass &l, const MyClass &r) + { return l.order == r.order; } + friend std::size_t hash_value(const MyClass &value) + { return std::size_t(value.order); } +}; + +//This functor converts between MyClass and the InnerNode member hook +#define InnerMemberHook(TAG, HOOKTYPE, MEMBERNAME)\ + struct InnerMemberHookFunctor##TAG \ + {\ + typedef HOOKTYPE hook_type;\ + typedef hook_type* hook_ptr;\ + typedef const hook_type* const_hook_ptr;\ + typedef MyClass value_type;\ + typedef value_type* pointer;\ + typedef const value_type* const_pointer;\ + \ + static hook_ptr to_hook_ptr (value_type &value)\ + { return &value.inner.MEMBERNAME; }\ + static const_hook_ptr to_hook_ptr(const value_type &value)\ + { return &value.inner.MEMBERNAME; }\ + static pointer to_value_ptr(hook_ptr n)\ + {\ + return get_parent_from_member\ + (get_parent_from_member(n, &MyClass::InnerNode::MEMBERNAME)\ + ,&MyClass::inner\ + );\ + }\ + static const_pointer to_value_ptr(const_hook_ptr n)\ + {\ + return get_parent_from_member\ + (get_parent_from_member(n, &MyClass::InnerNode::MEMBERNAME)\ + ,&MyClass::inner\ + );\ + }\ + };\ +// + + +//This functor converts between MyClass and the InnerNode base hook +#define InnerBaseHook(TAG, HOOKTYPE)\ + struct InnerBaseHookFunctor##TAG \ + {\ + typedef HOOKTYPE hook_type;\ + typedef hook_type* hook_ptr;\ + typedef const hook_type* const_hook_ptr;\ + typedef MyClass value_type;\ + typedef value_type* pointer;\ + typedef const value_type* const_pointer;\ + \ + static hook_ptr to_hook_ptr (value_type &value)\ + { return &value.inner; }\ + static const_hook_ptr to_hook_ptr(const value_type &value)\ + { return &value.inner; }\ + static pointer to_value_ptr(hook_ptr n)\ + {\ + return get_parent_from_member(static_cast(n),&MyClass::inner);\ + }\ + static const_pointer to_value_ptr(const_hook_ptr n)\ + {\ + return get_parent_from_member(static_cast(n),&MyClass::inner);\ + }\ + };\ +// + +//List +InnerMemberHook(List, list_member_hook<>, listhook) +InnerBaseHook(List, list_base_hook<>) +//Slist +InnerMemberHook(Slist, slist_member_hook<>, slisthook) +InnerBaseHook(Slist, slist_base_hook<>) +//Set +InnerMemberHook(Set, set_member_hook<>, sethook) +InnerBaseHook(Set, set_base_hook<>) +//Unordered Set +InnerMemberHook(USet, unordered_set_member_hook<>, usethook) +InnerBaseHook(USet, unordered_set_base_hook<>) + +//Define containers +typedef list < MyClass, function_hook< InnerMemberHookFunctorList> > CustomListMember; +typedef list < MyClass, function_hook< InnerBaseHookFunctorList > > CustomListBase; +typedef slist< MyClass, function_hook< InnerMemberHookFunctorSlist> > CustomSlistMember; +typedef slist< MyClass, function_hook< InnerBaseHookFunctorSlist > > CustomSlistBase; +typedef set < MyClass, function_hook< InnerMemberHookFunctorSet> > CustomSetMember; +typedef set < MyClass, function_hook< InnerBaseHookFunctorSet > > CustomSetBase; +typedef unordered_set< MyClass, function_hook< InnerMemberHookFunctorUSet> > CustomUSetMember; +typedef unordered_set< MyClass, function_hook< InnerBaseHookFunctorUSet > > CustomUSetBase; + +int main() +{ + MyClass n; + CustomListBase listbase; + CustomListMember listmember; + CustomSlistBase slistbase; + CustomSlistMember slistmember; + CustomSetBase setbase; + CustomSetMember setmember; + CustomUSetBase::bucket_type buckets[1]; + CustomUSetBase usetbase(CustomUSetBase::bucket_traits(buckets, 1)); + CustomUSetMember usetmember(CustomUSetMember::bucket_traits(buckets, 1)); + + listbase.insert(listbase.begin(), n); + listmember.insert(listmember.begin(), n); + slistbase.insert(slistbase.begin(), n); + slistmember.insert(slistmember.begin(), n); + setbase.insert(n); + setmember.insert(n); + usetbase.insert(n); + usetmember.insert(n); + + return 0; +} + +#include diff --git a/test/generic_assoc_test.hpp b/test/generic_assoc_test.hpp index 5d10d72..7ff75f7 100644 --- a/test/generic_assoc_test.hpp +++ b/test/generic_assoc_test.hpp @@ -402,9 +402,9 @@ void test_generic_assoc::test_insert_before for(vec_iterator it(--values.end()); true; --it){ testset.push_front(*it); - if(it == values.begin()){ + if(it == values.begin()){ break; - } + } } BOOST_TEST(testset.size() == values.size()); TEST_INTRUSIVE_SEQUENCE_EXPECTED(values, testset.begin()); diff --git a/test/list_test.cpp b/test/list_test.cpp index e9f8b74..b55ec08 100644 --- a/test/list_test.cpp +++ b/test/list_test.cpp @@ -10,10 +10,8 @@ // See http://www.boost.org/libs/intrusive for documentation. // ///////////////////////////////////////////////////////////////////////////// - #include #include - #include #include "itestvalue.hpp" #include "smart_ptr.hpp" @@ -500,4 +498,3 @@ int main( int, char* [] ) return boost::report_errors(); } -#include diff --git a/test/recursive_test.cpp b/test/recursive_test.cpp new file mode 100644 index 0000000..c72316b --- /dev/null +++ b/test/recursive_test.cpp @@ -0,0 +1,71 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2007-2010 +// +// 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 +#include +#include +#include +#include +#include + +using namespace boost::intrusive; + +typedef list_base_hook<> ListBaseHook; +typedef slist_base_hook<> SListBaseHook; +typedef set_base_hook<> SetBaseHook; +typedef unordered_set_base_hook<> USetBaseHook; + +class Foo; +typedef unordered_set > USet; + +class Foo : public ListBaseHook, public SListBaseHook, public SetBaseHook, public USetBaseHook +{ + USet::bucket_type buckets[1]; + Foo(const Foo &); + Foo & operator=(const Foo &); + + public: + Foo() : uset_children(USet::bucket_traits(buckets, 1)) + {} + list > list_children; + slist > slist_children; + set > set_children; + USet uset_children; +}; + +void instantiate() +{ + list< Foo, base_hook > list_; list_.clear(); + slist< Foo, base_hook > slist_; slist_.clear(); + set< Foo, base_hook > set_; set_.clear(); + + USet::bucket_type buckets[1]; + USet unordered_set_(USet::bucket_traits(buckets, 1)); unordered_set_.clear(); +} +int main() +{ + instantiate(); + + //A small test with list + { + Foo f, f2; + list< Foo, base_hook > l; + l.insert(l.begin(), f); + l.begin()->list_children.insert(l.begin()->list_children.begin(), f2); + assert(l.size() == l.begin()->list_children.size()); + l.begin()->list_children.clear(); + l.clear(); + } + return 0; +} diff --git a/test/smart_ptr.hpp b/test/smart_ptr.hpp index c5ccfc5..6965eab 100644 --- a/test/smart_ptr.hpp +++ b/test/smart_ptr.hpp @@ -13,6 +13,7 @@ #include #include +#include #if (defined _MSC_VER) && (_MSC_VER >= 1200) # pragma once @@ -312,7 +313,7 @@ inline T* boost_intrusive_get_pointer(const smart_ptr & p) //!Simulation of static_cast between pointers. Never throws. template inline smart_ptr - static_pointer_cast(smart_ptr const & r) + static_pointer_cast(const smart_ptr & r) { return smart_ptr(r, detail::static_cast_tag()); }