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