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