unordered_multiset_test.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2006-2015.
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/intrusive for documentation.
  10. //
  11. /////////////////////////////////////////////////////////////////////////////
  12. #include <boost/intrusive/unordered_set.hpp>
  13. #include <boost/intrusive/pointer_traits.hpp>
  14. #include <boost/intrusive/detail/iterator.hpp>
  15. #include "itestvalue.hpp"
  16. #include "smart_ptr.hpp"
  17. #include "common_functors.hpp"
  18. #include <vector>
  19. #include <algorithm> //std::sort
  20. #include <set>
  21. #include <boost/detail/lightweight_test.hpp>
  22. #include "test_macros.hpp"
  23. #include "test_container.hpp"
  24. #include "unordered_test_common.hpp"
  25. #include "unordered_test.hpp"
  26. using namespace boost::intrusive;
  27. template < class ValueTraits, bool ConstantTimeSize, bool CacheBegin, bool CompareHash, bool Incremental, bool Map, bool DefaultHolder >
  28. struct rebinder
  29. {
  30. typedef unordered_rebinder_common<ValueTraits, DefaultHolder, Map> common_t;
  31. typedef typename ValueContainer< typename ValueTraits::value_type >::type value_cont_type;
  32. template < class Option1 =void
  33. , class Option2 =void
  34. >
  35. struct container
  36. {
  37. typedef unordered_multiset
  38. < typename common_t::value_type
  39. , value_traits<ValueTraits>
  40. , constant_time_size<ConstantTimeSize>
  41. , cache_begin<CacheBegin>
  42. , compare_hash<CompareHash>
  43. , incremental<Incremental>
  44. , typename common_t::holder_opt
  45. , typename common_t::key_of_value_opt
  46. , Option1
  47. , Option2
  48. > type;
  49. BOOST_STATIC_ASSERT((key_type_tester<typename common_t::key_of_value_opt, type>::value));
  50. BOOST_STATIC_ASSERT((boost::intrusive::test::is_multikey_true<type>::value));
  51. };
  52. };
  53. enum HookType
  54. {
  55. Base,
  56. Member,
  57. NonMember
  58. };
  59. template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map, HookType Type>
  60. class test_main_template;
  61. template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map>
  62. class test_main_template<VoidPointer, ConstantTimeSize, DefaultHolder, Map, Base>
  63. {
  64. public:
  65. static void execute()
  66. {
  67. typedef testvalue<unordered_hooks<VoidPointer> > value_type;
  68. static const int random_init[6] = { 3, 2, 4, 1, 5, 2 };
  69. typedef typename ValueContainer< value_type >::type value_cont_type;
  70. value_cont_type data (6);
  71. for (int i = 0; i < 6; ++i)
  72. data[i].value_ = random_init[i];
  73. typedef testvalue_traits< unordered_hooks<VoidPointer> > testval_traits_t;
  74. //base
  75. typedef typename detail::if_c
  76. < ConstantTimeSize
  77. , typename testval_traits_t::base_value_traits
  78. , typename testval_traits_t::auto_base_value_traits //store_hash<true>
  79. >::type base_hook_t;
  80. test::test_unordered
  81. < //cache_begin, compare_hash, incremental
  82. rebinder<base_hook_t, ConstantTimeSize, ConstantTimeSize, !ConstantTimeSize, !!ConstantTimeSize, Map, DefaultHolder>
  83. >::test_all(data);
  84. }
  85. };
  86. template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map>
  87. class test_main_template<VoidPointer, ConstantTimeSize, DefaultHolder, Map, Member>
  88. {
  89. public:
  90. static void execute()
  91. {
  92. typedef testvalue<unordered_hooks<VoidPointer> > value_type;
  93. static const int random_init[6] = { 3, 2, 4, 1, 5, 2 };
  94. typedef typename ValueContainer< value_type >::type value_cont_type;
  95. value_cont_type data (6);
  96. for (int i = 0; i < 6; ++i)
  97. data[i].value_ = random_init[i];
  98. typedef testvalue_traits< unordered_hooks<VoidPointer> > testval_traits_t;
  99. //member
  100. typedef typename detail::if_c
  101. < ConstantTimeSize
  102. , typename testval_traits_t::member_value_traits //optimize_multikey<true>
  103. , typename testval_traits_t::auto_member_value_traits //store_hash<true>, optimize_multikey<true>
  104. >::type member_hook_t;
  105. test::test_unordered
  106. < //cache_begin, compare_hash, incremental
  107. rebinder<member_hook_t, ConstantTimeSize, false, !ConstantTimeSize, false, !ConstantTimeSize, DefaultHolder>
  108. >::test_all(data);
  109. }
  110. };
  111. template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map>
  112. class test_main_template<VoidPointer, ConstantTimeSize, DefaultHolder, Map, NonMember>
  113. {
  114. public:
  115. static void execute()
  116. {
  117. typedef testvalue<unordered_hooks<VoidPointer> > value_type;
  118. static const int random_init[6] = { 3, 2, 4, 1, 5, 2 };
  119. typedef typename ValueContainer< value_type >::type value_cont_type;
  120. value_cont_type data (6);
  121. for (int i = 0; i < 6; ++i)
  122. data[i].value_ = random_init[i];
  123. typedef testvalue_traits< unordered_hooks<VoidPointer> > testval_traits_t;
  124. //nonmember
  125. test::test_unordered
  126. < //cache_begin, compare_hash, incremental
  127. rebinder<typename testval_traits_t::nonhook_value_traits, ConstantTimeSize, false, false, false, Map, DefaultHolder>
  128. >::test_all(data);
  129. }
  130. };
  131. int main()
  132. {
  133. //VoidPointer x ConstantTimeSize x Map x DefaultHolder
  134. //void pointer
  135. test_main_template<void*, false, false, false, Base>::execute();
  136. test_main_template<void*, false, true, false, Member>::execute();
  137. test_main_template<void*, true, false, false, NonMember>::execute();
  138. test_main_template<void*, true, true, false, Base>::execute();
  139. //smart_ptr
  140. test_main_template<smart_ptr<void>, false, false, false, Member>::execute();
  141. test_main_template<smart_ptr<void>, false, true, false, NonMember>::execute();
  142. test_main_template<smart_ptr<void>, true, false, false, Base>::execute();
  143. test_main_template<smart_ptr<void>, true, true, false, Member>::execute();
  144. ////bounded_ptr (bool ConstantTimeSize, bool Map)
  145. //test_main_template_bptr< false, false >::execute();
  146. //test_main_template_bptr< false, true >::execute();
  147. //test_main_template_bptr< true, false >::execute();
  148. //test_main_template_bptr< true, true >::execute();
  149. return boost::report_errors();
  150. }