Chris@16
|
1 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 //
|
Chris@101
|
3 // (C) Copyright Ion Gaztanaga 2008-2013. Distributed under the Boost
|
Chris@16
|
4 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 //
|
Chris@16
|
7 // See http://www.boost.org/libs/container for documentation.
|
Chris@16
|
8 //
|
Chris@16
|
9 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_CONTAINER_ADVANCED_INSERT_INT_HPP
|
Chris@16
|
12 #define BOOST_CONTAINER_ADVANCED_INSERT_INT_HPP
|
Chris@16
|
13
|
Chris@101
|
14 #ifndef BOOST_CONFIG_HPP
|
Chris@101
|
15 # include <boost/config.hpp>
|
Chris@101
|
16 #endif
|
Chris@101
|
17
|
Chris@101
|
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
|
Chris@16
|
19 # pragma once
|
Chris@16
|
20 #endif
|
Chris@16
|
21
|
Chris@101
|
22 #include <boost/container/detail/config_begin.hpp>
|
Chris@16
|
23 #include <boost/container/detail/workaround.hpp>
|
Chris@101
|
24
|
Chris@101
|
25 // container
|
Chris@16
|
26 #include <boost/container/allocator_traits.hpp>
|
Chris@101
|
27 // container/detail
|
Chris@101
|
28 #include <boost/container/detail/copy_move_algo.hpp>
|
Chris@16
|
29 #include <boost/container/detail/destroyers.hpp>
|
Chris@101
|
30 #include <boost/container/detail/mpl.hpp>
|
Chris@101
|
31 #include <boost/container/detail/type_traits.hpp>
|
Chris@101
|
32 #include <boost/container/detail/iterator.hpp>
|
Chris@101
|
33 #include <boost/container/detail/iterators.hpp>
|
Chris@101
|
34 #include <boost/container/detail/iterator_to_raw_pointer.hpp>
|
Chris@101
|
35 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@101
|
36 #include <boost/move/detail/fwd_macros.hpp>
|
Chris@101
|
37 #endif
|
Chris@101
|
38 // move
|
Chris@101
|
39 #include <boost/move/utility_core.hpp>
|
Chris@101
|
40 // other
|
Chris@16
|
41 #include <boost/assert.hpp>
|
Chris@101
|
42 #include <boost/core/no_exceptions_support.hpp>
|
Chris@16
|
43
|
Chris@16
|
44 namespace boost { namespace container { namespace container_detail {
|
Chris@16
|
45
|
Chris@101
|
46 template<class Allocator, class FwdIt, class Iterator>
|
Chris@16
|
47 struct move_insert_range_proxy
|
Chris@16
|
48 {
|
Chris@101
|
49 typedef typename allocator_traits<Allocator>::size_type size_type;
|
Chris@101
|
50 typedef typename allocator_traits<Allocator>::value_type value_type;
|
Chris@16
|
51
|
Chris@101
|
52 explicit move_insert_range_proxy(FwdIt first)
|
Chris@101
|
53 : first_(first)
|
Chris@16
|
54 {}
|
Chris@16
|
55
|
Chris@101
|
56 void uninitialized_copy_n_and_update(Allocator &a, Iterator p, size_type n)
|
Chris@16
|
57 {
|
Chris@16
|
58 this->first_ = ::boost::container::uninitialized_move_alloc_n_source
|
Chris@101
|
59 (a, this->first_, n, p);
|
Chris@16
|
60 }
|
Chris@16
|
61
|
Chris@101
|
62 void copy_n_and_update(Allocator &, Iterator p, size_type n)
|
Chris@16
|
63 {
|
Chris@16
|
64 this->first_ = ::boost::container::move_n_source(this->first_, n, p);
|
Chris@16
|
65 }
|
Chris@16
|
66
|
Chris@16
|
67 FwdIt first_;
|
Chris@16
|
68 };
|
Chris@16
|
69
|
Chris@16
|
70
|
Chris@101
|
71 template<class Allocator, class FwdIt, class Iterator>
|
Chris@16
|
72 struct insert_range_proxy
|
Chris@16
|
73 {
|
Chris@101
|
74 typedef typename allocator_traits<Allocator>::size_type size_type;
|
Chris@101
|
75 typedef typename allocator_traits<Allocator>::value_type value_type;
|
Chris@16
|
76
|
Chris@101
|
77 explicit insert_range_proxy(FwdIt first)
|
Chris@101
|
78 : first_(first)
|
Chris@16
|
79 {}
|
Chris@16
|
80
|
Chris@101
|
81 void uninitialized_copy_n_and_update(Allocator &a, Iterator p, size_type n)
|
Chris@16
|
82 {
|
Chris@101
|
83 this->first_ = ::boost::container::uninitialized_copy_alloc_n_source(a, this->first_, n, p);
|
Chris@16
|
84 }
|
Chris@16
|
85
|
Chris@101
|
86 void copy_n_and_update(Allocator &, Iterator p, size_type n)
|
Chris@16
|
87 {
|
Chris@16
|
88 this->first_ = ::boost::container::copy_n_source(this->first_, n, p);
|
Chris@16
|
89 }
|
Chris@16
|
90
|
Chris@16
|
91 FwdIt first_;
|
Chris@16
|
92 };
|
Chris@16
|
93
|
Chris@16
|
94
|
Chris@101
|
95 template<class Allocator, class Iterator>
|
Chris@16
|
96 struct insert_n_copies_proxy
|
Chris@16
|
97 {
|
Chris@101
|
98 typedef typename allocator_traits<Allocator>::size_type size_type;
|
Chris@101
|
99 typedef typename allocator_traits<Allocator>::value_type value_type;
|
Chris@16
|
100
|
Chris@101
|
101 explicit insert_n_copies_proxy(const value_type &v)
|
Chris@101
|
102 : v_(v)
|
Chris@16
|
103 {}
|
Chris@16
|
104
|
Chris@101
|
105 void uninitialized_copy_n_and_update(Allocator &a, Iterator p, size_type n) const
|
Chris@101
|
106 { boost::container::uninitialized_fill_alloc_n(a, v_, n, p); }
|
Chris@16
|
107
|
Chris@101
|
108 void copy_n_and_update(Allocator &, Iterator p, size_type n) const
|
Chris@101
|
109 {
|
Chris@101
|
110 for (; 0 < n; --n, ++p){
|
Chris@101
|
111 *p = v_;
|
Chris@101
|
112 }
|
Chris@101
|
113 }
|
Chris@16
|
114
|
Chris@16
|
115 const value_type &v_;
|
Chris@16
|
116 };
|
Chris@16
|
117
|
Chris@101
|
118 template<class Allocator, class Iterator>
|
Chris@16
|
119 struct insert_value_initialized_n_proxy
|
Chris@16
|
120 {
|
Chris@101
|
121 typedef ::boost::container::allocator_traits<Allocator> alloc_traits;
|
Chris@101
|
122 typedef typename allocator_traits<Allocator>::size_type size_type;
|
Chris@101
|
123 typedef typename allocator_traits<Allocator>::value_type value_type;
|
Chris@16
|
124
|
Chris@101
|
125 void uninitialized_copy_n_and_update(Allocator &a, Iterator p, size_type n) const
|
Chris@101
|
126 { boost::container::uninitialized_value_init_alloc_n(a, n, p); }
|
Chris@16
|
127
|
Chris@101
|
128 void copy_n_and_update(Allocator &, Iterator, size_type) const
|
Chris@101
|
129 { BOOST_ASSERT(false); }
|
Chris@16
|
130 };
|
Chris@16
|
131
|
Chris@101
|
132 template<class Allocator, class Iterator>
|
Chris@16
|
133 struct insert_default_initialized_n_proxy
|
Chris@16
|
134 {
|
Chris@101
|
135 typedef ::boost::container::allocator_traits<Allocator> alloc_traits;
|
Chris@101
|
136 typedef typename allocator_traits<Allocator>::size_type size_type;
|
Chris@101
|
137 typedef typename allocator_traits<Allocator>::value_type value_type;
|
Chris@16
|
138
|
Chris@101
|
139 void uninitialized_copy_n_and_update(Allocator &a, Iterator p, size_type n) const
|
Chris@101
|
140 { boost::container::uninitialized_default_init_alloc_n(a, n, p); }
|
Chris@16
|
141
|
Chris@101
|
142 void copy_n_and_update(Allocator &, Iterator, size_type) const
|
Chris@101
|
143 { BOOST_ASSERT(false); }
|
Chris@16
|
144 };
|
Chris@16
|
145
|
Chris@101
|
146 template<class Allocator, class Iterator>
|
Chris@16
|
147 struct insert_copy_proxy
|
Chris@16
|
148 {
|
Chris@101
|
149 typedef boost::container::allocator_traits<Allocator> alloc_traits;
|
Chris@16
|
150 typedef typename alloc_traits::size_type size_type;
|
Chris@16
|
151 typedef typename alloc_traits::value_type value_type;
|
Chris@16
|
152
|
Chris@101
|
153 explicit insert_copy_proxy(const value_type &v)
|
Chris@101
|
154 : v_(v)
|
Chris@16
|
155 {}
|
Chris@16
|
156
|
Chris@101
|
157 void uninitialized_copy_n_and_update(Allocator &a, Iterator p, size_type n) const
|
Chris@16
|
158 {
|
Chris@16
|
159 BOOST_ASSERT(n == 1); (void)n;
|
Chris@101
|
160 alloc_traits::construct( a, iterator_to_raw_pointer(p), v_);
|
Chris@16
|
161 }
|
Chris@16
|
162
|
Chris@101
|
163 void copy_n_and_update(Allocator &, Iterator p, size_type n) const
|
Chris@16
|
164 {
|
Chris@16
|
165 BOOST_ASSERT(n == 1); (void)n;
|
Chris@16
|
166 *p =v_;
|
Chris@16
|
167 }
|
Chris@16
|
168
|
Chris@16
|
169 const value_type &v_;
|
Chris@16
|
170 };
|
Chris@16
|
171
|
Chris@16
|
172
|
Chris@101
|
173 template<class Allocator, class Iterator>
|
Chris@16
|
174 struct insert_move_proxy
|
Chris@16
|
175 {
|
Chris@101
|
176 typedef boost::container::allocator_traits<Allocator> alloc_traits;
|
Chris@16
|
177 typedef typename alloc_traits::size_type size_type;
|
Chris@16
|
178 typedef typename alloc_traits::value_type value_type;
|
Chris@16
|
179
|
Chris@101
|
180 explicit insert_move_proxy(value_type &v)
|
Chris@101
|
181 : v_(v)
|
Chris@16
|
182 {}
|
Chris@16
|
183
|
Chris@101
|
184 void uninitialized_copy_n_and_update(Allocator &a, Iterator p, size_type n) const
|
Chris@16
|
185 {
|
Chris@16
|
186 BOOST_ASSERT(n == 1); (void)n;
|
Chris@101
|
187 alloc_traits::construct( a, iterator_to_raw_pointer(p), ::boost::move(v_) );
|
Chris@16
|
188 }
|
Chris@16
|
189
|
Chris@101
|
190 void copy_n_and_update(Allocator &, Iterator p, size_type n) const
|
Chris@16
|
191 {
|
Chris@16
|
192 BOOST_ASSERT(n == 1); (void)n;
|
Chris@16
|
193 *p = ::boost::move(v_);
|
Chris@16
|
194 }
|
Chris@16
|
195
|
Chris@16
|
196 value_type &v_;
|
Chris@16
|
197 };
|
Chris@16
|
198
|
Chris@101
|
199 template<class It, class Allocator>
|
Chris@101
|
200 insert_move_proxy<Allocator, It> get_insert_value_proxy(BOOST_RV_REF(typename boost::container::iterator_traits<It>::value_type) v)
|
Chris@16
|
201 {
|
Chris@101
|
202 return insert_move_proxy<Allocator, It>(v);
|
Chris@16
|
203 }
|
Chris@16
|
204
|
Chris@101
|
205 template<class It, class Allocator>
|
Chris@101
|
206 insert_copy_proxy<Allocator, It> get_insert_value_proxy(const typename boost::container::iterator_traits<It>::value_type &v)
|
Chris@16
|
207 {
|
Chris@101
|
208 return insert_copy_proxy<Allocator, It>(v);
|
Chris@16
|
209 }
|
Chris@16
|
210
|
Chris@16
|
211 }}} //namespace boost { namespace container { namespace container_detail {
|
Chris@16
|
212
|
Chris@101
|
213 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
214
|
Chris@16
|
215 #include <boost/container/detail/variadic_templates_tools.hpp>
|
Chris@101
|
216 #include <boost/move/utility_core.hpp>
|
Chris@16
|
217
|
Chris@16
|
218 namespace boost {
|
Chris@16
|
219 namespace container {
|
Chris@16
|
220 namespace container_detail {
|
Chris@16
|
221
|
Chris@101
|
222 template<class Allocator, class Iterator, class ...Args>
|
Chris@101
|
223 struct insert_nonmovable_emplace_proxy
|
Chris@16
|
224 {
|
Chris@101
|
225 typedef boost::container::allocator_traits<Allocator> alloc_traits;
|
Chris@16
|
226 typedef typename alloc_traits::size_type size_type;
|
Chris@16
|
227 typedef typename alloc_traits::value_type value_type;
|
Chris@16
|
228
|
Chris@16
|
229 typedef typename build_number_seq<sizeof...(Args)>::type index_tuple_t;
|
Chris@16
|
230
|
Chris@101
|
231 explicit insert_nonmovable_emplace_proxy(BOOST_FWD_REF(Args)... args)
|
Chris@101
|
232 : args_(args...)
|
Chris@16
|
233 {}
|
Chris@16
|
234
|
Chris@101
|
235 void uninitialized_copy_n_and_update(Allocator &a, Iterator p, size_type n)
|
Chris@101
|
236 { this->priv_uninitialized_copy_some_and_update(a, index_tuple_t(), p, n); }
|
Chris@16
|
237
|
Chris@16
|
238 private:
|
Chris@16
|
239 template<int ...IdxPack>
|
Chris@101
|
240 void priv_uninitialized_copy_some_and_update(Allocator &a, const index_tuple<IdxPack...>&, Iterator p, size_type n)
|
Chris@16
|
241 {
|
Chris@16
|
242 BOOST_ASSERT(n == 1); (void)n;
|
Chris@101
|
243 alloc_traits::construct( a, iterator_to_raw_pointer(p), ::boost::forward<Args>(get<IdxPack>(this->args_))... );
|
Chris@16
|
244 }
|
Chris@16
|
245
|
Chris@16
|
246 protected:
|
Chris@16
|
247 tuple<Args&...> args_;
|
Chris@16
|
248 };
|
Chris@16
|
249
|
Chris@101
|
250 template<class Allocator, class Iterator, class ...Args>
|
Chris@16
|
251 struct insert_emplace_proxy
|
Chris@101
|
252 : public insert_nonmovable_emplace_proxy<Allocator, Iterator, Args...>
|
Chris@16
|
253 {
|
Chris@101
|
254 typedef insert_nonmovable_emplace_proxy<Allocator, Iterator, Args...> base_t;
|
Chris@101
|
255 typedef boost::container::allocator_traits<Allocator> alloc_traits;
|
Chris@16
|
256 typedef typename base_t::value_type value_type;
|
Chris@16
|
257 typedef typename base_t::size_type size_type;
|
Chris@16
|
258 typedef typename base_t::index_tuple_t index_tuple_t;
|
Chris@16
|
259
|
Chris@101
|
260 explicit insert_emplace_proxy(BOOST_FWD_REF(Args)... args)
|
Chris@101
|
261 : base_t(::boost::forward<Args>(args)...)
|
Chris@16
|
262 {}
|
Chris@16
|
263
|
Chris@101
|
264 void copy_n_and_update(Allocator &a, Iterator p, size_type n)
|
Chris@101
|
265 { this->priv_copy_some_and_update(a, index_tuple_t(), p, n); }
|
Chris@16
|
266
|
Chris@16
|
267 private:
|
Chris@16
|
268
|
Chris@16
|
269 template<int ...IdxPack>
|
Chris@101
|
270 void priv_copy_some_and_update(Allocator &a, const index_tuple<IdxPack...>&, Iterator p, size_type n)
|
Chris@16
|
271 {
|
Chris@16
|
272 BOOST_ASSERT(n ==1); (void)n;
|
Chris@101
|
273 typename aligned_storage<sizeof(value_type), alignment_of<value_type>::value>::type v;
|
Chris@16
|
274 value_type *vp = static_cast<value_type *>(static_cast<void *>(&v));
|
Chris@101
|
275 alloc_traits::construct(a, vp,
|
Chris@16
|
276 ::boost::forward<Args>(get<IdxPack>(this->args_))...);
|
Chris@16
|
277 BOOST_TRY{
|
Chris@16
|
278 *p = ::boost::move(*vp);
|
Chris@16
|
279 }
|
Chris@16
|
280 BOOST_CATCH(...){
|
Chris@101
|
281 alloc_traits::destroy(a, vp);
|
Chris@16
|
282 BOOST_RETHROW
|
Chris@16
|
283 }
|
Chris@16
|
284 BOOST_CATCH_END
|
Chris@101
|
285 alloc_traits::destroy(a, vp);
|
Chris@16
|
286 }
|
Chris@16
|
287 };
|
Chris@16
|
288
|
Chris@101
|
289 //Specializations to avoid an unneeded temporary when emplacing from a single argument o type value_type
|
Chris@101
|
290 template<class Allocator, class Iterator>
|
Chris@101
|
291 struct insert_emplace_proxy<Allocator, Iterator, typename boost::container::allocator_traits<Allocator>::value_type>
|
Chris@101
|
292 : public insert_move_proxy<Allocator, Iterator>
|
Chris@101
|
293 {
|
Chris@101
|
294 explicit insert_emplace_proxy(typename boost::container::allocator_traits<Allocator>::value_type &&v)
|
Chris@101
|
295 : insert_move_proxy<Allocator, Iterator>(v)
|
Chris@101
|
296 {}
|
Chris@101
|
297 };
|
Chris@101
|
298
|
Chris@101
|
299 //We use "add_const" here as adding "const" only confuses MSVC12(and maybe later) provoking
|
Chris@101
|
300 //compiler error C2752 ("more than one partial specialization matches").
|
Chris@101
|
301 //Any problem is solvable with an extra layer of indirection? ;-)
|
Chris@101
|
302 template<class Allocator, class Iterator>
|
Chris@101
|
303 struct insert_emplace_proxy<Allocator, Iterator
|
Chris@101
|
304 , typename boost::container::container_detail::add_const<typename boost::container::allocator_traits<Allocator>::value_type>::type
|
Chris@101
|
305 >
|
Chris@101
|
306 : public insert_copy_proxy<Allocator, Iterator>
|
Chris@101
|
307 {
|
Chris@101
|
308 explicit insert_emplace_proxy(const typename boost::container::allocator_traits<Allocator>::value_type &v)
|
Chris@101
|
309 : insert_copy_proxy<Allocator, Iterator>(v)
|
Chris@101
|
310 {}
|
Chris@101
|
311 };
|
Chris@101
|
312
|
Chris@101
|
313 template<class Allocator, class Iterator>
|
Chris@101
|
314 struct insert_emplace_proxy<Allocator, Iterator, typename boost::container::allocator_traits<Allocator>::value_type &>
|
Chris@101
|
315 : public insert_copy_proxy<Allocator, Iterator>
|
Chris@101
|
316 {
|
Chris@101
|
317 explicit insert_emplace_proxy(const typename boost::container::allocator_traits<Allocator>::value_type &v)
|
Chris@101
|
318 : insert_copy_proxy<Allocator, Iterator>(v)
|
Chris@101
|
319 {}
|
Chris@101
|
320 };
|
Chris@101
|
321
|
Chris@101
|
322 template<class Allocator, class Iterator>
|
Chris@101
|
323 struct insert_emplace_proxy<Allocator, Iterator
|
Chris@101
|
324 , typename boost::container::container_detail::add_const<typename boost::container::allocator_traits<Allocator>::value_type>::type &
|
Chris@101
|
325 >
|
Chris@101
|
326 : public insert_copy_proxy<Allocator, Iterator>
|
Chris@101
|
327 {
|
Chris@101
|
328 explicit insert_emplace_proxy(const typename boost::container::allocator_traits<Allocator>::value_type &v)
|
Chris@101
|
329 : insert_copy_proxy<Allocator, Iterator>(v)
|
Chris@101
|
330 {}
|
Chris@101
|
331 };
|
Chris@101
|
332
|
Chris@16
|
333 }}} //namespace boost { namespace container { namespace container_detail {
|
Chris@16
|
334
|
Chris@101
|
335 #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
336
|
Chris@16
|
337 #include <boost/container/detail/value_init.hpp>
|
Chris@16
|
338
|
Chris@16
|
339 namespace boost {
|
Chris@16
|
340 namespace container {
|
Chris@16
|
341 namespace container_detail {
|
Chris@16
|
342
|
Chris@101
|
343 #define BOOST_CONTAINER_ADVANCED_INSERT_INT_CODE(N) \
|
Chris@101
|
344 template< class Allocator, class Iterator BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
|
Chris@101
|
345 struct insert_nonmovable_emplace_proxy##N\
|
Chris@101
|
346 {\
|
Chris@101
|
347 typedef boost::container::allocator_traits<Allocator> alloc_traits;\
|
Chris@101
|
348 typedef typename alloc_traits::size_type size_type;\
|
Chris@101
|
349 typedef typename alloc_traits::value_type value_type;\
|
Chris@101
|
350 \
|
Chris@101
|
351 explicit insert_nonmovable_emplace_proxy##N(BOOST_MOVE_UREF##N)\
|
Chris@101
|
352 BOOST_MOVE_COLON##N BOOST_MOVE_FWD_INIT##N {}\
|
Chris@101
|
353 \
|
Chris@101
|
354 void uninitialized_copy_n_and_update(Allocator &a, Iterator p, size_type n)\
|
Chris@101
|
355 {\
|
Chris@101
|
356 BOOST_ASSERT(n == 1); (void)n;\
|
Chris@101
|
357 alloc_traits::construct(a, iterator_to_raw_pointer(p) BOOST_MOVE_I##N BOOST_MOVE_MFWD##N);\
|
Chris@101
|
358 }\
|
Chris@101
|
359 \
|
Chris@101
|
360 void copy_n_and_update(Allocator &, Iterator, size_type)\
|
Chris@101
|
361 { BOOST_ASSERT(false); }\
|
Chris@101
|
362 \
|
Chris@101
|
363 protected:\
|
Chris@101
|
364 BOOST_MOVE_MREF##N\
|
Chris@101
|
365 };\
|
Chris@101
|
366 \
|
Chris@101
|
367 template< class Allocator, class Iterator BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
|
Chris@101
|
368 struct insert_emplace_proxy_arg##N\
|
Chris@101
|
369 : insert_nonmovable_emplace_proxy##N< Allocator, Iterator BOOST_MOVE_I##N BOOST_MOVE_TARG##N >\
|
Chris@101
|
370 {\
|
Chris@101
|
371 typedef insert_nonmovable_emplace_proxy##N\
|
Chris@101
|
372 < Allocator, Iterator BOOST_MOVE_I##N BOOST_MOVE_TARG##N > base_t;\
|
Chris@101
|
373 typedef typename base_t::value_type value_type;\
|
Chris@101
|
374 typedef typename base_t::size_type size_type;\
|
Chris@101
|
375 typedef boost::container::allocator_traits<Allocator> alloc_traits;\
|
Chris@101
|
376 \
|
Chris@101
|
377 explicit insert_emplace_proxy_arg##N(BOOST_MOVE_UREF##N)\
|
Chris@101
|
378 : base_t(BOOST_MOVE_FWD##N){}\
|
Chris@101
|
379 \
|
Chris@101
|
380 void copy_n_and_update(Allocator &a, Iterator p, size_type n)\
|
Chris@101
|
381 {\
|
Chris@101
|
382 BOOST_ASSERT(n == 1); (void)n;\
|
Chris@101
|
383 typename aligned_storage<sizeof(value_type), alignment_of<value_type>::value>::type v;\
|
Chris@101
|
384 BOOST_ASSERT((((size_type)(&v)) % alignment_of<value_type>::value) == 0);\
|
Chris@101
|
385 value_type *vp = static_cast<value_type *>(static_cast<void *>(&v));\
|
Chris@101
|
386 alloc_traits::construct(a, vp BOOST_MOVE_I##N BOOST_MOVE_MFWD##N);\
|
Chris@101
|
387 BOOST_TRY{\
|
Chris@101
|
388 *p = ::boost::move(*vp);\
|
Chris@101
|
389 }\
|
Chris@101
|
390 BOOST_CATCH(...){\
|
Chris@101
|
391 alloc_traits::destroy(a, vp);\
|
Chris@101
|
392 BOOST_RETHROW\
|
Chris@101
|
393 }\
|
Chris@101
|
394 BOOST_CATCH_END\
|
Chris@101
|
395 alloc_traits::destroy(a, vp);\
|
Chris@101
|
396 }\
|
Chris@101
|
397 };\
|
Chris@101
|
398 //
|
Chris@101
|
399 BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_ADVANCED_INSERT_INT_CODE)
|
Chris@101
|
400 #undef BOOST_CONTAINER_ADVANCED_INSERT_INT_CODE
|
Chris@101
|
401
|
Chris@101
|
402 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@101
|
403
|
Chris@101
|
404 //Specializations to avoid an unneeded temporary when emplacing from a single argument o type value_type
|
Chris@101
|
405 template<class Allocator, class Iterator>
|
Chris@101
|
406 struct insert_emplace_proxy_arg1<Allocator, Iterator, ::boost::rv<typename boost::container::allocator_traits<Allocator>::value_type> >
|
Chris@101
|
407 : public insert_move_proxy<Allocator, Iterator>
|
Chris@101
|
408 {
|
Chris@101
|
409 explicit insert_emplace_proxy_arg1(typename boost::container::allocator_traits<Allocator>::value_type &v)
|
Chris@101
|
410 : insert_move_proxy<Allocator, Iterator>(v)
|
Chris@101
|
411 {}
|
Chris@101
|
412 };
|
Chris@101
|
413
|
Chris@101
|
414 template<class Allocator, class Iterator>
|
Chris@101
|
415 struct insert_emplace_proxy_arg1<Allocator, Iterator, typename boost::container::allocator_traits<Allocator>::value_type>
|
Chris@101
|
416 : public insert_copy_proxy<Allocator, Iterator>
|
Chris@101
|
417 {
|
Chris@101
|
418 explicit insert_emplace_proxy_arg1(const typename boost::container::allocator_traits<Allocator>::value_type &v)
|
Chris@101
|
419 : insert_copy_proxy<Allocator, Iterator>(v)
|
Chris@101
|
420 {}
|
Chris@101
|
421 };
|
Chris@101
|
422
|
Chris@101
|
423 #else //e.g. MSVC10 & MSVC11
|
Chris@101
|
424
|
Chris@101
|
425 //Specializations to avoid an unneeded temporary when emplacing from a single argument o type value_type
|
Chris@101
|
426 template<class Allocator, class Iterator>
|
Chris@101
|
427 struct insert_emplace_proxy_arg1<Allocator, Iterator, typename boost::container::allocator_traits<Allocator>::value_type>
|
Chris@101
|
428 : public insert_move_proxy<Allocator, Iterator>
|
Chris@101
|
429 {
|
Chris@101
|
430 explicit insert_emplace_proxy_arg1(typename boost::container::allocator_traits<Allocator>::value_type &&v)
|
Chris@101
|
431 : insert_move_proxy<Allocator, Iterator>(v)
|
Chris@101
|
432 {}
|
Chris@101
|
433 };
|
Chris@101
|
434
|
Chris@101
|
435 //We use "add_const" here as adding "const" only confuses MSVC10&11 provoking
|
Chris@101
|
436 //compiler error C2752 ("more than one partial specialization matches").
|
Chris@101
|
437 //Any problem is solvable with an extra layer of indirection? ;-)
|
Chris@101
|
438 template<class Allocator, class Iterator>
|
Chris@101
|
439 struct insert_emplace_proxy_arg1<Allocator, Iterator
|
Chris@101
|
440 , typename boost::container::container_detail::add_const<typename boost::container::allocator_traits<Allocator>::value_type>::type
|
Chris@101
|
441 >
|
Chris@101
|
442 : public insert_copy_proxy<Allocator, Iterator>
|
Chris@101
|
443 {
|
Chris@101
|
444 explicit insert_emplace_proxy_arg1(const typename boost::container::allocator_traits<Allocator>::value_type &v)
|
Chris@101
|
445 : insert_copy_proxy<Allocator, Iterator>(v)
|
Chris@101
|
446 {}
|
Chris@101
|
447 };
|
Chris@101
|
448
|
Chris@101
|
449 template<class Allocator, class Iterator>
|
Chris@101
|
450 struct insert_emplace_proxy_arg1<Allocator, Iterator, typename boost::container::allocator_traits<Allocator>::value_type &>
|
Chris@101
|
451 : public insert_copy_proxy<Allocator, Iterator>
|
Chris@101
|
452 {
|
Chris@101
|
453 explicit insert_emplace_proxy_arg1(const typename boost::container::allocator_traits<Allocator>::value_type &v)
|
Chris@101
|
454 : insert_copy_proxy<Allocator, Iterator>(v)
|
Chris@101
|
455 {}
|
Chris@101
|
456 };
|
Chris@101
|
457
|
Chris@101
|
458 template<class Allocator, class Iterator>
|
Chris@101
|
459 struct insert_emplace_proxy_arg1<Allocator, Iterator
|
Chris@101
|
460 , typename boost::container::container_detail::add_const<typename boost::container::allocator_traits<Allocator>::value_type>::type &
|
Chris@101
|
461 >
|
Chris@101
|
462 : public insert_copy_proxy<Allocator, Iterator>
|
Chris@101
|
463 {
|
Chris@101
|
464 explicit insert_emplace_proxy_arg1(const typename boost::container::allocator_traits<Allocator>::value_type &v)
|
Chris@101
|
465 : insert_copy_proxy<Allocator, Iterator>(v)
|
Chris@101
|
466 {}
|
Chris@101
|
467 };
|
Chris@101
|
468
|
Chris@101
|
469 #endif
|
Chris@16
|
470
|
Chris@16
|
471 }}} //namespace boost { namespace container { namespace container_detail {
|
Chris@16
|
472
|
Chris@101
|
473 #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
474
|
Chris@16
|
475 #include <boost/container/detail/config_end.hpp>
|
Chris@16
|
476
|
Chris@16
|
477 #endif //#ifndef BOOST_CONTAINER_ADVANCED_INSERT_INT_HPP
|