Skip to content

Commit e760874

Browse files
committed
Divide too big to maintain (flat_)tree into (flat_)map and (flat_)set tests.
1 parent 8c7e4a4 commit e760874

4 files changed

Lines changed: 234 additions & 135 deletions

File tree

test/flat_map_test.cpp

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//////////////////////////////////////////////////////////////////////////////
2+
//
3+
// (C) Copyright Ion Gaztanaga 2004-2026. Distributed under the Boost
4+
// Software License, Version 1.0. (See accompanying file
5+
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
// See http://www.boost.org/libs/interprocess for documentation.
8+
//
9+
//////////////////////////////////////////////////////////////////////////////
10+
11+
#include <map>
12+
#include <boost/interprocess/managed_shared_memory.hpp>
13+
#include <boost/container/flat_map.hpp>
14+
#include <boost/interprocess/allocators/allocator.hpp>
15+
#include "print_container.hpp"
16+
#include "movable_int.hpp"
17+
#include "map_test.hpp"
18+
#include "emplace_test.hpp"
19+
20+
/////////////////////////////////////////////////////////////////
21+
//
22+
// This example repeats the same operations with std::map and
23+
// shmem_map using the node allocator
24+
// and compares the values of both containers
25+
//
26+
/////////////////////////////////////////////////////////////////
27+
28+
using namespace boost::interprocess;
29+
30+
//Customize managed_shared_memory class
31+
typedef basic_managed_shared_memory
32+
<char,
33+
//simple_seq_fit<mutex_family>,
34+
rbtree_best_fit<mutex_family>,
35+
iset_index
36+
> my_managed_shared_memory;
37+
38+
//Alias allocator type
39+
typedef allocator<std::pair<int, int>, my_managed_shared_memory::segment_manager>
40+
shmem_pair_allocator_t;
41+
typedef allocator<std::pair<test::movable_int, test::movable_int>, my_managed_shared_memory::segment_manager>
42+
shmem_movable_pair_allocator_t;
43+
44+
typedef allocator<std::pair<test::movable_and_copyable_int, test::movable_and_copyable_int>, my_managed_shared_memory::segment_manager>
45+
shmem_move_copy_pair_allocator_t;
46+
47+
//Alias map types
48+
typedef std::map<int, int> MyStdMap;
49+
typedef std::multimap<int, int> MyStdMultiMap;
50+
51+
typedef boost::container::flat_map<int, int, std::less<int>, shmem_pair_allocator_t> MyShmMap;
52+
typedef boost::container::flat_multimap<int, int, std::less<int>, shmem_pair_allocator_t> MyShmMultiMap;
53+
54+
typedef boost::container::flat_map<test::movable_int, test::movable_int
55+
,std::less<test::movable_int>
56+
,shmem_movable_pair_allocator_t> MyMovableShmMap;
57+
typedef boost::container::flat_multimap<test::movable_int, test::movable_int
58+
,std::less<test::movable_int>
59+
,shmem_movable_pair_allocator_t> MyMovableShmMultiMap;
60+
61+
typedef boost::container::flat_map<test::movable_and_copyable_int, test::movable_and_copyable_int
62+
,std::less<test::movable_and_copyable_int>
63+
,shmem_move_copy_pair_allocator_t> MyMoveCopyShmMap;
64+
typedef boost::container::flat_multimap<test::movable_and_copyable_int, test::movable_and_copyable_int
65+
,std::less<test::movable_and_copyable_int>
66+
,shmem_move_copy_pair_allocator_t> MyMoveCopyShmMultiMap;
67+
68+
int main()
69+
{
70+
using namespace boost::interprocess::test;
71+
72+
if (0 != map_test<my_managed_shared_memory
73+
,MyShmMap
74+
,MyStdMap
75+
,MyShmMultiMap
76+
,MyStdMultiMap>()){
77+
std::cout << "Error in map_test<MyShmMap>" << std::endl;
78+
return 1;
79+
}
80+
81+
if (0 != map_test_copyable<my_managed_shared_memory
82+
,MyShmMap
83+
,MyStdMap
84+
,MyShmMultiMap
85+
,MyStdMultiMap>()){
86+
std::cout << "Error in map_test<MyShmMap>" << std::endl;
87+
return 1;
88+
}
89+
90+
// if (0 != map_test<my_managed_shared_memory
91+
// ,MyMovableShmMap
92+
// ,MyStdMap
93+
// ,MyMovableShmMultiMap
94+
// ,MyStdMultiMap>()){
95+
// return 1;
96+
// }
97+
98+
if (0 != map_test<my_managed_shared_memory
99+
,MyMoveCopyShmMap
100+
,MyStdMap
101+
,MyMoveCopyShmMultiMap
102+
,MyStdMultiMap>()){
103+
std::cout << "Error in map_test<MyMoveCopyShmMap>" << std::endl;
104+
return 1;
105+
}
106+
107+
//#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC_MINOR__ < 3)
108+
const test::EmplaceOptions MapOptions = (test::EmplaceOptions)(test::EMPLACE_HINT_PAIR | test::EMPLACE_ASSOC_PAIR);
109+
110+
if(!boost::interprocess::test::test_emplace<boost::container::flat_map<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
111+
return 1;
112+
if(!boost::interprocess::test::test_emplace<boost::container::flat_multimap<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
113+
return 1;
114+
//#endif //!defined(__GNUC__)
115+
return 0;
116+
117+
}
Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//////////////////////////////////////////////////////////////////////////////
22
//
3-
// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost
3+
// (C) Copyright Ion Gaztanaga 2004-2026. Distributed under the Boost
44
// Software License, Version 1.0. (See accompanying file
55
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
66
//
@@ -11,14 +11,10 @@
1111
#include <set>
1212
#include <boost/interprocess/managed_shared_memory.hpp>
1313
#include <boost/container/flat_set.hpp>
14-
#include <boost/container/flat_map.hpp>
1514
#include <boost/interprocess/allocators/allocator.hpp>
16-
#include <boost/interprocess/indexes/flat_map_index.hpp>
1715
#include "print_container.hpp"
18-
#include "dummy_test_allocator.hpp"
1916
#include "movable_int.hpp"
2017
#include "set_test.hpp"
21-
#include "map_test.hpp"
2218
#include "emplace_test.hpp"
2319

2420
/////////////////////////////////////////////////////////////////
@@ -44,41 +40,24 @@ typedef allocator<int, my_managed_shared_memory::segment_manager>
4440
shmem_allocator_t;
4541
typedef allocator<test::movable_int, my_managed_shared_memory::segment_manager>
4642
shmem_movable_allocator_t;
47-
typedef allocator<std::pair<int, int>, my_managed_shared_memory::segment_manager>
48-
shmem_pair_allocator_t;
49-
typedef allocator<std::pair<test::movable_int, test::movable_int>, my_managed_shared_memory::segment_manager>
50-
shmem_movable_pair_allocator_t;
5143

5244
typedef allocator<test::movable_and_copyable_int, my_managed_shared_memory::segment_manager>
5345
shmem_move_copy_allocator_t;
5446

5547
typedef allocator<test::copyable_int, my_managed_shared_memory::segment_manager>
5648
shmem_copy_allocator_t;
5749

58-
typedef allocator<std::pair<test::movable_and_copyable_int, test::movable_and_copyable_int>, my_managed_shared_memory::segment_manager>
59-
shmem_move_copy_pair_allocator_t;
60-
6150
//Alias set types
6251
typedef std::set<int> MyStdSet;
6352
typedef std::multiset<int> MyStdMultiSet;
64-
typedef std::map<int, int> MyStdMap;
65-
typedef std::multimap<int, int> MyStdMultiMap;
6653

6754
typedef boost::container::flat_set<int, std::less<int>, shmem_allocator_t> MyShmSet;
6855
typedef boost::container::flat_multiset<int, std::less<int>, shmem_allocator_t> MyShmMultiSet;
69-
typedef boost::container::flat_map<int, int, std::less<int>, shmem_pair_allocator_t> MyShmMap;
70-
typedef boost::container::flat_multimap<int, int, std::less<int>, shmem_pair_allocator_t> MyShmMultiMap;
7156

7257
typedef boost::container::flat_set<test::movable_int, std::less<test::movable_int>
7358
,shmem_movable_allocator_t> MyMovableShmSet;
7459
typedef boost::container::flat_multiset<test::movable_int,std::less<test::movable_int>
7560
,shmem_movable_allocator_t> MyMovableShmMultiSet;
76-
typedef boost::container::flat_map<test::movable_int, test::movable_int
77-
,std::less<test::movable_int>
78-
,shmem_movable_pair_allocator_t> MyMovableShmMap;
79-
typedef boost::container::flat_multimap<test::movable_int, test::movable_int
80-
,std::less<test::movable_int>
81-
,shmem_movable_pair_allocator_t> MyMovableShmMultiMap;
8261

8362
typedef boost::container::flat_set<test::movable_and_copyable_int, std::less<test::movable_and_copyable_int>
8463
,shmem_move_copy_allocator_t> MyMoveCopyShmSet;
@@ -90,13 +69,6 @@ typedef boost::container::flat_set<test::copyable_int, std::less<test::copyable_
9069
typedef boost::container::flat_multiset<test::copyable_int,std::less<test::copyable_int>
9170
,shmem_copy_allocator_t> MyCopyShmMultiSet;
9271

93-
typedef boost::container::flat_map<test::movable_and_copyable_int, test::movable_and_copyable_int
94-
,std::less<test::movable_and_copyable_int>
95-
,shmem_move_copy_pair_allocator_t> MyMoveCopyShmMap;
96-
typedef boost::container::flat_multimap<test::movable_and_copyable_int, test::movable_and_copyable_int
97-
,std::less<test::movable_and_copyable_int>
98-
,shmem_move_copy_pair_allocator_t> MyMoveCopyShmMultiMap;
99-
10072
int main()
10173
{
10274
using namespace boost::interprocess::test;
@@ -146,49 +118,9 @@ int main()
146118
return 1;
147119
}
148120

149-
if (0 != map_test<my_managed_shared_memory
150-
,MyShmMap
151-
,MyStdMap
152-
,MyShmMultiMap
153-
,MyStdMultiMap>()){
154-
std::cout << "Error in map_test<MyShmMap>" << std::endl;
155-
return 1;
156-
}
157-
158-
if (0 != map_test_copyable<my_managed_shared_memory
159-
,MyShmMap
160-
,MyStdMap
161-
,MyShmMultiMap
162-
,MyStdMultiMap>()){
163-
std::cout << "Error in map_test<MyShmMap>" << std::endl;
164-
return 1;
165-
}
166-
167-
// if (0 != map_test<my_managed_shared_memory
168-
// ,MyMovableShmMap
169-
// ,MyStdMap
170-
// ,MyMovableShmMultiMap
171-
// ,MyStdMultiMap>()){
172-
// return 1;
173-
// }
174-
175-
if (0 != map_test<my_managed_shared_memory
176-
,MyMoveCopyShmMap
177-
,MyStdMap
178-
,MyMoveCopyShmMultiMap
179-
,MyStdMultiMap>()){
180-
std::cout << "Error in map_test<MyMoveCopyShmMap>" << std::endl;
181-
return 1;
182-
}
183-
184121
//#if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC_MINOR__ < 3)
185122
const test::EmplaceOptions SetOptions = (test::EmplaceOptions)(test::EMPLACE_HINT | test::EMPLACE_ASSOC);
186-
const test::EmplaceOptions MapOptions = (test::EmplaceOptions)(test::EMPLACE_HINT_PAIR | test::EMPLACE_ASSOC_PAIR);
187123

188-
if(!boost::interprocess::test::test_emplace<boost::container::flat_map<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
189-
return 1;
190-
if(!boost::interprocess::test::test_emplace<boost::container::flat_multimap<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
191-
return 1;
192124
if(!boost::interprocess::test::test_emplace<boost::container::flat_set<test::EmplaceInt>, SetOptions>())
193125
return 1;
194126
if(!boost::interprocess::test::test_emplace<boost::container::flat_multiset<test::EmplaceInt>, SetOptions>())

test/map_test.cpp

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
//////////////////////////////////////////////////////////////////////////////
2+
//
3+
// (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost
4+
// Software License, Version 1.0. (See accompanying file
5+
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
// See http://www.boost.org/libs/interprocess for documentation.
8+
//
9+
//////////////////////////////////////////////////////////////////////////////
10+
#include <map>
11+
#include <boost/interprocess/managed_shared_memory.hpp>
12+
#include <boost/container/map.hpp>
13+
#include <boost/interprocess/allocators/allocator.hpp>
14+
#include <boost/interprocess/indexes/map_index.hpp>
15+
#include <boost/interprocess/indexes/iset_index.hpp>
16+
#include <boost/interprocess/mem_algo/simple_seq_fit.hpp>
17+
#include "print_container.hpp"
18+
#include "movable_int.hpp"
19+
#include "map_test.hpp"
20+
#include "emplace_test.hpp"
21+
22+
///////////////////////////////////////////////////////////////////
23+
// //
24+
// This example repeats the same operations with std::map and //
25+
// shmem_map using the node allocator //
26+
// and compares the values of both containers //
27+
// //
28+
///////////////////////////////////////////////////////////////////
29+
30+
using namespace boost::interprocess;
31+
32+
//Customize managed_shared_memory class
33+
typedef basic_managed_shared_memory
34+
<char,
35+
simple_seq_fit<mutex_family, offset_ptr<void> >,
36+
map_index
37+
> my_managed_shared_memory;
38+
39+
//We will work with narrow characters for shared memory objects
40+
//Alias an integer node allocator type
41+
typedef allocator<std::pair<const int, int>, my_managed_shared_memory::segment_manager>
42+
shmem_node_pair_allocator_t;
43+
typedef allocator<std::pair<const test::movable_int, test::movable_int>, my_managed_shared_memory::segment_manager>
44+
shmem_movable_node_pair_allocator_t;
45+
typedef allocator<std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int>, my_managed_shared_memory::segment_manager>
46+
shmem_move_copy_node_pair_allocator_t;
47+
48+
//Alias standard types
49+
typedef std::map<int, int> MyStdMap;
50+
typedef std::multimap<int, int> MyStdMultiMap;
51+
52+
//Alias non-movable types
53+
typedef boost::container::map<int, int, std::less<int>, shmem_node_pair_allocator_t> MyShmMap;
54+
typedef boost::container::multimap<int, int, std::less<int>, shmem_node_pair_allocator_t> MyShmMultiMap;
55+
56+
//Alias movable types
57+
typedef boost::container::map<test::movable_int, test::movable_int,
58+
std::less<test::movable_int>,
59+
shmem_movable_node_pair_allocator_t> MyMovableShmMap;
60+
typedef boost::container::multimap<test::movable_int, test::movable_int,
61+
std::less<test::movable_int>,
62+
shmem_movable_node_pair_allocator_t> MyMovableShmMultiMap;
63+
64+
typedef boost::container::map<test::movable_and_copyable_int
65+
,test::movable_and_copyable_int
66+
,std::less<test::movable_and_copyable_int>
67+
,shmem_move_copy_node_pair_allocator_t> MyMoveCopyShmMap;
68+
typedef boost::container::multimap<test::movable_and_copyable_int
69+
,test::movable_and_copyable_int
70+
,std::less<test::movable_and_copyable_int>
71+
,shmem_move_copy_node_pair_allocator_t> MyMoveCopyShmMultiMap;
72+
73+
int main ()
74+
{
75+
using namespace boost::interprocess::ipcdetail;
76+
77+
if (0 != test::map_test<my_managed_shared_memory
78+
,MyShmMap
79+
,MyStdMap
80+
,MyShmMultiMap
81+
,MyStdMultiMap>()){
82+
return 1;
83+
}
84+
85+
if(0 != test::map_test_copyable<my_managed_shared_memory
86+
,MyShmMap
87+
,MyStdMap
88+
,MyShmMultiMap
89+
,MyStdMultiMap>()){
90+
return 1;
91+
}
92+
93+
// if (0 != test::map_test<my_managed_shared_memory
94+
// ,MyMovableShmMap
95+
// ,MyStdMap
96+
// ,MyMovableShmMultiMap
97+
// ,MyStdMultiMap>()){
98+
// return 1;
99+
// }
100+
101+
if (0 != test::map_test<my_managed_shared_memory
102+
,MyMoveCopyShmMap
103+
,MyStdMap
104+
,MyMoveCopyShmMultiMap
105+
,MyStdMultiMap>()){
106+
return 1;
107+
}
108+
109+
const test::EmplaceOptions MapOptions = (test::EmplaceOptions)(test::EMPLACE_HINT_PAIR | test::EMPLACE_ASSOC_PAIR);
110+
if(!boost::interprocess::test::test_emplace<boost::container::map<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
111+
return 1;
112+
if(!boost::interprocess::test::test_emplace<boost::container::multimap<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
113+
return 1;
114+
115+
return 0;
116+
}

0 commit comments

Comments
 (0)