dispatch_uses_allocator.hpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2015-2015. 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/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_CONTAINER_DISPATCH_USES_ALLOCATOR_HPP
  11. #define BOOST_CONTAINER_DISPATCH_USES_ALLOCATOR_HPP
  12. #if defined (_MSC_VER)
  13. # pragma once
  14. #endif
  15. #include <boost/container/detail/config_begin.hpp>
  16. #include <boost/container/detail/workaround.hpp>
  17. #include <boost/container/allocator_traits.hpp>
  18. #include <boost/container/uses_allocator.hpp>
  19. #include <boost/container/detail/addressof.hpp>
  20. #include <boost/container/detail/mpl.hpp>
  21. #include <boost/container/detail/is_pair.hpp>
  22. #include <boost/container/detail/type_traits.hpp>
  23. #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  24. #include <boost/move/detail/fwd_macros.hpp>
  25. #else
  26. #include <boost/container/detail/variadic_templates_tools.hpp>
  27. #endif
  28. #include <boost/move/utility_core.hpp>
  29. namespace boost { namespace container {
  30. namespace dtl {
  31. // Check if we can detect is_convertible using advanced SFINAE expressions
  32. #if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  33. //! Code inspired by Mathias Gaunard's is_convertible.cpp found in the Boost mailing list
  34. //! http://boost.2283326.n4.nabble.com/type-traits-is-constructible-when-decltype-is-supported-td3575452.html
  35. //! Thanks Mathias!
  36. //With variadic templates, we need a single class to implement the trait
  37. template<class T, class ...Args>
  38. struct is_constructible
  39. {
  40. typedef char yes_type;
  41. struct no_type
  42. { char padding[2]; };
  43. template<std::size_t N>
  44. struct dummy;
  45. template<class X>
  46. static decltype(X(boost::move_detail::declval<Args>()...), true_type()) test(int);
  47. template<class X>
  48. static no_type test(...);
  49. static const bool value = sizeof(test<T>(0)) == sizeof(yes_type);
  50. };
  51. template <class T, class InnerAlloc, class ...Args>
  52. struct is_constructible_with_allocator_prefix
  53. : is_constructible<T, allocator_arg_t, InnerAlloc, Args...>
  54. {};
  55. #else // #if !defined(BOOST_NO_SFINAE_EXPR) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  56. //Without advanced SFINAE expressions, we can't use is_constructible
  57. //so backup to constructible_with_allocator_xxx
  58. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  59. template <class T, class InnerAlloc, class ...Args>
  60. struct is_constructible_with_allocator_prefix
  61. : constructible_with_allocator_prefix<T>
  62. {};
  63. template <class T, class InnerAlloc, class ...Args>
  64. struct is_constructible_with_allocator_suffix
  65. : constructible_with_allocator_suffix<T>
  66. {};
  67. #else // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  68. template <class T, class InnerAlloc, BOOST_MOVE_CLASSDFLT9>
  69. struct is_constructible_with_allocator_prefix
  70. : constructible_with_allocator_prefix<T>
  71. {};
  72. template <class T, class InnerAlloc, BOOST_MOVE_CLASSDFLT9>
  73. struct is_constructible_with_allocator_suffix
  74. : constructible_with_allocator_suffix<T>
  75. {};
  76. #endif // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  77. #endif // #if !defined(BOOST_NO_SFINAE_EXPR)
  78. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  79. template < typename ConstructAlloc
  80. , typename ArgAlloc
  81. , typename T
  82. , class ...Args
  83. >
  84. inline typename dtl::enable_if_and
  85. < void
  86. , dtl::is_not_pair<T>
  87. , dtl::not_< uses_allocator<T, typename remove_cvref<ArgAlloc>::type > >
  88. >::type dispatch_uses_allocator
  89. ( ConstructAlloc & construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p, BOOST_FWD_REF(Args)...args)
  90. {
  91. (void)arg_alloc;
  92. allocator_traits<ConstructAlloc>::construct(construct_alloc, p, ::boost::forward<Args>(args)...);
  93. }
  94. // allocator_arg_t
  95. template < typename ConstructAlloc
  96. , typename ArgAlloc
  97. , typename T
  98. , class ...Args
  99. >
  100. inline typename dtl::enable_if_and
  101. < void
  102. , dtl::is_not_pair<T>
  103. , uses_allocator<T, typename remove_cvref<ArgAlloc>::type>
  104. , is_constructible_with_allocator_prefix<T, ArgAlloc, Args...>
  105. >::type dispatch_uses_allocator
  106. ( ConstructAlloc& construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p, BOOST_FWD_REF(Args) ...args)
  107. {
  108. allocator_traits<ConstructAlloc>::construct
  109. ( construct_alloc, p, allocator_arg
  110. , ::boost::forward<ArgAlloc>(arg_alloc), ::boost::forward<Args>(args)...);
  111. }
  112. // allocator suffix
  113. template < typename ConstructAlloc
  114. , typename ArgAlloc
  115. , typename T
  116. , class ...Args
  117. >
  118. inline typename dtl::enable_if_and
  119. < void
  120. , dtl::is_not_pair<T>
  121. , uses_allocator<T, typename remove_cvref<ArgAlloc>::type>
  122. , dtl::not_<is_constructible_with_allocator_prefix<T, ArgAlloc, Args...> >
  123. >::type dispatch_uses_allocator
  124. ( ConstructAlloc& construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p, BOOST_FWD_REF(Args)...args)
  125. {
  126. allocator_traits<ConstructAlloc>::construct
  127. (construct_alloc, p, ::boost::forward<Args>(args)..., ::boost::forward<ArgAlloc>(arg_alloc));
  128. }
  129. #else //#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  130. #define BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE(N) \
  131. template <typename ConstructAlloc, typename ArgAlloc, typename T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
  132. inline typename dtl::enable_if_and\
  133. < void\
  134. , dtl::is_not_pair<T>\
  135. , dtl::not_<uses_allocator<T, typename remove_cvref<ArgAlloc>::type> >\
  136. >::type\
  137. dispatch_uses_allocator\
  138. (ConstructAlloc &construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  139. {\
  140. (void)arg_alloc;\
  141. allocator_traits<ConstructAlloc>::construct(construct_alloc, p BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
  142. }\
  143. //
  144. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE)
  145. #undef BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE
  146. #define BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE(N) \
  147. template < typename ConstructAlloc, typename ArgAlloc, typename T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
  148. inline typename dtl::enable_if_and\
  149. < void\
  150. , dtl::is_not_pair<T>\
  151. , uses_allocator<T, typename remove_cvref<ArgAlloc>::type>\
  152. , is_constructible_with_allocator_prefix<T, ArgAlloc BOOST_MOVE_I##N BOOST_MOVE_TARG##N>\
  153. >::type\
  154. dispatch_uses_allocator\
  155. (ConstructAlloc& construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  156. {\
  157. allocator_traits<ConstructAlloc>::construct\
  158. (construct_alloc, p, allocator_arg, ::boost::forward<ArgAlloc>(arg_alloc) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
  159. }\
  160. //
  161. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE)
  162. #undef BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE
  163. #define BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE(N) \
  164. template < typename ConstructAlloc, typename ArgAlloc, typename T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
  165. inline typename dtl::enable_if_and\
  166. < void\
  167. , dtl::is_not_pair<T>\
  168. , uses_allocator<T, typename remove_cvref<ArgAlloc>::type>\
  169. , dtl::not_<is_constructible_with_allocator_prefix<T, ArgAlloc BOOST_MOVE_I##N BOOST_MOVE_TARG##N> >\
  170. >::type\
  171. dispatch_uses_allocator\
  172. (ConstructAlloc& construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  173. {\
  174. allocator_traits<ConstructAlloc>::construct\
  175. (construct_alloc, p BOOST_MOVE_I##N BOOST_MOVE_FWD##N, ::boost::forward<ArgAlloc>(arg_alloc));\
  176. }\
  177. //
  178. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE)
  179. #undef BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE
  180. #endif //#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  181. template < typename ConstructAlloc
  182. , typename ArgAlloc
  183. , typename Pair
  184. > inline
  185. BOOST_CONTAINER_DOC1ST(void, typename dtl::enable_if<dtl::is_pair<Pair> BOOST_MOVE_I void >::type)
  186. dispatch_uses_allocator
  187. ( ConstructAlloc & construct_alloc
  188. , BOOST_FWD_REF(ArgAlloc) arg_alloc
  189. , Pair* p)
  190. {
  191. dispatch_uses_allocator(construct_alloc, arg_alloc, dtl::addressof(p->first));
  192. BOOST_CONTAINER_TRY{
  193. dispatch_uses_allocator(construct_alloc, arg_alloc, dtl::addressof(p->second));
  194. }
  195. BOOST_CONTAINER_CATCH(...) {
  196. allocator_traits<ConstructAlloc>::destroy(construct_alloc, dtl::addressof(p->first));
  197. BOOST_CONTAINER_RETHROW
  198. }
  199. BOOST_CONTAINER_CATCH_END
  200. }
  201. template < typename ConstructAlloc
  202. , typename ArgAlloc
  203. , class Pair, class U, class V>
  204. BOOST_CONTAINER_DOC1ST(void, typename dtl::enable_if<dtl::is_pair<Pair> BOOST_MOVE_I void>::type)
  205. dispatch_uses_allocator
  206. ( ConstructAlloc & construct_alloc
  207. , BOOST_FWD_REF(ArgAlloc) arg_alloc
  208. , Pair* p, BOOST_FWD_REF(U) x, BOOST_FWD_REF(V) y)
  209. {
  210. dispatch_uses_allocator(construct_alloc, arg_alloc, dtl::addressof(p->first), ::boost::forward<U>(x));
  211. BOOST_CONTAINER_TRY{
  212. dispatch_uses_allocator(construct_alloc, arg_alloc, dtl::addressof(p->second), ::boost::forward<V>(y));
  213. }
  214. BOOST_CONTAINER_CATCH(...){
  215. allocator_traits<ConstructAlloc>::destroy(construct_alloc, dtl::addressof(p->first));
  216. BOOST_CONTAINER_RETHROW
  217. }
  218. BOOST_CONTAINER_CATCH_END
  219. }
  220. template < typename ConstructAlloc
  221. , typename ArgAlloc
  222. , class Pair, class Pair2>
  223. BOOST_CONTAINER_DOC1ST(void, typename dtl::enable_if< dtl::is_pair<Pair> BOOST_MOVE_I void >::type)
  224. dispatch_uses_allocator
  225. (ConstructAlloc & construct_alloc
  226. , BOOST_FWD_REF(ArgAlloc) arg_alloc
  227. , Pair* p, Pair2& x)
  228. { dispatch_uses_allocator(construct_alloc, arg_alloc, p, x.first, x.second); }
  229. template < typename ConstructAlloc
  230. , typename ArgAlloc
  231. , class Pair, class Pair2>
  232. typename dtl::enable_if_and
  233. < void
  234. , dtl::is_pair<Pair>
  235. , dtl::not_<boost::move_detail::is_reference<Pair2> > >::type //This is needed for MSVC10 and ambiguous overloads
  236. dispatch_uses_allocator
  237. (ConstructAlloc & construct_alloc
  238. , BOOST_FWD_REF(ArgAlloc) arg_alloc
  239. , Pair* p, BOOST_RV_REF_BEG Pair2 BOOST_RV_REF_END x)
  240. { dispatch_uses_allocator(construct_alloc, arg_alloc, p, ::boost::move(x.first), ::boost::move(x.second)); }
  241. //piecewise construction from boost::tuple
  242. #define BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_BOOST_TUPLE_CODE(N,M)\
  243. template< typename ConstructAlloc, typename ArgAlloc, class Pair \
  244. , template<class, class, class, class, class, class, class, class, class, class> class BoostTuple \
  245. BOOST_MOVE_I_IF(BOOST_MOVE_OR(N,M)) BOOST_MOVE_CLASS##N BOOST_MOVE_I_IF(BOOST_MOVE_AND(N,M)) BOOST_MOVE_CLASSQ##M > \
  246. typename dtl::enable_if< dtl::is_pair<Pair> BOOST_MOVE_I void>::type\
  247. dispatch_uses_allocator( ConstructAlloc & construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, Pair* pair, piecewise_construct_t\
  248. , BoostTuple<BOOST_MOVE_TARG##N BOOST_MOVE_I##N BOOST_MOVE_REPEAT(BOOST_MOVE_SUB(10,N),::boost::tuples::null_type)> p\
  249. , BoostTuple<BOOST_MOVE_TARGQ##M BOOST_MOVE_I##M BOOST_MOVE_REPEAT(BOOST_MOVE_SUB(10,M),::boost::tuples::null_type)> q)\
  250. {\
  251. (void)p; (void)q;\
  252. dispatch_uses_allocator\
  253. (construct_alloc, arg_alloc, dtl::addressof(pair->first) BOOST_MOVE_I_IF(N) BOOST_MOVE_TMPL_GET##N);\
  254. BOOST_CONTAINER_TRY{\
  255. dispatch_uses_allocator\
  256. (construct_alloc, arg_alloc, dtl::addressof(pair->second) BOOST_MOVE_I_IF(M) BOOST_MOVE_TMPL_GETQ##M);\
  257. }\
  258. BOOST_CONTAINER_CATCH(...) {\
  259. allocator_traits<ConstructAlloc>::destroy(construct_alloc, dtl::addressof(pair->first));\
  260. BOOST_CONTAINER_RETHROW\
  261. }\
  262. BOOST_CONTAINER_CATCH_END\
  263. }\
  264. //
  265. BOOST_MOVE_ITER2D_0TOMAX(9, BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_BOOST_TUPLE_CODE)
  266. #undef BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_BOOST_TUPLE_CODE
  267. //piecewise construction from Std Tuple
  268. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  269. template< typename ConstructAlloc, typename ArgAlloc, class Pair
  270. , template<class ...> class Tuple, class... Args1, class... Args2, size_t... Indexes1, size_t... Indexes2>
  271. void dispatch_uses_allocator_index( ConstructAlloc & construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, Pair* pair
  272. , Tuple<Args1...>& t1, Tuple<Args2...>& t2, index_tuple<Indexes1...>, index_tuple<Indexes2...>)
  273. {
  274. (void)t1; (void)t2;
  275. dispatch_uses_allocator(construct_alloc, arg_alloc, dtl::addressof(pair->first), ::boost::forward<Args1>(get<Indexes1>(t1))...);
  276. BOOST_CONTAINER_TRY{
  277. dispatch_uses_allocator(construct_alloc, arg_alloc, dtl::addressof(pair->second), ::boost::forward<Args2>(get<Indexes2>(t2))...);
  278. }
  279. BOOST_CONTAINER_CATCH(...){
  280. allocator_traits<ConstructAlloc>::destroy(construct_alloc, dtl::addressof(pair->first));
  281. BOOST_CONTAINER_RETHROW
  282. }
  283. BOOST_CONTAINER_CATCH_END
  284. }
  285. template< typename ConstructAlloc, typename ArgAlloc, class Pair
  286. , template<class ...> class Tuple, class... Args1, class... Args2>
  287. typename dtl::enable_if< dtl::is_pair<Pair>, void >::type
  288. dispatch_uses_allocator( ConstructAlloc & construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, Pair* pair, piecewise_construct_t
  289. , Tuple<Args1...> t1, Tuple<Args2...> t2)
  290. {
  291. (dispatch_uses_allocator_index)( construct_alloc, arg_alloc, pair, t1, t2
  292. , typename build_number_seq<sizeof...(Args1)>::type()
  293. , typename build_number_seq<sizeof...(Args2)>::type());
  294. }
  295. #elif defined(BOOST_MSVC) && (_CPPLIB_VER == 520)
  296. //MSVC 2010 tuple implementation
  297. #define BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_MSVC2010_TUPLE_CODE(N,M)\
  298. template< typename ConstructAlloc, typename ArgAlloc, class Pair\
  299. , template<class, class, class, class, class, class, class, class, class, class> class StdTuple\
  300. BOOST_MOVE_I_IF(BOOST_MOVE_OR(N,M)) BOOST_MOVE_CLASS##N BOOST_MOVE_I_IF(BOOST_MOVE_AND(N,M)) BOOST_MOVE_CLASSQ##M > \
  301. typename dtl::enable_if< dtl::is_pair<Pair> BOOST_MOVE_I void>::type\
  302. dispatch_uses_allocator(ConstructAlloc & construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, Pair* pair, piecewise_construct_t\
  303. , StdTuple<BOOST_MOVE_TARG##N BOOST_MOVE_I##N BOOST_MOVE_REPEAT(BOOST_MOVE_SUB(10,N),::std::tr1::_Nil)> p\
  304. , StdTuple<BOOST_MOVE_TARGQ##M BOOST_MOVE_I##M BOOST_MOVE_REPEAT(BOOST_MOVE_SUB(10,M),::std::tr1::_Nil)> q)\
  305. {\
  306. (void)p; (void)q;\
  307. dispatch_uses_allocator\
  308. (construct_alloc, arg_alloc, dtl::addressof(pair->first) BOOST_MOVE_I_IF(N) BOOST_MOVE_GET_IDX##N);\
  309. BOOST_CONTAINER_TRY{\
  310. dispatch_uses_allocator\
  311. (construct_alloc, arg_alloc, dtl::addressof(pair->second) BOOST_MOVE_I_IF(M) BOOST_MOVE_GET_IDXQ##M);\
  312. }\
  313. BOOST_CONTAINER_CATCH(...) {\
  314. allocator_traits<ConstructAlloc>::destroy(construct_alloc, dtl::addressof(pair->first));\
  315. BOOST_CONTAINER_RETHROW\
  316. }\
  317. BOOST_CONTAINER_CATCH_END\
  318. }\
  319. //
  320. BOOST_MOVE_ITER2D_0TOMAX(9, BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_MSVC2010_TUPLE_CODE)
  321. #undef BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_MSVC2010_TUPLE_CODE
  322. #elif defined(BOOST_MSVC) && (_CPPLIB_VER == 540)
  323. #if _VARIADIC_MAX >= 9
  324. #define BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_MSVC2012_TUPLE_MAX_IT 9
  325. #else
  326. #define BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_MSVC2012_TUPLE_MAX_IT BOOST_MOVE_ADD(_VARIADIC_MAX, 1)
  327. #endif
  328. //MSVC 2012 tuple implementation
  329. #define BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_MSVC2012_TUPLE_CODE(N,M)\
  330. template< typename ConstructAlloc, typename ArgAlloc, class Pair\
  331. , template<BOOST_MOVE_REPEAT(_VARIADIC_MAX, class), class, class, class> class StdTuple \
  332. BOOST_MOVE_I_IF(BOOST_MOVE_OR(N,M)) BOOST_MOVE_CLASS##N BOOST_MOVE_I_IF(BOOST_MOVE_AND(N,M)) BOOST_MOVE_CLASSQ##M > \
  333. typename dtl::enable_if< dtl::is_pair<Pair> BOOST_MOVE_I void>::type\
  334. dispatch_uses_allocator\
  335. ( ConstructAlloc & construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, Pair* pair, piecewise_construct_t\
  336. , StdTuple<BOOST_MOVE_TARG##N BOOST_MOVE_I##N BOOST_MOVE_REPEAT(BOOST_MOVE_SUB(BOOST_MOVE_ADD(_VARIADIC_MAX, 3),N),::std::_Nil) > p\
  337. , StdTuple<BOOST_MOVE_TARGQ##M BOOST_MOVE_I##M BOOST_MOVE_REPEAT(BOOST_MOVE_SUB(BOOST_MOVE_ADD(_VARIADIC_MAX, 3),M),::std::_Nil) > q)\
  338. {\
  339. (void)p; (void)q;\
  340. dispatch_uses_allocator\
  341. (construct_alloc, arg_alloc, dtl::addressof(pair->first) BOOST_MOVE_I_IF(N) BOOST_MOVE_GET_IDX##N);\
  342. BOOST_CONTAINER_TRY{\
  343. dispatch_uses_allocator\
  344. (construct_alloc, arg_alloc, dtl::addressof(pair->second) BOOST_MOVE_I_IF(M) BOOST_MOVE_GET_IDXQ##M);\
  345. }\
  346. BOOST_CONTAINER_CATCH(...) {\
  347. allocator_traits<ConstructAlloc>::destroy(construct_alloc, dtl::addressof(pair->first));\
  348. BOOST_CONTAINER_RETHROW\
  349. }\
  350. BOOST_CONTAINER_CATCH_END\
  351. }\
  352. //
  353. BOOST_MOVE_ITER2D_0TOMAX(BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_MSVC2012_TUPLE_MAX_IT, BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_MSVC2012_TUPLE_CODE)
  354. #undef BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_MSVC2010_TUPLE_CODE
  355. #undef BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_MSVC2012_TUPLE_MAX_IT
  356. #endif //!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  357. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  358. template < typename ConstructAlloc
  359. , typename ArgAlloc
  360. , class Pair, class KeyType, class ... Args>
  361. typename dtl::enable_if< dtl::is_pair<Pair>, void >::type
  362. dispatch_uses_allocator
  363. (ConstructAlloc & construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, Pair* p, try_emplace_t, BOOST_FWD_REF(KeyType) k, BOOST_FWD_REF(Args) ...args)
  364. {
  365. dispatch_uses_allocator(construct_alloc, arg_alloc, dtl::addressof(p->first), ::boost::forward<KeyType>(k));
  366. BOOST_CONTAINER_TRY{
  367. dispatch_uses_allocator(construct_alloc, arg_alloc, dtl::addressof(p->second), ::boost::forward<Args>(args)...);
  368. }
  369. BOOST_CONTAINER_CATCH(...) {
  370. allocator_traits<ConstructAlloc>::destroy(construct_alloc, dtl::addressof(p->first));
  371. BOOST_CONTAINER_RETHROW
  372. }
  373. BOOST_CONTAINER_CATCH_END
  374. }
  375. #else
  376. #define BOOST_CONTAINER_DISPATCH_USES_ALLOCATOR_PAIR_TRY_EMPLACE_CODE(N) \
  377. template <typename ConstructAlloc, typename ArgAlloc, class Pair, class KeyType BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
  378. inline typename dtl::enable_if\
  379. < dtl::is_pair<Pair> BOOST_MOVE_I void >::type\
  380. dispatch_uses_allocator\
  381. (ConstructAlloc &construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, Pair* p, try_emplace_t, \
  382. BOOST_FWD_REF(KeyType) k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  383. {\
  384. dispatch_uses_allocator(construct_alloc, arg_alloc, dtl::addressof(p->first), ::boost::forward<KeyType>(k));\
  385. BOOST_CONTAINER_TRY{\
  386. dispatch_uses_allocator(construct_alloc, arg_alloc, dtl::addressof(p->second) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
  387. }\
  388. BOOST_CONTAINER_CATCH(...) {\
  389. allocator_traits<ConstructAlloc>::destroy(construct_alloc, dtl::addressof(p->first));\
  390. BOOST_CONTAINER_RETHROW\
  391. }\
  392. BOOST_CONTAINER_CATCH_END\
  393. }\
  394. //
  395. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_DISPATCH_USES_ALLOCATOR_PAIR_TRY_EMPLACE_CODE)
  396. #undef BOOST_CONTAINER_DISPATCH_USES_ALLOCATOR_PAIR_TRY_EMPLACE_CODE
  397. #endif //!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  398. } //namespace dtl
  399. }} // namespace boost { namespace container {
  400. #include <boost/container/detail/config_end.hpp>
  401. #endif // BOOST_CONTAINER_DISPATCH_USES_ALLOCATOR_HPP