eaaf0c79b33f55c8ab91af8ce4925470fb10cc7e
[libcds.git] / tests / test-hdr / set / hdr_striped_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 #if CDS_COMPILER == CDS_COMPILER_MSVC && CDS_COMPILER_VERSION == CDS_COMPILER_MSVC12 && BOOST_VERSION <= 105500
8 namespace set {
9     void StripedSetHdrTest::Striped_boost_flat_set()
10     {
11         CPPUNIT_MESSAGE("Skipped; for Microsoft Visual C++ 2013 and boost::container::flat_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_flat_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::flat_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::Striped_boost_flat_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::striping<> >
43         >   set_cmp;
44         test_striped< set_cmp >();
45
46         CPPUNIT_MESSAGE( "less");
47         typedef cc::StripedSet< set_t
48             , co::hash< hash_int >
49             , co::less< less<item> >
50         >   set_less;
51         test_striped< set_less >();
52
53         CPPUNIT_MESSAGE( "cmpmix");
54         typedef cc::StripedSet< set_t
55             , co::hash< hash_int >
56             , co::compare< cmp<item> >
57             , co::less< less<item> >
58         >   set_cmpmix;
59         test_striped< set_cmpmix >();
60
61         // Spinlock as lock policy
62         CPPUNIT_MESSAGE( "spinlock");
63         typedef cc::StripedSet< set_t
64             , co::hash< hash_int >
65             , co::less< less<item> >
66             ,co::mutex_policy< cc::striped_set::striping< cds::lock::Spin > >
67         >   set_spin;
68         test_striped< set_spin >();
69
70         // Resizing policy
71         CPPUNIT_MESSAGE( "load_factor_resizing<0>(1024)");
72         {
73             typedef cc::StripedSet< set_t
74                 , co::hash< hash_int >
75                 , co::less< less<item> >
76                 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
77             >   set_less_resizing_lf;
78
79             set_less_resizing_lf s( 30, cc::striped_set::load_factor_resizing<0>( 1024 ) );
80             test_striped_with( s );
81         }
82
83         CPPUNIT_MESSAGE( "load_factor_resizing<256>");
84         typedef cc::StripedSet< set_t
85             , co::hash< hash_int >
86             , co::less< less<item> >
87             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
88         >   set_less_resizing_lf16;
89         test_striped< set_less_resizing_lf16 >();
90
91         CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(1024)");
92         {
93             typedef cc::StripedSet< set_t
94                 , co::hash< hash_int >
95                 , co::less< less<item> >
96                 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
97             >   set_less_resizing_sbt;
98
99             set_less_resizing_sbt s( 30, cc::striped_set::single_bucket_size_threshold<0>( 1024 ) );
100             test_striped_with( s );
101         }
102
103         CPPUNIT_MESSAGE( "single_bucket_size_threshold<256>");
104         typedef cc::StripedSet< set_t
105             , co::hash< hash_int >
106             , co::less< less<item> >
107             , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<256> >
108         >   set_less_resizing_sbt16;
109         test_striped< set_less_resizing_sbt16 >();
110
111         // Copy policy
112         CPPUNIT_MESSAGE( "load_factor_resizing<256>, copy_item");
113         typedef cc::StripedSet< set_t
114             , co::hash< hash_int >
115             , co::compare< cmp<item> >
116             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
117             , co::copy_policy< cc::striped_set::copy_item >
118         >   set_copy_item;
119         test_striped< set_copy_item >();
120
121         CPPUNIT_MESSAGE( "load_factor_resizing<256>, swap_item");
122         typedef cc::StripedSet< set_t
123             , co::hash< hash_int >
124             , co::compare< cmp<item> >
125             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
126             , co::copy_policy< cc::striped_set::swap_item >
127         >   set_swap_item;
128         test_striped< set_swap_item >();
129
130         CPPUNIT_MESSAGE( "load_factor_resizing<256>, move_item");
131         typedef cc::StripedSet< set_t
132             , co::hash< hash_int >
133             , co::compare< cmp<item> >
134             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
135             , co::copy_policy< cc::striped_set::move_item >
136         >   set_move_item;
137         test_striped< set_move_item >();
138
139         CPPUNIT_MESSAGE( "load_factor_resizing<256>, special copy_policy");
140         typedef cc::StripedSet< set_t
141             , co::hash< hash_int >
142             , co::compare< cmp<item> >
143             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
144             , co::copy_policy< my_copy_policy >
145         >   set_special_copy_item;
146         test_striped< set_special_copy_item >();
147
148     }
149
150 }   // namespace set
151
152 /*
153 #else
154     namespace set {
155         void StripedSetHdrTest::Striped_boost_flat_set()
156         {
157             CPPUNIT_MESSAGE( "Skipped; boost::container::flat_set is not compatible with MS VC++ 11" );
158         }
159     }
160 #endif
161 */
162
163 #else // BOOST_VERSION < 104800
164
165 namespace set {
166     void StripedSetHdrTest::Striped_boost_flat_set()
167     {
168         CPPUNIT_MESSAGE( "Skipped; for boost::container::flat_set you should use boost version 1.48 or above" );
169     }
170 }
171 #endif  // BOOST_VERSION