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