forked from boostorg/intrusive
- Implemented map and multimap-like interfaces.
- Refactored hashtable containers to reduce template instantiations.
This commit is contained in:
+90
-206
@@ -1,7 +1,7 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Olaf Krzikalla 2004-2006.
|
||||
// (C) Copyright Ion Gaztanaga 2006-2013.
|
||||
// (C) Copyright Ion Gaztanaga 2006-2015.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -14,232 +14,116 @@
|
||||
#include "itestvalue.hpp"
|
||||
#include "bptr_value.hpp"
|
||||
#include "smart_ptr.hpp"
|
||||
#include "rb_test_common.hpp"
|
||||
#include "generic_set_test.hpp"
|
||||
|
||||
namespace boost { namespace intrusive { namespace test {
|
||||
|
||||
#if !defined (BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
||||
template<class T, class O1, class O2, class O3, class O4, class O5>
|
||||
#else
|
||||
template<class T, class ...Options>
|
||||
#endif
|
||||
struct has_insert_before<boost::intrusive::set<T,
|
||||
#if !defined (BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
||||
O1, O2, O3, O4, O5
|
||||
#else
|
||||
Options...
|
||||
#endif
|
||||
> >
|
||||
{
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
struct my_tag;
|
||||
|
||||
using namespace boost::intrusive;
|
||||
|
||||
template<class VoidPointer>
|
||||
struct hooks
|
||||
template < class ValueTraits, bool ConstantTimeSize, bool DefaultHolder, bool Map >
|
||||
struct rebinder
|
||||
{
|
||||
typedef set_base_hook
|
||||
<void_pointer<VoidPointer> > base_hook_type;
|
||||
typedef set_base_hook
|
||||
<link_mode<auto_unlink>
|
||||
, void_pointer<VoidPointer>
|
||||
, tag<my_tag>
|
||||
, optimize_size<true> > auto_base_hook_type;
|
||||
typedef set_member_hook<void_pointer
|
||||
<VoidPointer>, optimize_size<true> > member_hook_type;
|
||||
typedef set_member_hook
|
||||
<link_mode<auto_unlink>, void_pointer<VoidPointer> > auto_member_hook_type;
|
||||
typedef nonhook_node_member< rbtree_node_traits <VoidPointer, false >,
|
||||
rbtree_algorithms
|
||||
> nonhook_node_member_type;
|
||||
typedef tree_rebinder_common<ValueTraits, DefaultHolder, Map> common_t;
|
||||
|
||||
template < class Option1 =void
|
||||
, class Option2 =void
|
||||
>
|
||||
struct container
|
||||
{
|
||||
typedef set
|
||||
< typename common_t::value_type
|
||||
, value_traits<ValueTraits>
|
||||
, constant_time_size<ConstantTimeSize>
|
||||
, typename common_t::holder_opt
|
||||
, typename common_t::key_of_value_opt
|
||||
, Option1
|
||||
, Option2
|
||||
> type;
|
||||
BOOST_STATIC_ASSERT((key_type_tester<typename common_t::key_of_value_opt, type>::value));
|
||||
};
|
||||
};
|
||||
|
||||
// container generator with void node allocator
|
||||
template < bool Default_Holder >
|
||||
struct GetContainer_With_Holder
|
||||
{
|
||||
template< class ValueType
|
||||
, class Option1 =void
|
||||
, class Option2 =void
|
||||
, class Option3 =void
|
||||
>
|
||||
struct GetContainer
|
||||
{
|
||||
typedef boost::intrusive::set
|
||||
< ValueType
|
||||
, Option1
|
||||
, Option2
|
||||
, Option3
|
||||
> type;
|
||||
};
|
||||
};
|
||||
|
||||
// container generator with standard (non-void) node allocator
|
||||
template <>
|
||||
struct GetContainer_With_Holder< false >
|
||||
{
|
||||
template< class ValueType
|
||||
, class Option1 =void
|
||||
, class Option2 =void
|
||||
, class Option3 =void
|
||||
>
|
||||
struct GetContainer
|
||||
{
|
||||
// extract node type through options->value_traits->node_traits->node
|
||||
typedef typename pack_options< rbtree_defaults, Option1, Option2, Option3 >::type packed_options;
|
||||
typedef typename detail::get_value_traits< ValueType, typename packed_options::proto_value_traits>::type value_traits;
|
||||
typedef typename value_traits::node_traits::node node;
|
||||
|
||||
typedef boost::intrusive::set
|
||||
< ValueType
|
||||
, Option1
|
||||
, Option2
|
||||
, Option3
|
||||
, header_holder_type< pointer_holder< node > >
|
||||
> type;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template<class VoidPointer, bool constant_time_size, bool Default_Holder>
|
||||
template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map>
|
||||
class test_main_template
|
||||
{
|
||||
public:
|
||||
int operator()()
|
||||
static void execute()
|
||||
{
|
||||
using namespace boost::intrusive;
|
||||
typedef testvalue<hooks<VoidPointer> , constant_time_size> value_type;
|
||||
|
||||
test::test_generic_set < typename detail::get_base_value_traits
|
||||
< value_type
|
||||
, typename hooks<VoidPointer>::base_hook_type
|
||||
>::type
|
||||
, GetContainer_With_Holder< Default_Holder >::template GetContainer
|
||||
>::test_all();
|
||||
test::test_generic_set < typename detail::get_member_value_traits
|
||||
< member_hook< value_type
|
||||
, typename hooks<VoidPointer>::member_hook_type
|
||||
, &value_type::node_
|
||||
>
|
||||
>::type
|
||||
, GetContainer_With_Holder< Default_Holder >::template GetContainer
|
||||
>::test_all();
|
||||
test::test_generic_set < nonhook_node_member_value_traits< value_type,
|
||||
typename hooks<VoidPointer>::nonhook_node_member_type,
|
||||
&value_type::nhn_member_,
|
||||
safe_link
|
||||
>,
|
||||
GetContainer_With_Holder< Default_Holder >::template GetContainer
|
||||
>::test_all();
|
||||
return 0;
|
||||
typedef testvalue_traits< rb_hooks<VoidPointer> > testval_traits_t;
|
||||
//base
|
||||
typedef typename detail::if_c
|
||||
< ConstantTimeSize
|
||||
, typename testval_traits_t::base_value_traits
|
||||
, typename testval_traits_t::auto_base_value_traits
|
||||
>::type base_hook_t;
|
||||
test::test_generic_set
|
||||
< base_hook_t
|
||||
, rebinder<base_hook_t, ConstantTimeSize, DefaultHolder, Map>
|
||||
>::test_all();
|
||||
//member
|
||||
typedef typename detail::if_c
|
||||
< ConstantTimeSize
|
||||
, typename testval_traits_t::member_value_traits
|
||||
, typename testval_traits_t::auto_member_value_traits
|
||||
>::type member_hook_t;
|
||||
test::test_generic_set
|
||||
< member_hook_t
|
||||
, rebinder<member_hook_t, ConstantTimeSize, DefaultHolder, Map>
|
||||
>::test_all();
|
||||
//nonmember
|
||||
test::test_generic_set
|
||||
< typename testval_traits_t::nonhook_value_traits
|
||||
, rebinder<typename testval_traits_t::nonhook_value_traits, ConstantTimeSize, DefaultHolder, Map>
|
||||
>::test_all();
|
||||
}
|
||||
};
|
||||
|
||||
template<class VoidPointer, bool Default_Holder>
|
||||
class test_main_template<VoidPointer, false, Default_Holder>
|
||||
{
|
||||
public:
|
||||
int operator()()
|
||||
{
|
||||
using namespace boost::intrusive;
|
||||
typedef testvalue<hooks<VoidPointer> , false> value_type;
|
||||
|
||||
test::test_generic_set < typename detail::get_base_value_traits
|
||||
< value_type
|
||||
, typename hooks<VoidPointer>::base_hook_type
|
||||
>::type
|
||||
, GetContainer_With_Holder< Default_Holder >::template GetContainer
|
||||
>::test_all();
|
||||
|
||||
test::test_generic_set < typename detail::get_member_value_traits
|
||||
< member_hook< value_type
|
||||
, typename hooks<VoidPointer>::member_hook_type
|
||||
, &value_type::node_
|
||||
>
|
||||
>::type
|
||||
, GetContainer_With_Holder< Default_Holder >::template GetContainer
|
||||
>::test_all();
|
||||
|
||||
test::test_generic_set < typename detail::get_base_value_traits
|
||||
< value_type
|
||||
, typename hooks<VoidPointer>::auto_base_hook_type
|
||||
>::type
|
||||
, GetContainer_With_Holder< Default_Holder >::template GetContainer
|
||||
>::test_all();
|
||||
|
||||
test::test_generic_set < typename detail::get_member_value_traits
|
||||
< member_hook< value_type
|
||||
, typename hooks<VoidPointer>::auto_member_hook_type
|
||||
, &value_type::auto_node_
|
||||
>
|
||||
>::type
|
||||
, GetContainer_With_Holder< Default_Holder >::template GetContainer
|
||||
>::test_all();
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
// container generator which ignores further parametrization, except for compare option
|
||||
template < typename Value_Traits, bool ConstantTimeSize, typename HeaderHolder >
|
||||
struct Get_Preset_Container
|
||||
{
|
||||
template < class
|
||||
, class Option1 = void
|
||||
, class Option2 = void
|
||||
, class Option3 = void
|
||||
>
|
||||
struct GetContainer
|
||||
{
|
||||
// ignore further paramatrization except for the compare option
|
||||
// notably ignore the size option (use preset)
|
||||
typedef typename pack_options< rbtree_defaults, Option1, Option2, Option3 >::type packed_options;
|
||||
typedef typename packed_options::compare compare_option;
|
||||
|
||||
typedef boost::intrusive::set< typename Value_Traits::value_type,
|
||||
value_traits< Value_Traits >,
|
||||
constant_time_size< ConstantTimeSize >,
|
||||
compare< compare_option >,
|
||||
header_holder_type< HeaderHolder >
|
||||
> type;
|
||||
};
|
||||
};
|
||||
|
||||
template < bool ConstantTimeSize >
|
||||
template < bool ConstantTimeSize, bool Map >
|
||||
struct test_main_template_bptr
|
||||
{
|
||||
void operator () ()
|
||||
{
|
||||
typedef BPtr_Value value_type;
|
||||
typedef BPtr_Value_Traits< RBTree_BPtr_Node_Traits > value_traits;
|
||||
typedef bounded_allocator< value_type > allocator_type;
|
||||
static void execute()
|
||||
{
|
||||
typedef BPtr_Value_Traits< RBTree_BPtr_Node_Traits > value_traits;
|
||||
typedef bounded_allocator< BPtr_Value > allocator_type;
|
||||
|
||||
allocator_type::init();
|
||||
test::test_generic_set< value_traits,
|
||||
Get_Preset_Container< value_traits, ConstantTimeSize,
|
||||
bounded_pointer_holder< value_type >
|
||||
>::template GetContainer
|
||||
>::test_all();
|
||||
assert(allocator_type::is_clear());
|
||||
allocator_type::destroy();
|
||||
}
|
||||
bounded_allocator_scope<allocator_type> bounded_scope; (void)bounded_scope;
|
||||
test::test_generic_set
|
||||
< value_traits
|
||||
, rebinder< value_traits, ConstantTimeSize, true, Map>
|
||||
>::test_all();
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
// test (plain/smart pointers) x (nonconst/const size) x (void node allocator)
|
||||
test_main_template<void*, false, true>()();
|
||||
test_main_template<boost::intrusive::smart_ptr<void>, false, true>()();
|
||||
test_main_template<void*, true, true>()();
|
||||
test_main_template<boost::intrusive::smart_ptr<void>, true, true>()();
|
||||
// test (bounded pointers) x (nonconst/const size) x (special node allocator)
|
||||
test_main_template_bptr< true >()();
|
||||
test_main_template_bptr< false >()();
|
||||
//Combinations: VoidPointer x ConstantTimeSize x DefaultHolder x Map
|
||||
//Minimize them selecting different combinations for raw and smart pointers
|
||||
//Start with ('false', 'false', 'false') in sets and 'false', 'false', 'true' in multisets
|
||||
|
||||
//void pointer
|
||||
test_main_template<void*, false, false, false>::execute();
|
||||
//test_main_template<void*, false, false, true>::execute();
|
||||
test_main_template<void*, false, true, false>::execute();
|
||||
//test_main_template<void*, false, true, true>::execute();
|
||||
test_main_template<void*, true, false, false>::execute();
|
||||
//test_main_template<void*, true, false, true>::execute();
|
||||
test_main_template<void*, true, true, false>::execute();
|
||||
//test_main_template<void*, true, true, true>::execute();
|
||||
|
||||
//smart_ptr
|
||||
//test_main_template<smart_ptr<void>, false, false, false>::execute();
|
||||
test_main_template<smart_ptr<void>, false, false, true>::execute();
|
||||
//test_main_template<smart_ptr<void>, false, true, false>::execute();
|
||||
test_main_template<smart_ptr<void>, false, true, true>::execute();
|
||||
//test_main_template<smart_ptr<void>, true, false, false>::execute();
|
||||
test_main_template<smart_ptr<void>, true, false, true>::execute();
|
||||
//test_main_template<smart_ptr<void>, true, true, false>::execute();
|
||||
test_main_template<smart_ptr<void>, true, true, true>::execute();
|
||||
|
||||
//bounded_ptr (bool ConstantTimeSize, bool Map)
|
||||
test_main_template_bptr< false, false >::execute();
|
||||
//test_main_template_bptr< false, true >::execute();
|
||||
//test_main_template_bptr< true, false >::execute();
|
||||
test_main_template_bptr< true, true >::execute();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user