2007-11-18 10:44:56 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2013-07-28 22:10:37 +00:00
|
|
|
// (C) Copyright Ion Gaztanaga 2007-2013
|
2007-11-18 10:44:56 +00:00
|
|
|
//
|
|
|
|
// 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 <boost/intrusive/detail/config_begin.hpp>
|
|
|
|
#include <boost/intrusive/sg_set.hpp>
|
|
|
|
#include "itestvalue.hpp"
|
2014-05-20 16:42:56 -04:00
|
|
|
#include "bptr_value.hpp"
|
2007-11-18 10:44:56 +00:00
|
|
|
#include "smart_ptr.hpp"
|
|
|
|
#include "generic_set_test.hpp"
|
|
|
|
|
|
|
|
namespace boost { namespace intrusive { namespace test {
|
|
|
|
|
2008-10-11 13:18:02 +00:00
|
|
|
#if !defined (BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
2014-05-20 16:42:56 -04:00
|
|
|
template<class T, class O1, class O2, class O3, class O4, class O5>
|
2008-10-11 13:18:02 +00:00
|
|
|
#else
|
|
|
|
template<class T, class ...Options>
|
|
|
|
#endif
|
2012-05-20 09:54:48 +00:00
|
|
|
struct has_rebalance<boost::intrusive::sg_set<T,
|
2008-10-11 13:18:02 +00:00
|
|
|
#if !defined (BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
2014-05-20 16:42:56 -04:00
|
|
|
O1, O2, O3, O4, O5
|
2008-10-11 13:18:02 +00:00
|
|
|
#else
|
|
|
|
Options...
|
|
|
|
#endif
|
|
|
|
> >
|
2007-11-18 10:44:56 +00:00
|
|
|
{
|
|
|
|
static const bool value = true;
|
|
|
|
};
|
|
|
|
|
2009-10-14 13:08:04 +00:00
|
|
|
#if !defined (BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
2014-05-20 16:42:56 -04:00
|
|
|
template<class T, class O1, class O2, class O3, class O4, class O5>
|
2009-10-14 13:08:04 +00:00
|
|
|
#else
|
|
|
|
template<class T, class ...Options>
|
|
|
|
#endif
|
2012-05-20 09:54:48 +00:00
|
|
|
struct has_insert_before<boost::intrusive::sg_set<T,
|
2009-10-14 13:08:04 +00:00
|
|
|
#if !defined (BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
2014-05-20 16:42:56 -04:00
|
|
|
O1, O2, O3, O4, O5
|
2009-10-14 13:08:04 +00:00
|
|
|
#else
|
|
|
|
Options...
|
|
|
|
#endif
|
|
|
|
> >
|
|
|
|
{
|
|
|
|
static const bool value = true;
|
|
|
|
};
|
|
|
|
|
2007-11-18 10:44:56 +00:00
|
|
|
}}}
|
|
|
|
|
2008-12-13 13:49:31 +00:00
|
|
|
|
|
|
|
using namespace boost::intrusive;
|
|
|
|
|
|
|
|
struct my_tag;
|
|
|
|
|
|
|
|
template<class VoidPointer>
|
|
|
|
struct hooks
|
|
|
|
{
|
|
|
|
typedef bs_set_base_hook<void_pointer<VoidPointer> > base_hook_type;
|
|
|
|
typedef bs_set_member_hook<void_pointer<VoidPointer> > member_hook_type;
|
|
|
|
typedef member_hook_type auto_member_hook_type;
|
|
|
|
struct auto_base_hook_type
|
|
|
|
: bs_set_base_hook<void_pointer<VoidPointer>, tag<my_tag> >
|
|
|
|
{};
|
2014-04-28 20:08:24 -04:00
|
|
|
typedef nonhook_node_member< tree_node_traits < VoidPointer >,
|
|
|
|
sgtree_algorithms
|
|
|
|
> nonhook_node_member_type;
|
2008-12-13 13:49:31 +00:00
|
|
|
};
|
|
|
|
|
2007-11-18 10:44:56 +00:00
|
|
|
template< class ValueType
|
2013-07-28 22:10:37 +00:00
|
|
|
, class Option1 =void
|
|
|
|
, class Option2 =void
|
|
|
|
, class Option3 =void
|
2007-11-18 10:44:56 +00:00
|
|
|
>
|
|
|
|
struct GetContainer
|
|
|
|
{
|
|
|
|
typedef boost::intrusive::sg_set
|
|
|
|
< ValueType
|
|
|
|
, Option1
|
|
|
|
, Option2
|
|
|
|
, Option3
|
|
|
|
> type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template< class ValueType
|
2013-07-28 22:10:37 +00:00
|
|
|
, class Option1 =void
|
|
|
|
, class Option2 =void
|
|
|
|
, class Option3 =void
|
2007-11-18 10:44:56 +00:00
|
|
|
>
|
|
|
|
struct GetContainerFixedAlpha
|
|
|
|
{
|
|
|
|
typedef boost::intrusive::sg_set
|
|
|
|
< ValueType
|
|
|
|
, Option1
|
|
|
|
, Option2
|
|
|
|
, Option3
|
|
|
|
, boost::intrusive::floating_point<false>
|
|
|
|
> type;
|
|
|
|
};
|
|
|
|
|
2014-05-20 16:42:56 -04:00
|
|
|
// 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::sg_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< sgtree_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::sg_set
|
|
|
|
< ValueType
|
|
|
|
, Option1
|
|
|
|
, Option2
|
|
|
|
, Option3
|
|
|
|
, header_holder_type< pointer_holder< node > >
|
|
|
|
> type;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// container generator with void node allocator
|
|
|
|
template < bool Default_Holder >
|
|
|
|
struct GetContainerFixedAlpha_With_Holder
|
|
|
|
{
|
|
|
|
template< class ValueType
|
|
|
|
, class Option1 =void
|
|
|
|
, class Option2 =void
|
|
|
|
, class Option3 =void
|
|
|
|
>
|
|
|
|
struct GetContainerFixedAlpha
|
|
|
|
{
|
|
|
|
typedef boost::intrusive::sg_set
|
|
|
|
< ValueType
|
|
|
|
, Option1
|
|
|
|
, Option2
|
|
|
|
, Option3
|
|
|
|
> type;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// container generator with standard (non-void) node allocator
|
|
|
|
template <>
|
|
|
|
struct GetContainerFixedAlpha_With_Holder< false >
|
|
|
|
{
|
|
|
|
template< class ValueType
|
|
|
|
, class Option1 =void
|
|
|
|
, class Option2 =void
|
|
|
|
, class Option3 =void
|
|
|
|
>
|
|
|
|
struct GetContainerFixedAlpha
|
|
|
|
{
|
|
|
|
// extract node type through options->value_traits->node_traits->node
|
|
|
|
typedef typename pack_options< sgtree_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::sg_set
|
|
|
|
< ValueType
|
|
|
|
, Option1
|
|
|
|
, Option2
|
|
|
|
, Option3
|
|
|
|
, boost::intrusive::floating_point<false>
|
|
|
|
, header_holder_type< pointer_holder< node > >
|
|
|
|
> type;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class VoidPointer, bool Default_Holder>
|
2007-11-18 10:44:56 +00:00
|
|
|
class test_main_template
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int operator()()
|
|
|
|
{
|
|
|
|
using namespace boost::intrusive;
|
2008-12-13 13:49:31 +00:00
|
|
|
typedef testvalue<hooks<VoidPointer> , true> value_type;
|
2007-11-18 10:44:56 +00:00
|
|
|
|
|
|
|
test::test_generic_set < typename detail::get_base_value_traits
|
|
|
|
< value_type
|
2008-12-13 13:49:31 +00:00
|
|
|
, typename hooks<VoidPointer>::base_hook_type
|
2007-11-18 10:44:56 +00:00
|
|
|
>::type
|
2014-05-20 16:42:56 -04:00
|
|
|
, GetContainer_With_Holder< Default_Holder >::template GetContainer
|
2007-11-18 10:44:56 +00:00
|
|
|
>::test_all();
|
|
|
|
test::test_generic_set < typename detail::get_member_value_traits
|
|
|
|
< value_type
|
|
|
|
, member_hook< value_type
|
2008-12-13 13:49:31 +00:00
|
|
|
, typename hooks<VoidPointer>::member_hook_type
|
|
|
|
, &value_type::node_
|
2007-11-18 10:44:56 +00:00
|
|
|
>
|
|
|
|
>::type
|
2014-05-20 16:42:56 -04:00
|
|
|
, GetContainer_With_Holder< Default_Holder >::template GetContainer
|
2007-11-18 10:44:56 +00:00
|
|
|
>::test_all();
|
|
|
|
|
|
|
|
test::test_generic_set < typename detail::get_base_value_traits
|
|
|
|
< value_type
|
2008-12-13 13:49:31 +00:00
|
|
|
, typename hooks<VoidPointer>::base_hook_type
|
2007-11-18 10:44:56 +00:00
|
|
|
>::type
|
2014-05-20 16:42:56 -04:00
|
|
|
, GetContainerFixedAlpha_With_Holder< Default_Holder >::template GetContainerFixedAlpha
|
2007-11-18 10:44:56 +00:00
|
|
|
>::test_all();
|
|
|
|
test::test_generic_set < typename detail::get_member_value_traits
|
|
|
|
< value_type
|
|
|
|
, member_hook< value_type
|
2008-12-13 13:49:31 +00:00
|
|
|
, typename hooks<VoidPointer>::member_hook_type
|
|
|
|
, &value_type::node_
|
2007-11-18 10:44:56 +00:00
|
|
|
>
|
|
|
|
>::type
|
2014-05-20 16:42:56 -04:00
|
|
|
, GetContainerFixedAlpha_With_Holder< Default_Holder >::template GetContainerFixedAlpha
|
2007-11-18 10:44:56 +00:00
|
|
|
>::test_all();
|
2014-04-28 20:08:24 -04:00
|
|
|
test::test_generic_set < nonhook_node_member_value_traits< value_type,
|
|
|
|
typename hooks<VoidPointer>::nonhook_node_member_type,
|
|
|
|
&value_type::nhn_member_,
|
|
|
|
safe_link
|
|
|
|
>,
|
2014-05-20 16:42:56 -04:00
|
|
|
GetContainerFixedAlpha_With_Holder< Default_Holder >::template GetContainerFixedAlpha
|
2014-04-28 20:08:24 -04:00
|
|
|
>::test_all();
|
2007-11-18 10:44:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-05-20 16:42:56 -04:00
|
|
|
// container generator which ignores further parametrization, except for compare option
|
2014-06-12 11:49:42 +02:00
|
|
|
template < typename Value_Traits, bool ConstantTimeSize, typename HeaderHolder >
|
2014-05-20 16:42:56 -04:00
|
|
|
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< sgtree_defaults, Option1, Option2, Option3 >::type packed_options;
|
|
|
|
typedef typename packed_options::compare compare_option;
|
|
|
|
|
|
|
|
typedef boost::intrusive::sg_set< typename Value_Traits::value_type,
|
|
|
|
value_traits< Value_Traits >,
|
2014-06-12 11:49:42 +02:00
|
|
|
constant_time_size< ConstantTimeSize >,
|
2014-05-20 16:42:56 -04:00
|
|
|
compare< compare_option >,
|
2014-06-12 11:49:42 +02:00
|
|
|
header_holder_type< HeaderHolder >
|
2014-05-20 16:42:56 -04:00
|
|
|
> type;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct test_main_template_bptr
|
|
|
|
{
|
|
|
|
void operator () ()
|
|
|
|
{
|
|
|
|
typedef BPtr_Value value_type;
|
|
|
|
typedef BPtr_Value_Traits< Tree_BPtr_Node_Traits > value_traits;
|
2014-06-12 11:49:42 +02:00
|
|
|
typedef bounded_allocator< value_type > allocator_type;
|
2014-05-20 16:42:56 -04:00
|
|
|
|
|
|
|
allocator_type::init();
|
|
|
|
test::test_generic_set< value_traits,
|
2014-10-10 18:22:14 +02:00
|
|
|
Get_Preset_Container< value_traits, true,
|
|
|
|
bounded_pointer_holder< value_type > >::GetContainer
|
2014-05-20 16:42:56 -04:00
|
|
|
>::test_all();
|
|
|
|
assert(allocator_type::is_clear());
|
|
|
|
allocator_type::destroy();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-12 11:49:42 +02:00
|
|
|
int main()
|
2007-11-18 10:44:56 +00:00
|
|
|
{
|
2014-05-20 16:42:56 -04:00
|
|
|
// test (plain/smart pointers) x (const size) x (void node allocator)
|
|
|
|
test_main_template<void*, true>()();
|
|
|
|
test_main_template<boost::intrusive::smart_ptr<void>, true >()();
|
|
|
|
// test (plain pointers) x (const size) x (standard node allocator)
|
|
|
|
test_main_template<void*, false>()();
|
|
|
|
// test (bounded pointers) x (nonconst/const size) x (special node allocator)
|
2014-10-10 18:22:14 +02:00
|
|
|
test_main_template_bptr()();
|
2014-05-20 16:42:56 -04:00
|
|
|
|
2007-11-18 10:44:56 +00:00
|
|
|
return boost::report_errors();
|
|
|
|
}
|
|
|
|
#include <boost/intrusive/detail/config_end.hpp>
|