Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/interprocess/detail/named_proxy.hpp @ 101:c530137014c0
Update Boost headers (1.58.0)
author | Chris Cannam |
---|---|
date | Mon, 07 Sep 2015 11:12:49 +0100 |
parents | 2665513ce2d3 |
children |
comparison
equal
deleted
inserted
replaced
100:793467b5e61c | 101:c530137014c0 |
---|---|
9 ////////////////////////////////////////////////////////////////////////////// | 9 ////////////////////////////////////////////////////////////////////////////// |
10 | 10 |
11 #ifndef BOOST_INTERPROCESS_NAMED_PROXY_HPP | 11 #ifndef BOOST_INTERPROCESS_NAMED_PROXY_HPP |
12 #define BOOST_INTERPROCESS_NAMED_PROXY_HPP | 12 #define BOOST_INTERPROCESS_NAMED_PROXY_HPP |
13 | 13 |
14 #if (defined _MSC_VER) && (_MSC_VER >= 1200) | 14 #ifndef BOOST_CONFIG_HPP |
15 # include <boost/config.hpp> | |
16 #endif | |
17 # | |
18 #if defined(BOOST_HAS_PRAGMA_ONCE) | |
15 # pragma once | 19 # pragma once |
16 #endif | 20 #endif |
17 | 21 |
18 #include <boost/interprocess/detail/config_begin.hpp> | 22 #include <boost/interprocess/detail/config_begin.hpp> |
19 #include <boost/interprocess/detail/workaround.hpp> | 23 #include <boost/interprocess/detail/workaround.hpp> |
20 | 24 |
21 #include <new> | 25 // interprocess/detail |
22 #include <iterator> | |
23 #include <boost/interprocess/detail/in_place_interface.hpp> | 26 #include <boost/interprocess/detail/in_place_interface.hpp> |
24 #include <boost/interprocess/detail/mpl.hpp> | 27 #include <boost/interprocess/detail/mpl.hpp> |
25 | 28 #include <boost/move/utility_core.hpp> |
26 #ifndef BOOST_INTERPROCESS_PERFECT_FORWARDING | 29 #ifndef BOOST_INTERPROCESS_PERFECT_FORWARDING |
27 #include <boost/interprocess/detail/preprocessor.hpp> | 30 #include <boost/move/detail/fwd_macros.hpp> |
28 #else | 31 #else |
29 #include <boost/move/move.hpp> | 32 #include <boost/move/utility_core.hpp> |
30 #include <boost/interprocess/detail/variadic_templates_tools.hpp> | 33 #include <boost/interprocess/detail/variadic_templates_tools.hpp> |
31 #endif //#ifdef BOOST_INTERPROCESS_PERFECT_FORWARDING | 34 #endif //#ifdef BOOST_INTERPROCESS_PERFECT_FORWARDING |
35 #include <boost/container/detail/placement_new.hpp> | |
32 | 36 |
33 //!\file | 37 //!\file |
34 //!Describes a proxy class that implements named allocation syntax. | 38 //!Describes a proxy class that implements named allocation syntax. |
35 | 39 |
36 namespace boost { | 40 namespace boost { |
38 namespace ipcdetail { | 42 namespace ipcdetail { |
39 | 43 |
40 #ifdef BOOST_INTERPROCESS_PERFECT_FORWARDING | 44 #ifdef BOOST_INTERPROCESS_PERFECT_FORWARDING |
41 | 45 |
42 template<class T, bool is_iterator, class ...Args> | 46 template<class T, bool is_iterator, class ...Args> |
43 struct CtorNArg : public placement_destroy<T> | 47 struct CtorArgN : public placement_destroy<T> |
44 { | 48 { |
45 typedef bool_<is_iterator> IsIterator; | 49 typedef bool_<is_iterator> IsIterator; |
46 typedef CtorNArg<T, is_iterator, Args...> self_t; | 50 typedef CtorArgN<T, is_iterator, Args...> self_t; |
47 typedef typename build_number_seq<sizeof...(Args)>::type index_tuple_t; | 51 typedef typename build_number_seq<sizeof...(Args)>::type index_tuple_t; |
48 | 52 |
49 self_t& operator++() | 53 self_t& operator++() |
50 { | 54 { |
51 this->do_increment(IsIterator(), index_tuple_t()); | 55 this->do_increment(IsIterator(), index_tuple_t()); |
52 return *this; | 56 return *this; |
53 } | 57 } |
54 | 58 |
55 self_t operator++(int) { return ++*this; *this; } | 59 self_t operator++(int) { return ++*this; *this; } |
56 | 60 |
57 CtorNArg(Args && ...args) | 61 CtorArgN(Args && ...args) |
58 : args_(args...) | 62 : args_(args...) |
59 {} | 63 {} |
60 | 64 |
61 virtual void construct_n(void *mem | 65 virtual void construct_n(void *mem |
62 , std::size_t num | 66 , std::size_t num |
70 } | 74 } |
71 | 75 |
72 private: | 76 private: |
73 template<int ...IdxPack> | 77 template<int ...IdxPack> |
74 void construct(void *mem, true_, const index_tuple<IdxPack...>&) | 78 void construct(void *mem, true_, const index_tuple<IdxPack...>&) |
75 { new((void*)mem)T(*boost::forward<Args>(get<IdxPack>(args_))...); } | 79 { ::new((void*)mem, boost_container_new_t())T(*boost::forward<Args>(get<IdxPack>(args_))...); } |
76 | 80 |
77 template<int ...IdxPack> | 81 template<int ...IdxPack> |
78 void construct(void *mem, false_, const index_tuple<IdxPack...>&) | 82 void construct(void *mem, false_, const index_tuple<IdxPack...>&) |
79 { new((void*)mem)T(boost::forward<Args>(get<IdxPack>(args_))...); } | 83 { ::new((void*)mem, boost_container_new_t())T(boost::forward<Args>(get<IdxPack>(args_))...); } |
80 | 84 |
81 template<int ...IdxPack> | 85 template<int ...IdxPack> |
82 void do_increment(true_, const index_tuple<IdxPack...>&) | 86 void do_increment(true_, const index_tuple<IdxPack...>&) |
83 { | 87 { |
84 this->expansion_helper(++get<IdxPack>(args_)...); | 88 this->expansion_helper(++get<IdxPack>(args_)...); |
118 {} | 122 {} |
119 | 123 |
120 template<class ...Args> | 124 template<class ...Args> |
121 T *operator()(Args &&...args) const | 125 T *operator()(Args &&...args) const |
122 { | 126 { |
123 CtorNArg<T, is_iterator, Args...> &&ctor_obj = CtorNArg<T, is_iterator, Args...> | 127 CtorArgN<T, is_iterator, Args...> &&ctor_obj = CtorArgN<T, is_iterator, Args...> |
124 (boost::forward<Args>(args)...); | 128 (boost::forward<Args>(args)...); |
125 return mp_mngr->template | 129 return mp_mngr->template |
126 generic_construct<T>(mp_name, m_num, m_find, m_dothrow, ctor_obj); | 130 generic_construct<T>(mp_name, m_num, m_find, m_dothrow, ctor_obj); |
127 } | 131 } |
128 | 132 |
130 const named_proxy &operator[](std::size_t num) const | 134 const named_proxy &operator[](std::size_t num) const |
131 { m_num *= num; return *this; } | 135 { m_num *= num; return *this; } |
132 }; | 136 }; |
133 | 137 |
134 #else //#ifdef BOOST_INTERPROCESS_PERFECT_FORWARDING | 138 #else //#ifdef BOOST_INTERPROCESS_PERFECT_FORWARDING |
135 | |
136 //!Function object that makes placement new | |
137 //!without arguments | |
138 template<class T> | |
139 struct Ctor0Arg : public placement_destroy<T> | |
140 { | |
141 typedef Ctor0Arg self_t; | |
142 | |
143 Ctor0Arg(){} | |
144 | |
145 self_t& operator++() { return *this; } | |
146 self_t operator++(int) { return *this; } | |
147 | |
148 void construct(void *mem) | |
149 { new((void*)mem)T; } | |
150 | |
151 virtual void construct_n(void *mem, std::size_t num, std::size_t &constructed) | |
152 { | |
153 T* memory = static_cast<T*>(mem); | |
154 for(constructed = 0; constructed < num; ++constructed) | |
155 new((void*)memory++)T; | |
156 } | |
157 }; | |
158 | 139 |
159 //////////////////////////////////////////////////////////////// | 140 //////////////////////////////////////////////////////////////// |
160 // What the macro should generate (n == 2): | 141 // What the macro should generate (n == 2): |
161 // | 142 // |
162 // template<class T, bool is_iterator, class P1, class P2> | 143 // template<class T, bool is_iterator, class P1, class P2> |
205 // | 186 // |
206 // P1 &m_p1; P2 &m_p2; | 187 // P1 &m_p1; P2 &m_p2; |
207 // }; | 188 // }; |
208 //////////////////////////////////////////////////////////////// | 189 //////////////////////////////////////////////////////////////// |
209 | 190 |
210 //Note: | 191 #define BOOST_INTERPROCESS_NAMED_PROXY_CTORARGN(N)\ |
211 //We define template parameters as const references to | 192 \ |
212 //be able to bind temporaries. After that we will un-const them. | 193 template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N > \ |
213 //This cast is ugly but it is necessary until "perfect forwarding" | 194 struct CtorArg##N : placement_destroy<T>\ |
214 //is achieved in C++0x. Meanwhile, if we want to be able to | 195 {\ |
215 //bind lvalues with non-const references, we have to be ugly | 196 typedef CtorArg##N self_t;\ |
216 #define BOOST_PP_LOCAL_MACRO(n) \ | 197 \ |
217 template<class T, bool is_iterator, BOOST_PP_ENUM_PARAMS(n, class P) > \ | 198 CtorArg##N ( BOOST_MOVE_UREF##N )\ |
218 struct BOOST_PP_CAT(BOOST_PP_CAT(Ctor, n), Arg) \ | 199 BOOST_MOVE_COLON##N BOOST_MOVE_FWD_INIT##N{}\ |
219 : public placement_destroy<T> \ | 200 \ |
220 { \ | 201 virtual void construct_n(void *mem, std::size_t num, std::size_t &constructed)\ |
221 typedef bool_<is_iterator> IsIterator; \ | 202 {\ |
222 typedef BOOST_PP_CAT(BOOST_PP_CAT(Ctor, n), Arg) self_t; \ | 203 T* memory = static_cast<T*>(mem);\ |
223 \ | 204 for(constructed = 0; constructed < num; ++constructed){\ |
224 void do_increment(true_) \ | 205 ::new((void*)memory++) T ( BOOST_MOVE_MFWD##N );\ |
225 { BOOST_PP_ENUM(n, BOOST_INTERPROCESS_PP_PARAM_INC, _); } \ | 206 }\ |
226 \ | 207 }\ |
227 void do_increment(false_){} \ | 208 \ |
228 \ | 209 private:\ |
229 self_t& operator++() \ | 210 BOOST_MOVE_MREF##N\ |
230 { \ | 211 };\ |
231 this->do_increment(IsIterator()); \ | |
232 return *this; \ | |
233 } \ | |
234 \ | |
235 self_t operator++(int) { return ++*this; *this; } \ | |
236 \ | |
237 BOOST_PP_CAT(BOOST_PP_CAT(Ctor, n), Arg) \ | |
238 ( BOOST_PP_ENUM(n, BOOST_INTERPROCESS_PP_PARAM_LIST, _) ) \ | |
239 : BOOST_PP_ENUM(n, BOOST_INTERPROCESS_PP_PARAM_INIT, _) {} \ | |
240 \ | |
241 virtual void construct_n(void *mem \ | |
242 , std::size_t num \ | |
243 , std::size_t &constructed) \ | |
244 { \ | |
245 T* memory = static_cast<T*>(mem); \ | |
246 for(constructed = 0; constructed < num; ++constructed){ \ | |
247 this->construct(memory++, IsIterator()); \ | |
248 this->do_increment(IsIterator()); \ | |
249 } \ | |
250 } \ | |
251 \ | |
252 private: \ | |
253 void construct(void *mem, true_) \ | |
254 { \ | |
255 new((void*)mem) T \ | |
256 (BOOST_PP_ENUM(n, BOOST_INTERPROCESS_PP_MEMBER_IT_FORWARD, _)); \ | |
257 } \ | |
258 \ | |
259 void construct(void *mem, false_) \ | |
260 { \ | |
261 new((void*)mem) T \ | |
262 (BOOST_PP_ENUM(n, BOOST_INTERPROCESS_PP_MEMBER_FORWARD, _)); \ | |
263 } \ | |
264 \ | |
265 BOOST_PP_REPEAT(n, BOOST_INTERPROCESS_PP_PARAM_DEFINE, _) \ | |
266 }; \ | |
267 //! | 212 //! |
268 #define BOOST_PP_LOCAL_LIMITS (1, BOOST_INTERPROCESS_MAX_CONSTRUCTOR_PARAMETERS) | 213 BOOST_MOVE_ITERATE_0TO9(BOOST_INTERPROCESS_NAMED_PROXY_CTORARGN) |
269 #include BOOST_PP_LOCAL_ITERATE() | 214 #undef BOOST_INTERPROCESS_NAMED_PROXY_CTORARGN |
215 | |
216 #define BOOST_INTERPROCESS_NAMED_PROXY_CTORITN(N)\ | |
217 \ | |
218 template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N > \ | |
219 struct CtorIt##N : public placement_destroy<T>\ | |
220 {\ | |
221 typedef CtorIt##N self_t;\ | |
222 \ | |
223 self_t& operator++()\ | |
224 { BOOST_MOVE_MINC##N; return *this; }\ | |
225 \ | |
226 self_t operator++(int) { return ++*this; *this; }\ | |
227 \ | |
228 CtorIt##N ( BOOST_MOVE_VAL##N )\ | |
229 BOOST_MOVE_COLON##N BOOST_MOVE_VAL_INIT##N{}\ | |
230 \ | |
231 virtual void construct_n(void *mem, std::size_t num, std::size_t &constructed)\ | |
232 {\ | |
233 T* memory = static_cast<T*>(mem);\ | |
234 for(constructed = 0; constructed < num; ++constructed){\ | |
235 ::new((void*)memory++) T( BOOST_MOVE_MITFWD##N );\ | |
236 ++(*this);\ | |
237 }\ | |
238 }\ | |
239 \ | |
240 private:\ | |
241 BOOST_MOVE_MEMB##N\ | |
242 };\ | |
243 //! | |
244 BOOST_MOVE_ITERATE_0TO9(BOOST_INTERPROCESS_NAMED_PROXY_CTORITN) | |
245 #undef BOOST_INTERPROCESS_NAMED_PROXY_CTORITN | |
270 | 246 |
271 //!Describes a proxy class that implements named | 247 //!Describes a proxy class that implements named |
272 //!allocation syntax. | 248 //!allocation syntax. |
273 template | 249 template |
274 < class SegmentManager //segment manager to construct the object | 250 < class SegmentManager //segment manager to construct the object |
288 named_proxy(SegmentManager *mngr, const char_type *name, bool find, bool dothrow) | 264 named_proxy(SegmentManager *mngr, const char_type *name, bool find, bool dothrow) |
289 : mp_name(name), mp_mngr(mngr), m_num(1) | 265 : mp_name(name), mp_mngr(mngr), m_num(1) |
290 , m_find(find), m_dothrow(dothrow) | 266 , m_find(find), m_dothrow(dothrow) |
291 {} | 267 {} |
292 | 268 |
293 //!makes a named allocation and calls the | 269 #define BOOST_INTERPROCESS_NAMED_PROXY_CALL_OPERATOR(N)\ |
294 //!default constructor | 270 \ |
295 T *operator()() const | 271 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ |
296 { | 272 T *operator()( BOOST_MOVE_UREF##N ) const\ |
297 Ctor0Arg<T> ctor_obj; | 273 {\ |
298 return mp_mngr->template | 274 typedef typename if_c<is_iterator \ |
299 generic_construct<T>(mp_name, m_num, m_find, m_dothrow, ctor_obj); | 275 , CtorIt##N<T BOOST_MOVE_I##N BOOST_MOVE_TARG##N> \ |
300 } | 276 , CtorArg##N<T BOOST_MOVE_I##N BOOST_MOVE_TARG##N> \ |
301 //! | 277 >::type ctor_obj_t;\ |
302 | 278 ctor_obj_t ctor_obj = ctor_obj_t( BOOST_MOVE_FWD##N );\ |
303 #define BOOST_PP_LOCAL_MACRO(n) \ | 279 return mp_mngr->template generic_construct<T>(mp_name, m_num, m_find, m_dothrow, ctor_obj);\ |
304 template<BOOST_PP_ENUM_PARAMS(n, class P)> \ | 280 }\ |
305 T *operator()(BOOST_PP_ENUM (n, BOOST_INTERPROCESS_PP_PARAM_LIST, _)) const\ | 281 // |
306 { \ | 282 BOOST_MOVE_ITERATE_0TO9(BOOST_INTERPROCESS_NAMED_PROXY_CALL_OPERATOR) |
307 typedef BOOST_PP_CAT(BOOST_PP_CAT(Ctor, n), Arg) \ | 283 #undef BOOST_INTERPROCESS_NAMED_PROXY_CALL_OPERATOR |
308 <T, is_iterator, BOOST_PP_ENUM_PARAMS(n, P)> \ | |
309 ctor_obj_t; \ | |
310 ctor_obj_t ctor_obj \ | |
311 (BOOST_PP_ENUM(n, BOOST_INTERPROCESS_PP_PARAM_FORWARD, _)); \ | |
312 return mp_mngr->template generic_construct<T> \ | |
313 (mp_name, m_num, m_find, m_dothrow, ctor_obj); \ | |
314 } \ | |
315 //! | |
316 | |
317 #define BOOST_PP_LOCAL_LIMITS ( 1, BOOST_INTERPROCESS_MAX_CONSTRUCTOR_PARAMETERS ) | |
318 #include BOOST_PP_LOCAL_ITERATE() | |
319 | 284 |
320 //////////////////////////////////////////////////////////////////////// | 285 //////////////////////////////////////////////////////////////////////// |
321 // What the macro should generate (n == 2) | 286 // What the macro should generate (n == 2) |
322 //////////////////////////////////////////////////////////////////////// | 287 //////////////////////////////////////////////////////////////////////// |
323 // | 288 // |
324 // template <class P1, class P2> | 289 // template <class P1, class P2> |
325 // T *operator()(P1 &p1, P2 &p2) const | 290 // T *operator()(P1 &p1, P2 &p2) const |
326 // { | 291 // { |
327 // typedef Ctor2Arg | 292 // typedef CtorArg2 |
328 // <T, is_iterator, P1, P2> | 293 // <T, is_iterator, P1, P2> |
329 // ctor_obj_t; | 294 // ctor_obj_t; |
330 // ctor_obj_t ctor_obj(p1, p2); | 295 // ctor_obj_t ctor_obj(p1, p2); |
331 // | 296 // |
332 // return mp_mngr->template generic_construct<T> | 297 // return mp_mngr->template generic_construct<T> |