diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index d64860b..d21ab56 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -53,7 +53,9 @@ doxygen autodoc \"avltree_impl=avltree\" \\ \"treap_set_impl=treap_set\" \\ \"treap_multiset_impl=treap_multiset\" \\ - \"treap_impl=treap\"" + \"treap_impl=treap\" \\ + \"BOOST_INTRUSIVE_OPTION_CONSTANT(OPTION_NAME, TYPE, VALUE, CONSTANT_NAME) = template struct OPTION_NAME{};\" \\ + \"BOOST_INTRUSIVE_OPTION_TYPE(OPTION_NAME, TYPE, TYPEDEF_EXPR, TYPEDEF_NAME) = template struct OPTION_NAME{};\" " ; xml intrusive : intrusive.qbk diff --git a/example/doc_auto_unlink.cpp b/example/doc_auto_unlink.cpp index 5fb12f4..b44dd31 100644 --- a/example/doc_auto_unlink.cpp +++ b/example/doc_auto_unlink.cpp @@ -24,7 +24,8 @@ class MyClass : public auto_unlink_hook public: MyClass(int i = 0) : int_(i) {} - void unlink() { auto_unlink_hook::unlink(); } + int get_int() { return int_; } + void unlink() { auto_unlink_hook::unlink(); } bool is_linked() { return auto_unlink_hook::is_linked(); } }; diff --git a/include/boost/intrusive/options.hpp b/include/boost/intrusive/options.hpp index 6d06a79..cbbd123 100644 --- a/include/boost/intrusive/options.hpp +++ b/include/boost/intrusive/options.hpp @@ -16,15 +16,15 @@ #include #include #include +#include #include #include #include - namespace boost { namespace intrusive { -/// @cond +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED //typedef void default_tag; struct default_tag; @@ -34,8 +34,6 @@ namespace detail{ struct default_hook_tag{}; -#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED - #define BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER) \ struct BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER : public default_hook_tag\ {\ @@ -50,14 +48,9 @@ BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_rbtree_hook); BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_hashtable_hook); BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_avltree_hook); BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_bstree_hook); -//BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_splaytree_hook); -//BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_sgtree_hook); -//BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_treap_hook); #undef BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION -#endif //BOOST_INTRUSIVE_DOXYGEN_INVOKED - template struct eval_value_traits { @@ -165,7 +158,7 @@ struct get_value_traits //...get it's internal value traits using //the provided T value type. , get_base_value_traits - //...else use it's internal value traits tag + //...else use its internal value traits tag //(member hooks and custom value traits are in this group) , detail::eval_if_c < internal_member_value_traits::value @@ -191,7 +184,7 @@ struct get_node_traits //...get it's internal value traits using //the provided T value type. , get_base_node_traits - //...else use it's internal value traits tag + //...else use its internal value traits tag //(member hooks and custom value traits are in this group) , detail::eval_if_c < internal_member_value_traits::value @@ -203,50 +196,20 @@ struct get_node_traits } //namespace detail{ -/// @endcond +#endif //BOOST_INTRUSIVE_DOXYGEN_INVOKED //!This option setter specifies if the intrusive //!container stores its size as a member to //!obtain constant-time size() member. -template -struct constant_time_size -{ -/// @cond - template - struct pack : Base - { - static const bool constant_time_size = Enabled; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(constant_time_size, bool, Enabled, constant_time_size) //!This option setter specifies the type that //!the container will use to store its size. -template -struct size_type -{ -/// @cond - template - struct pack : Base - { - typedef SizeType size_type; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(size_type, SizeType, SizeType, size_type) //!This option setter specifies the strict weak ordering //!comparison functor for the value type -template -struct compare -{ -/// @cond - template - struct pack : Base - { - typedef Compare compare; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(compare, Compare, Compare, compare) //!This option setter for scapegoat containers specifies if //!the intrusive scapegoat container should use a non-variable @@ -260,74 +223,39 @@ struct compare //!If the user only needs an alpha value near 1/sqrt(2), this //!option also improves performance since avoids logarithm //!and division operations when rebalancing the tree. -template -struct floating_point -{ -/// @cond - template - struct pack : Base - { - static const bool floating_point = Enabled; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(floating_point, bool, Enabled, floating_point) //!This option setter specifies the equality //!functor for the value type -template -struct equal -{ -/// @cond - template - struct pack : Base - { - typedef Equal equal; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(equal, Equal, Equal, equal) //!This option setter specifies the equality //!functor for the value type -template -struct priority -{ -/// @cond - template - struct pack : Base - { - typedef Priority priority; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(priority, Priority, Priority, priority) //!This option setter specifies the hash //!functor for the value type -template -struct hash -{ -/// @cond - template - struct pack : Base - { - typedef Hash hash; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(hash, Hash, Hash, hash) //!This option setter specifies the relationship between the type //!to be managed by the container (the value type) and the node to be //!used in the node algorithms. It also specifies the linking policy. -template -struct value_traits -{ -/// @cond - template - struct pack : Base - { - typedef ValueTraits proto_value_traits; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(value_traits, ValueTraits, ValueTraits, proto_value_traits) + +//#define BOOST_INTRUSIVE_COMMA , +//#define BOOST_INTRUSIVE_LESS < +//#define BOOST_INTRUSIVE_MORE > +//BOOST_INTRUSIVE_OPTION_TYPE (member_hook, Parent BOOST_INTRUSIVE_COMMA class MemberHook BOOST_INTRUSIVE_COMMA MemberHook Parent::* PtrToMember , mhtraits BOOST_INTRUSIVE_LESS Parent BOOST_INTRUSIVE_COMMA MemberHook BOOST_INTRUSIVE_COMMA PtrToMember BOOST_INTRUSIVE_MORE , proto_value_traits) +//template< class Parent , class MemberHook , MemberHook Parent::* PtrToMember> +//struct member_hook { +// template struct pack : Base { +// typedef mhtraits < Parent , MemberHook , PtrToMember > proto_value_traits; +// }; +//}; +// +//#undef BOOST_INTRUSIVE_COMMA +//#undef BOOST_INTRUSIVE_LESS +//#undef BOOST_INTRUSIVE_MORE //!This option setter specifies the member hook the //!container must use. @@ -336,27 +264,21 @@ template< typename Parent , MemberHook Parent::* PtrToMember> struct member_hook { -/// @cond -/* - typedef typename MemberHook::hooktags::node_traits node_traits; - typedef typename node_traits::node node_type; - typedef node_type Parent::* Ptr2MemNode; - typedef mhtraits - < Parent - , node_traits - //This cast is really ugly but necessary to reduce template bloat. - //Since we control the layout between the hook and the node, and there is - //always single inheritance, the offset of the node is exactly the offset of - //the hook. Since the node type is shared between all member hooks, this saves - //quite a lot of symbol stuff. - , (Ptr2MemNode)PtrToMember - , MemberHook::hooktags::link_mode> member_value_traits; -*/ - typedef mhtraits - < Parent - , MemberHook - , PtrToMember - > member_value_traits; +// @cond +// typedef typename MemberHook::hooktags::node_traits node_traits; +// typedef typename node_traits::node node_type; +// typedef node_type Parent::* Ptr2MemNode; +// typedef mhtraits +// < Parent +// , node_traits +// //This cast is really ugly but necessary to reduce template bloat. +// //Since we control the layout between the hook and the node, and there is +// //always single inheritance, the offset of the node is exactly the offset of +// //the hook. Since the node type is shared between all member hooks, this saves +// //quite a lot of symbol stuff. +// , (Ptr2MemNode)PtrToMember +// , MemberHook::hooktags::link_mode> member_value_traits; + typedef mhtraits member_value_traits; template struct pack : Base { @@ -365,158 +287,54 @@ struct member_hook /// @endcond }; - //!This option setter specifies the function object that will //!be used to convert between values to be inserted in a container //!and the hook to be used for that purpose. -template< typename Functor> -struct function_hook -{ -/// @cond - typedef fhtraits - function_value_traits; - template - struct pack : Base - { - typedef function_value_traits proto_value_traits; - }; -/// @endcond -}; - +BOOST_INTRUSIVE_OPTION_TYPE(function_hook, Functor, fhtraits, proto_value_traits) //!This option setter specifies that the container //!must use the specified base hook -template -struct base_hook -{ -/// @cond - template - struct pack : Base - { - typedef BaseHook proto_value_traits; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(base_hook, BaseHook, BaseHook, proto_value_traits) //!This option setter specifies the type of //!a void pointer. This will instruct the hook //!to use this type of pointer instead of the //!default one -template -struct void_pointer -{ -/// @cond - template - struct pack : Base - { - typedef VoidPointer void_pointer; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(void_pointer, VoidPointer, VoidPointer, void_pointer) //!This option setter specifies the type of //!the tag of a base hook. A type cannot have two //!base hooks of the same type, so a tag can be used //!to differentiate two base hooks with otherwise same type -template -struct tag -{ -/// @cond - template - struct pack : Base - { - typedef Tag tag; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(tag, Tag, Tag, tag) //!This option setter specifies the link mode //!(normal_link, safe_link or auto_unlink) -template -struct link_mode -{ -/// @cond - template - struct pack : Base - { - static const link_mode_type link_mode = LinkType; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(link_mode, link_mode_type, LinkType, link_mode) //!This option setter specifies if the hook //!should be optimized for size instead of for speed. -template -struct optimize_size -{ -/// @cond - template - struct pack : Base - { - static const bool optimize_size = Enabled; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(optimize_size, bool, Enabled, optimize_size) //!This option setter specifies if the list container should //!use a linear implementation instead of a circular one. -template -struct linear -{ -/// @cond - template - struct pack : Base - { - static const bool linear = Enabled; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(linear, bool, Enabled, linear) //!This option setter specifies if the list container should //!use a linear implementation instead of a circular one. -template -struct cache_last -{ -/// @cond - template - struct pack : Base - { - static const bool cache_last = Enabled; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(cache_last, bool, Enabled, cache_last) //!This option setter specifies the bucket traits //!class for unordered associative containers. When this option is specified, //!instead of using the default bucket traits, a user defined holder will be defined -template -struct bucket_traits -{ -/// @cond - template - struct pack : Base - { - typedef BucketTraits bucket_traits; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(bucket_traits, BucketTraits, BucketTraits, bucket_traits) //!This option setter specifies if the unordered hook //!should offer room to store the hash value. //!Storing the hash in the hook will speed up rehashing //!processes in applications where rehashing is frequent, //!rehashing might throw or the value is heavy to hash. -template -struct store_hash -{ -/// @cond - template - struct pack : Base - { - static const bool store_hash = Enabled; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(store_hash, bool, Enabled, store_hash) //!This option setter specifies if the unordered hook //!should offer room to store another link to another node @@ -524,51 +342,20 @@ struct store_hash //!Storing this link will speed up lookups and insertions on //!unordered_multiset containers with a great number of elements //!with the same key. -template -struct optimize_multikey -{ -/// @cond - template - struct pack : Base - { - static const bool optimize_multikey = Enabled; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(optimize_multikey, bool, Enabled, optimize_multikey) //!This option setter specifies if the bucket array will be always power of two. //!This allows using masks instead of the default modulo operation to determine //!the bucket number from the hash value, leading to better performance. //!In debug mode, if power of two buckets mode is activated, the bucket length //!will be checked to through assertions to assure the bucket length is power of two. -template -struct power_2_buckets -{ -/// @cond - template - struct pack : Base - { - static const bool power_2_buckets = Enabled; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(power_2_buckets, bool, Enabled, power_2_buckets) //!This option setter specifies if the container will cache a pointer to the first //!non-empty bucket so that begin() is always constant-time. //!This is specially helpful when we can have containers with a few elements //!but with big bucket arrays (that is, hashtables with low load factors). -template -struct cache_begin -{ -/// @cond - template - struct pack : Base - { - static const bool cache_begin = Enabled; - }; -/// @endcond -}; - +BOOST_INTRUSIVE_OPTION_CONSTANT(cache_begin, bool, Enabled, cache_begin) //!This option setter specifies if the container will compare the hash value //!before comparing objects. This option can't be specified if store_hash<> @@ -576,17 +363,7 @@ struct cache_begin //!This is specially helpful when we have containers with a high load factor. //!and the comparison function is much more expensive that comparing already //!stored hash values. -template -struct compare_hash -{ -/// @cond - template - struct pack : Base - { - static const bool compare_hash = Enabled; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(compare_hash, bool, Enabled, compare_hash) //!This option setter specifies if the hash container will use incremental //!hashing. With incremental hashing the cost of hash table expansion is spread @@ -594,17 +371,7 @@ struct compare_hash //!Therefore linear hashing is well suited for interactive applications or real-time //!appplications where the worst-case insertion time of non-incremental hash containers //!(rehashing the whole bucket array) is not admisible. -template -struct incremental -{ - /// @cond - template - struct pack : Base - { - static const bool incremental = Enabled; - }; - /// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(incremental, bool, Enabled, incremental) /// @cond @@ -615,210 +382,6 @@ struct none {}; }; -//To-do: pass to variadic templates -#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - -template -struct do_pack -{ - //Use "pack" member template to pack options - typedef typename Next::template pack type; -}; - -template -struct do_pack -{ - //Avoid packing "void" to shorten template names - typedef Prev type; -}; - -template - < class DefaultOptions - , class O1 = void - , class O2 = void - , class O3 = void - , class O4 = void - , class O5 = void - , class O6 = void - , class O7 = void - , class O8 = void - , class O9 = void - , class O10 = void - , class O11 = void - > -struct pack_options -{ - // join options - typedef - typename do_pack - < typename do_pack - < typename do_pack - < typename do_pack - < typename do_pack - < typename do_pack - < typename do_pack - < typename do_pack - < typename do_pack - < typename do_pack - < typename do_pack - < DefaultOptions - , O1 - >::type - , O2 - >::type - , O3 - >::type - , O4 - >::type - , O5 - >::type - , O6 - >::type - , O7 - >::type - , O8 - >::type - , O9 - >::type - , O10 - >::type - , O11 - >::type - type; -}; -#else - -//index_tuple -template -struct index_tuple{}; - -//build_number_seq -template > -struct build_number_seq; - -template -struct build_number_seq > - : build_number_seq > -{}; - -template -struct build_number_seq<0, index_tuple > -{ typedef index_tuple type; }; - -template -struct typelist -{}; - -//invert_typelist -template -struct invert_typelist; - -template -struct typelist_element; - -template -struct typelist_element > -{ - typedef typename typelist_element >::type type; -}; - -template -struct typelist_element<0, typelist > -{ - typedef Head type; -}; - -template -typelist >::type...> - inverted_typelist(index_tuple, typelist) -{ - return typelist >::type...>(); -} - -//sizeof_typelist -template -struct sizeof_typelist; - -template -struct sizeof_typelist< typelist > -{ - static const std::size_t value = sizeof...(Types); -}; - -//invert_typelist_impl -template -struct invert_typelist_impl; - - -template -struct invert_typelist_impl< Typelist, index_tuple > -{ - static const std::size_t last_idx = sizeof_typelist::value - 1; - typedef typelist - ::type...> type; -}; - -template -struct invert_typelist_impl< Typelist, index_tuple > -{ - typedef Typelist type; -}; - -template -struct invert_typelist_impl< Typelist, index_tuple<> > -{ - typedef Typelist type; -}; - -//invert_typelist -template -struct invert_typelist; - -template -struct invert_typelist< typelist > -{ - typedef typelist typelist_t; - typedef typename build_number_seq::type indexes_t; - typedef typename invert_typelist_impl::type type; -}; - -//Do pack -template -struct do_pack; - -template<> -struct do_pack >; - -template -struct do_pack > -{ - typedef Prev type; -}; - -template -struct do_pack > -{ - typedef typename Prev::template pack type; -}; - -template -struct do_pack > -{ - typedef typename Prev::template pack - >::type> type; -}; - - -template -struct pack_options -{ - typedef typelist typelist_t; - typedef typename invert_typelist::type inverted_typelist; - typedef typename do_pack::type type; -}; - -#endif - struct hook_defaults { typedef void* void_pointer; diff --git a/include/boost/intrusive/pack_options.hpp b/include/boost/intrusive/pack_options.hpp new file mode 100644 index 0000000..7d282dd --- /dev/null +++ b/include/boost/intrusive/pack_options.hpp @@ -0,0 +1,370 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2013-2013 +// +// 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. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_PACK_OPTIONS_HPP +#define BOOST_INTRUSIVE_PACK_OPTIONS_HPP + +#include + +namespace boost { +namespace intrusive { + +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + +template +struct do_pack +{ + //Use "pack" member template to pack options + typedef typename Next::template pack type; +}; + +template +struct do_pack +{ + //Avoid packing "void" to shorten template names + typedef Prev type; +}; + +template + < class DefaultOptions + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void + , class O6 = void + , class O7 = void + , class O8 = void + , class O9 = void + , class O10 = void + , class O11 = void + > +struct pack_options +{ + // join options + typedef + typename do_pack + < typename do_pack + < typename do_pack + < typename do_pack + < typename do_pack + < typename do_pack + < typename do_pack + < typename do_pack + < typename do_pack + < typename do_pack + < typename do_pack + < DefaultOptions + , O1 + >::type + , O2 + >::type + , O3 + >::type + , O4 + >::type + , O5 + >::type + , O6 + >::type + , O7 + >::type + , O8 + >::type + , O9 + >::type + , O10 + >::type + , O11 + >::type + type; +}; +#else + +//index_tuple +template +struct index_tuple{}; + +//build_number_seq +template > +struct build_number_seq; + +template +struct build_number_seq > + : build_number_seq > +{}; + +template +struct build_number_seq<0, index_tuple > +{ typedef index_tuple type; }; + +template +struct typelist +{}; + +//invert_typelist +template +struct invert_typelist; + +template +struct typelist_element; + +template +struct typelist_element > +{ + typedef typename typelist_element >::type type; +}; + +template +struct typelist_element<0, typelist > +{ + typedef Head type; +}; + +template +typelist >::type...> + inverted_typelist(index_tuple, typelist) +{ + return typelist >::type...>(); +} + +//sizeof_typelist +template +struct sizeof_typelist; + +template +struct sizeof_typelist< typelist > +{ + static const std::size_t value = sizeof...(Types); +}; + +//invert_typelist_impl +template +struct invert_typelist_impl; + + +template +struct invert_typelist_impl< Typelist, index_tuple > +{ + static const std::size_t last_idx = sizeof_typelist::value - 1; + typedef typelist + ::type...> type; +}; + +template +struct invert_typelist_impl< Typelist, index_tuple > +{ + typedef Typelist type; +}; + +template +struct invert_typelist_impl< Typelist, index_tuple<> > +{ + typedef Typelist type; +}; + +//invert_typelist +template +struct invert_typelist; + +template +struct invert_typelist< typelist > +{ + typedef typelist typelist_t; + typedef typename build_number_seq::type indexes_t; + typedef typename invert_typelist_impl::type type; +}; + +//Do pack +template +struct do_pack; + +template<> +struct do_pack >; + +template +struct do_pack > +{ + typedef Prev type; +}; + +template +struct do_pack > +{ + typedef typename Prev::template pack type; +}; + +template +struct do_pack > +{ + typedef typename Prev::template pack + >::type> type; +}; + + +template +struct pack_options +{ + typedef typelist typelist_t; + typedef typename invert_typelist::type inverted_typelist; + typedef typename do_pack::type type; +}; + +#endif //!defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + +#define BOOST_INTRUSIVE_OPTION_TYPE(OPTION_NAME, TYPE, TYPEDEF_EXPR, TYPEDEF_NAME) \ +template< class TYPE> \ +struct OPTION_NAME \ +{ \ + template \ + struct pack : Base \ + { \ + typedef TYPEDEF_EXPR TYPEDEF_NAME; \ + }; \ +}; \ +// + +#define BOOST_INTRUSIVE_OPTION_CONSTANT(OPTION_NAME, TYPE, VALUE, CONSTANT_NAME) \ +template< TYPE VALUE> \ +struct OPTION_NAME \ +{ \ + template \ + struct pack : Base \ + { \ + static const TYPE CONSTANT_NAME = VALUE; \ + }; \ +}; \ +// + +#else //#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + +//! This class is a utility that takes: +//! - a default options class defining initial static constant +//! and typedefs +//! - several options defined with BOOST_INTRUSIVE_OPTION_CONSTANT and +//! BOOST_INTRUSIVE_OPTION_TYPE +//! +//! and packs them together in a new type that defines all options as +//! member typedefs or static constant values. Given options of form: +//! +//! \code +//! BOOST_INTRUSIVE_OPTION_TYPE(my_pointer, VoidPointer, VoidPointer, my_pointer_type) +//! BOOST_INTRUSIVE_OPTION_CONSTANT(incremental, bool, Enabled, is_incremental) +//! \endcode +//! +//! the following expression +//! +//! \code +//! +//! struct default_options +//! { +//! typedef long int_type; +//! static const int int_constant = -1; +//! }; +//! +//! pack_options< default_options, my_pointer, incremental >::type +//! \endcode +//! +//! will create a type that will contain the following typedefs/constants +//! +//! \code +//! struct unspecified_type +//! { +//! //Default options +//! typedef long int_type; +//! static const int int_constant = -1; +//! +//! //Packed options (will ovewrite any default option) +//! typedef void* my_pointer_type; +//! static const bool is_incremental = true; +//! }; +//! \endcode +//! +//! If an option is specified in the default options argument and later +//! redefined as an option, the last definition will prevail. +template +struct pack_options +{ + typedef unspecified_type type; +}; + +//! Defines an option class of name OPTION_NAME that can be used to specify a type +//! of type TYPE... +//! +//! \code +//! struct OPTION_NAME +//! { /*unspecified_content*/ }; +//! \endcode +//! +//! ...that after being combined with +//! boost::intrusive::pack_options, +//! will typedef TYPE as a typedef of name TYPEDEF_NAME. Example: +//! +//! \code +//! //[includes and namespaces omitted for brevity] +//! +//! //This macro will create the following class: +//! // template +//! // struct my_pointer +//! // { unspecified_content }; +//! BOOST_INTRUSIVE_OPTION_TYPE(my_pointer, VoidPointer, boost::remove_pointer::type, my_pointer_type) +//! +//! struct empty_default{}; +//! +//! typedef pack_options< empty_default, typename my_pointer >::type::my_pointer_type type; +//! +//! BOOST_STATIC_ASSERT(( boost::is_same::value )); +//! +//! \endcode +#define BOOST_INTRUSIVE_OPTION_TYPE(OPTION_NAME, TYPE, TYPEDEF_EXPR, TYPEDEF_NAME) + +//! Defines an option class of name OPTION_NAME that can be used to specify a constant +//! of type TYPE with value VALUE... +//! +//! \code +//! struct OPTION_NAME +//! { /*unspecified_content*/ }; +//! \endcode +//! +//! ...that after being combined with +//! boost::intrusive::pack_options, +//! will contain a CONSTANT_NAME static constant of value VALUE. Example: +//! +//! \code +//! //[includes and namespaces omitted for brevity] +//! +//! //This macro will create the following class: +//! // template +//! // struct incremental +//! // { unspecified_content }; +//! BOOST_INTRUSIVE_OPTION_CONSTANT(incremental, bool, Enabled, is_incremental) +//! +//! struct empty_default{}; +//! +//! const bool is_incremental = pack_options< empty_default, incremental >::type::is_incremental; +//! +//! BOOST_STATIC_ASSERT(( is_incremental == true )); +//! +//! \endcode +#define BOOST_INTRUSIVE_OPTION_CONSTANT(OPTION_NAME, TYPE, VALUE, CONSTANT_NAME) + +#endif //#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + +} //namespace intrusive { +} //namespace boost { + +#include + +#endif //#ifndef BOOST_INTRUSIVE_PACK_OPTIONS_HPP diff --git a/proj/vc7ide/Intrusive.sln b/proj/vc7ide/Intrusive.sln index 54fcb68..890c29e 100644 --- a/proj/vc7ide/Intrusive.sln +++ b/proj/vc7ide/Intrusive.sln @@ -115,6 +115,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "scary_iterators", "scary_it ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pack_options", "pack_options\pack_options.vcproj", "{77F4139B-281B-F694-7CB1-3495467B4D35}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject Global GlobalSection(SolutionConfiguration) = preSolution Debug = Debug @@ -239,6 +243,10 @@ Global {7679B41B-C1C5-FA34-9614-3547B3140346}.Debug.Build.0 = Debug|Win32 {7679B41B-C1C5-FA34-9614-3547B3140346}.Release.ActiveCfg = Release|Win32 {7679B41B-C1C5-FA34-9614-3547B3140346}.Release.Build.0 = Release|Win32 + {77F4139B-281B-F694-7CB1-3495467B4D35}.Debug.ActiveCfg = Debug|Win32 + {77F4139B-281B-F694-7CB1-3495467B4D35}.Debug.Build.0 = Debug|Win32 + {77F4139B-281B-F694-7CB1-3495467B4D35}.Release.ActiveCfg = Release|Win32 + {77F4139B-281B-F694-7CB1-3495467B4D35}.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 31c88f3..079a8ae 100644 --- a/proj/vc7ide/_intrusivelib/_intrusivelib.vcproj +++ b/proj/vc7ide/_intrusivelib/_intrusivelib.vcproj @@ -157,6 +157,9 @@ + + diff --git a/proj/vc7ide/pack_options/pack_options.vcproj b/proj/vc7ide/pack_options/pack_options.vcproj new file mode 100644 index 0000000..6da13c6 --- /dev/null +++ b/proj/vc7ide/pack_options/pack_options.vcproj @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/proj/vc7ide/set/set.vcproj b/proj/vc7ide/set/set.vcproj index f7a9976..2fb2369 100644 --- a/proj/vc7ide/set/set.vcproj +++ b/proj/vc7ide/set/set.vcproj @@ -21,6 +21,7 @@ Optimization="0" AdditionalIncludeDirectories="../../../../../" PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" + GeneratePreprocessedFile="0" MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="5" diff --git a/test/pack_options_test.cpp b/test/pack_options_test.cpp new file mode 100644 index 0000000..2f0ef09 --- /dev/null +++ b/test/pack_options_test.cpp @@ -0,0 +1,60 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2013-2013. 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 + +struct empty_default{}; + +using namespace boost::intrusive; + +//Test BOOST_INTRUSIVE_OPTION_CONSTANT +BOOST_INTRUSIVE_OPTION_CONSTANT(incremental, bool, Enabled, is_incremental) +const bool is_incremental_value = pack_options< empty_default, incremental >::type::is_incremental; +BOOST_STATIC_ASSERT(( is_incremental_value == true )); + +//Test BOOST_INTRUSIVE_OPTION_TYPE +BOOST_INTRUSIVE_OPTION_TYPE(my_pointer, VoidPointer, typename boost::remove_pointer::type, my_pointer_type) +typedef pack_options< empty_default, my_pointer >::type::my_pointer_type my_pointer_type; +BOOST_STATIC_ASSERT(( boost::is_same::value )); + +//test combination of BOOST_INTRUSIVE_OPTION_CONSTANT and BOOST_INTRUSIVE_OPTION_TYPE +// First add new options +struct default_options +{ + static const long long_constant = -3; + typedef double * double_typedef; +}; + +BOOST_INTRUSIVE_OPTION_CONSTANT(incremental2, bool, Enabled, is_incremental2) +BOOST_INTRUSIVE_OPTION_TYPE(my_pointer2, VoidPointer, typename boost::add_pointer::type, my_pointer_type2) +typedef pack_options < default_options + , incremental + , my_pointer + , incremental2 + , my_pointer2 + >::type combined_type; +BOOST_STATIC_ASSERT(( combined_type::is_incremental == false )); +BOOST_STATIC_ASSERT(( combined_type::is_incremental2 == true )); +BOOST_STATIC_ASSERT(( boost::is_same::value )); +BOOST_STATIC_ASSERT(( boost::is_same::value )); + +//test packing the default options leads to a default options type +BOOST_STATIC_ASSERT(( boost::is_same::type, default_options>::value )); + +int main() +{ + return 0; +} + +#include