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