Move libcds 1.6.0 from SVN
[libcds.git] / tests / test-hdr / set / hdr_refinable_hashset_boost_set.cpp
1 //$$CDS-header$$
2
3 #include "set/hdr_striped_set.h"
4
5 #include <boost/version.hpp>
6 #include <cds/details/defs.h>
7 #if CDS_COMPILER == CDS_COMPILER_MSVC && CDS_COMPILER_VERSION == CDS_COMPILER_MSVC12 && BOOST_VERSION <= 105500
8 namespace set {
9     void StripedSetHdrTest::Refinable_boost_set()
10     {
11         CPPUNIT_MESSAGE("Skipped; for Microsoft Visual C++ 2013 and boost::container::set you should use boost version 1.56 or above");
12     }
13 }
14
15 #elif BOOST_VERSION >= 104800
16
17 #include <cds/container/striped_set/boost_set.h>
18 #include <cds/container/striped_set.h>
19 #include <cds/lock/spinlock.h>
20
21 namespace set {
22
23     namespace {
24         typedef boost::container::set< StripedSetHdrTest::item, StripedSetHdrTest::less<StripedSetHdrTest::item> > set_t;
25
26         struct my_copy_policy {
27             typedef set_t::iterator iterator;
28
29             void operator()( set_t& set, iterator itWhat )
30             {
31                 set.insert( *itWhat );
32             }
33         };
34     }
35
36     void StripedSetHdrTest::Refinable_boost_set()
37     {
38         CPPUNIT_MESSAGE( "cmp");
39         typedef cc::StripedSet< set_t
40             , co::hash< hash_int >
41             , co::compare< cmp<item> >
42             ,co::mutex_policy< cc::striped_set::refinable<> >
43         >   set_cmp;
44         test_striped< set_cmp >();
45
46         CPPUNIT_MESSAGE( "less");
47         typedef cc::StripedSet< set_t
48             ,co::mutex_policy< cc::striped_set::refinable<> >
49             , co::hash< hash_int >
50             , co::less< less<item> >
51         >   set_less;
52         test_striped< set_less >();
53
54         CPPUNIT_MESSAGE( "cmpmix");
55         typedef cc::StripedSet< set_t
56             ,co::mutex_policy< cc::striped_set::refinable<> >
57             , co::hash< hash_int >
58             , co::compare< cmp<item> >
59             , co::less< less<item> >
60         >   set_cmpmix;
61         test_striped< set_cmpmix >();
62
63         // Spinlock as lock policy
64         CPPUNIT_MESSAGE( "spinlock");
65         typedef cc::StripedSet< set_t
66             ,co::mutex_policy< cc::striped_set::refinable<cds::lock::ReentrantSpin> >
67             , co::hash< hash_int >
68             , co::less< less<item> >
69         >   set_spin;
70         test_striped< set_spin >();
71
72         // Resizing policy
73         CPPUNIT_MESSAGE( "load_factor_resizing<0>(1024)");
74         {
75             typedef cc::StripedSet< set_t
76                 ,co::mutex_policy< cc::striped_set::refinable<> >
77                 , co::hash< hash_int >
78                 , co::less< less<item> >
79                 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
80             >   set_less_resizing_lf;
81             set_less_resizing_lf s(30, cc::striped_set::load_factor_resizing<0>(1024));
82             test_striped_with(s);
83         }
84
85         CPPUNIT_MESSAGE( "load_factor_resizing<256>");
86         typedef cc::StripedSet< set_t
87             ,co::mutex_policy< cc::striped_set::refinable<> >
88             , co::hash< hash_int >
89             , co::less< less<item> >
90             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
91         >   set_less_resizing_lf16;
92         test_striped< set_less_resizing_lf16 >();
93
94         CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(1024)");
95         {
96             typedef cc::StripedSet< set_t
97                 ,co::mutex_policy< cc::striped_set::refinable<> >
98                 , co::hash< hash_int >
99                 , co::less< less<item> >
100                 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
101             >   set_less_resizing_sbt;
102             set_less_resizing_sbt s(30, cc::striped_set::single_bucket_size_threshold<0>(1024) );
103             test_striped_with(s);
104         }
105
106         CPPUNIT_MESSAGE( "single_bucket_size_threshold<256>");
107         typedef cc::StripedSet< set_t
108             ,co::mutex_policy< cc::striped_set::refinable<> >
109             , co::hash< hash_int >
110             , co::less< less<item> >
111             , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<256> >
112         >   set_less_resizing_sbt16;
113         test_striped< set_less_resizing_sbt16 >();
114
115         // Copy policy
116         CPPUNIT_MESSAGE( "load_factor_resizing<256>, copy_item");
117         typedef cc::StripedSet< set_t
118             ,co::mutex_policy< cc::striped_set::refinable<> >
119             , co::hash< hash_int >
120             , co::compare< cmp<item> >
121             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
122             , co::copy_policy< cc::striped_set::copy_item >
123         >   set_copy_item;
124         test_striped< set_copy_item >();
125
126         CPPUNIT_MESSAGE( "load_factor_resizing<256>, swap_item");
127         typedef cc::StripedSet< set_t
128             ,co::mutex_policy< cc::striped_set::refinable<> >
129             , co::hash< hash_int >
130             , co::compare< cmp<item> >
131             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
132             , co::copy_policy< cc::striped_set::swap_item >
133         >   set_swap_item;
134         test_striped< set_swap_item >();
135
136         CPPUNIT_MESSAGE( "load_factor_resizing<256>, move_item");
137         typedef cc::StripedSet< set_t
138             ,co::mutex_policy< cc::striped_set::refinable<> >
139             , co::hash< hash_int >
140             , co::compare< cmp<item> >
141             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
142             , co::copy_policy< cc::striped_set::move_item >
143         >   set_move_item;
144         test_striped< set_move_item >();
145
146         CPPUNIT_MESSAGE( "load_factor_resizing<256>, special copy_item");
147         typedef cc::StripedSet< set_t
148             ,co::mutex_policy< cc::striped_set::refinable<> >
149             , co::hash< hash_int >
150             , co::compare< cmp<item> >
151             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
152             , co::copy_policy< my_copy_policy >
153         >   set_special_copy_item;
154         test_striped< set_special_copy_item >();
155     }
156
157 }   // namespace set
158
159 #else // BOOST_VERSION < 104800
160
161 namespace set {
162     void StripedSetHdrTest::Refinable_boost_set()
163     {
164         CPPUNIT_MESSAGE( "Skipped; for boost::container::set you should use boost version 1.48 or above" );
165     }
166 }
167 #endif  // BOOST_VERSION