Move libcds 1.6.0 from SVN
[libcds.git] / tests / test-hdr / set / hdr_striped_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::Striped_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::Striped_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::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             ,co::mutex_policy< cc::striped_set::striping<> >
51         >   set_less;
52         test_striped< set_less >();
53
54         CPPUNIT_MESSAGE( "cmpmix");
55         typedef cc::StripedSet< set_t
56             , co::hash< hash_int >
57             , co::compare< cmp<item> >
58             , co::less< less<item> >
59             ,co::mutex_policy< cc::striped_set::striping<> >
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::hash< hash_int >
67             , co::less< less<item> >
68             ,co::mutex_policy< cc::striped_set::striping< cds::lock::Spin > >
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::hash< hash_int >
77                 , co::less< less<item> >
78                 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
79             >   set_less_resizing_lf;
80             set_less_resizing_lf s(30, cc::striped_set::load_factor_resizing<0>( 1024 ));
81             test_striped_with( s );
82         }
83
84         CPPUNIT_MESSAGE( "load_factor_resizing<256>");
85         typedef cc::StripedSet< set_t
86             , co::hash< hash_int >
87             , co::less< less<item> >
88             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
89         >   set_less_resizing_lf16;
90         test_striped< set_less_resizing_lf16 >();
91
92         CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(1024");
93         {
94             typedef cc::StripedSet< set_t
95                 , co::hash< hash_int >
96                 , co::less< less<item> >
97                 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
98             >   set_less_resizing_sbt;
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_item");
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 }   // namespace set
150
151 #else // BOOST_VERSION < 104800
152
153 namespace set {
154     void StripedSetHdrTest::Striped_boost_set()
155     {
156         CPPUNIT_MESSAGE( "Skipped; for boost::container::set you should use boost version 1.48 or above" );
157     }
158 }
159 #endif  // BOOST_VERSION