~ubuntu-branches/ubuntu/wily/davix/wily

« back to all changes in this revision

Viewing changes to deps/boost_intern/boost/container/detail/advanced_insert_int.hpp

  • Committer: Package Import Robot
  • Author(s): Mattias Ellert
  • Date: 2015-07-31 13:17:55 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20150731131755-mizprbmn7ogv33te
Tags: 0.4.1-1
* Update to version 0.4.1
* Implement Multi-Arch support

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//////////////////////////////////////////////////////////////////////////////
2
 
//
3
 
// (C) Copyright Ion Gaztanaga 2008-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/container for documentation.
8
 
//
9
 
//////////////////////////////////////////////////////////////////////////////
10
 
 
11
 
#ifndef BOOST_CONTAINER_ADVANCED_INSERT_INT_HPP
12
 
#define BOOST_CONTAINER_ADVANCED_INSERT_INT_HPP
13
 
 
14
 
#if defined(_MSC_VER)
15
 
#  pragma once
16
 
#endif
17
 
 
18
 
#include "config_begin.hpp"
19
 
#include <boost/container/detail/workaround.hpp>
20
 
#include <boost/container/allocator_traits.hpp>
21
 
#include <boost/container/detail/destroyers.hpp>
22
 
#include <boost/aligned_storage.hpp>
23
 
#include <boost/move/utility.hpp>
24
 
#include <iterator>  //std::iterator_traits
25
 
#include <boost/assert.hpp>
26
 
#include <boost/detail/no_exceptions_support.hpp>
27
 
 
28
 
namespace boost { namespace container { namespace container_detail {
29
 
 
30
 
template<class A, class FwdIt, class Iterator>
31
 
struct move_insert_range_proxy
32
 
{
33
 
   typedef typename allocator_traits<A>::size_type size_type;
34
 
   typedef typename allocator_traits<A>::value_type value_type;
35
 
 
36
 
   move_insert_range_proxy(A& a, FwdIt first)
37
 
      :  a_(a), first_(first)
38
 
   {}
39
 
 
40
 
   void uninitialized_copy_n_and_update(Iterator p, size_type n)
41
 
   {
42
 
      this->first_ = ::boost::container::uninitialized_move_alloc_n_source
43
 
         (this->a_, this->first_, n, p);
44
 
   }
45
 
 
46
 
   void copy_n_and_update(Iterator p, size_type n)
47
 
   {
48
 
      this->first_ = ::boost::container::move_n_source(this->first_, n, p);
49
 
   }
50
 
 
51
 
   A &a_;
52
 
   FwdIt first_;
53
 
};
54
 
 
55
 
 
56
 
template<class A, class FwdIt, class Iterator>
57
 
struct insert_range_proxy
58
 
{
59
 
   typedef typename allocator_traits<A>::size_type size_type;
60
 
   typedef typename allocator_traits<A>::value_type value_type;
61
 
 
62
 
   insert_range_proxy(A& a, FwdIt first)
63
 
      :  a_(a), first_(first)
64
 
   {}
65
 
 
66
 
   void uninitialized_copy_n_and_update(Iterator p, size_type n)
67
 
   {
68
 
      this->first_ = ::boost::container::uninitialized_copy_alloc_n_source(this->a_, this->first_, n, p);
69
 
   }
70
 
 
71
 
   void copy_n_and_update(Iterator p, size_type n)
72
 
   {
73
 
      this->first_ = ::boost::container::copy_n_source(this->first_, n, p);
74
 
   }
75
 
 
76
 
   A &a_;
77
 
   FwdIt first_;
78
 
};
79
 
 
80
 
 
81
 
template<class A, class Iterator>
82
 
struct insert_n_copies_proxy
83
 
{
84
 
   typedef typename allocator_traits<A>::size_type size_type;
85
 
   typedef typename allocator_traits<A>::value_type value_type;
86
 
 
87
 
   insert_n_copies_proxy(A& a, const value_type &v)
88
 
      :  a_(a), v_(v)
89
 
   {}
90
 
 
91
 
   void uninitialized_copy_n_and_update(Iterator p, size_type n) const
92
 
   {  boost::container::uninitialized_fill_alloc_n(this->a_, v_, n, p);  }
93
 
 
94
 
   void copy_n_and_update(Iterator p, size_type n) const
95
 
   {  std::fill_n(p, n, v_);  }
96
 
 
97
 
   A &a_;
98
 
   const value_type &v_;
99
 
};
100
 
 
101
 
template<class A, class Iterator>
102
 
struct insert_value_initialized_n_proxy
103
 
{
104
 
   typedef ::boost::container::allocator_traits<A> alloc_traits;
105
 
   typedef typename allocator_traits<A>::size_type size_type;
106
 
   typedef typename allocator_traits<A>::value_type value_type;
107
 
 
108
 
 
109
 
   explicit insert_value_initialized_n_proxy(A &a)
110
 
      :  a_(a)
111
 
   {}
112
 
 
113
 
   void uninitialized_copy_n_and_update(Iterator p, size_type n) const
114
 
   {  boost::container::uninitialized_value_init_alloc_n(this->a_, n, p);  }
115
 
 
116
 
   void copy_n_and_update(Iterator, size_type) const
117
 
   {
118
 
      BOOST_ASSERT(false);
119
 
   }
120
 
 
121
 
   private:
122
 
   A &a_;
123
 
};
124
 
 
125
 
template<class A, class Iterator>
126
 
struct insert_default_initialized_n_proxy
127
 
{
128
 
   typedef ::boost::container::allocator_traits<A> alloc_traits;
129
 
   typedef typename allocator_traits<A>::size_type size_type;
130
 
   typedef typename allocator_traits<A>::value_type value_type;
131
 
 
132
 
 
133
 
   explicit insert_default_initialized_n_proxy(A &a)
134
 
      :  a_(a)
135
 
   {}
136
 
 
137
 
   void uninitialized_copy_n_and_update(Iterator p, size_type n) const
138
 
   {  boost::container::uninitialized_default_init_alloc_n(this->a_, n, p);  }
139
 
 
140
 
   void copy_n_and_update(Iterator, size_type) const
141
 
   {
142
 
      BOOST_ASSERT(false);
143
 
   }
144
 
 
145
 
   private:
146
 
   A &a_;
147
 
};
148
 
 
149
 
template<class A, class Iterator>
150
 
struct insert_copy_proxy
151
 
{
152
 
   typedef boost::container::allocator_traits<A> alloc_traits;
153
 
   typedef typename alloc_traits::size_type size_type;
154
 
   typedef typename alloc_traits::value_type value_type;
155
 
 
156
 
   insert_copy_proxy(A& a, const value_type &v)
157
 
      :  a_(a), v_(v)
158
 
   {}
159
 
 
160
 
   void uninitialized_copy_n_and_update(Iterator p, size_type n) const
161
 
   {
162
 
      BOOST_ASSERT(n == 1);  (void)n;
163
 
      alloc_traits::construct( this->a_
164
 
                              , container_detail::to_raw_pointer(&*p)
165
 
                              , v_
166
 
                              );
167
 
   }
168
 
 
169
 
   void copy_n_and_update(Iterator p, size_type n) const
170
 
   {
171
 
      BOOST_ASSERT(n == 1);  (void)n;
172
 
      *p =v_;
173
 
   }
174
 
 
175
 
   A &a_;
176
 
   const value_type &v_;
177
 
};
178
 
 
179
 
 
180
 
template<class A, class Iterator>
181
 
struct insert_move_proxy
182
 
{
183
 
   typedef boost::container::allocator_traits<A> alloc_traits;
184
 
   typedef typename alloc_traits::size_type size_type;
185
 
   typedef typename alloc_traits::value_type value_type;
186
 
 
187
 
   insert_move_proxy(A& a, value_type &v)
188
 
      :  a_(a), v_(v)
189
 
   {}
190
 
 
191
 
   void uninitialized_copy_n_and_update(Iterator p, size_type n) const
192
 
   {
193
 
      BOOST_ASSERT(n == 1);  (void)n;
194
 
      alloc_traits::construct( this->a_
195
 
                              , container_detail::to_raw_pointer(&*p)
196
 
                              , ::boost::move(v_)
197
 
                              );
198
 
   }
199
 
 
200
 
   void copy_n_and_update(Iterator p, size_type n) const
201
 
   {
202
 
      BOOST_ASSERT(n == 1);  (void)n;
203
 
      *p = ::boost::move(v_);
204
 
   }
205
 
 
206
 
   A &a_;
207
 
   value_type &v_;
208
 
};
209
 
 
210
 
template<class It, class A>
211
 
insert_move_proxy<A, It> get_insert_value_proxy(A& a, BOOST_RV_REF(typename std::iterator_traits<It>::value_type) v)
212
 
{
213
 
   return insert_move_proxy<A, It>(a, v);
214
 
}
215
 
 
216
 
template<class It, class A>
217
 
insert_copy_proxy<A, It> get_insert_value_proxy(A& a, const typename std::iterator_traits<It>::value_type &v)
218
 
{
219
 
   return insert_copy_proxy<A, It>(a, v);
220
 
}
221
 
 
222
 
}}}   //namespace boost { namespace container { namespace container_detail {
223
 
 
224
 
#ifdef BOOST_CONTAINER_PERFECT_FORWARDING
225
 
 
226
 
#include <boost/container/detail/variadic_templates_tools.hpp>
227
 
#include <boost/move/utility.hpp>
228
 
#include <typeinfo>
229
 
//#include <iostream> //For debugging purposes
230
 
 
231
 
namespace boost {
232
 
namespace container {
233
 
namespace container_detail {
234
 
 
235
 
template<class A, class Iterator, class ...Args>
236
 
struct insert_non_movable_emplace_proxy
237
 
{
238
 
   typedef boost::container::allocator_traits<A>   alloc_traits;
239
 
   typedef typename alloc_traits::size_type        size_type;
240
 
   typedef typename alloc_traits::value_type       value_type;
241
 
 
242
 
   typedef typename build_number_seq<sizeof...(Args)>::type index_tuple_t;
243
 
 
244
 
   explicit insert_non_movable_emplace_proxy(A &a, Args&&... args)
245
 
      : a_(a), args_(args...)
246
 
   {}
247
 
 
248
 
   void uninitialized_copy_n_and_update(Iterator p, size_type n)
249
 
   {  this->priv_uninitialized_copy_some_and_update(index_tuple_t(), p, n);  }
250
 
 
251
 
   private:
252
 
   template<int ...IdxPack>
253
 
   void priv_uninitialized_copy_some_and_update(const index_tuple<IdxPack...>&, Iterator p, size_type n)
254
 
   {
255
 
      BOOST_ASSERT(n == 1); (void)n;
256
 
      alloc_traits::construct( this->a_
257
 
                              , container_detail::to_raw_pointer(&*p)
258
 
                              , ::boost::forward<Args>(get<IdxPack>(this->args_))...
259
 
                              );
260
 
   }
261
 
 
262
 
   protected:
263
 
   A &a_;
264
 
   tuple<Args&...> args_;
265
 
};
266
 
 
267
 
template<class A, class Iterator, class ...Args>
268
 
struct insert_emplace_proxy
269
 
   :  public insert_non_movable_emplace_proxy<A, Iterator, Args...>
270
 
{
271
 
   typedef insert_non_movable_emplace_proxy<A, Iterator, Args...> base_t;
272
 
   typedef boost::container::allocator_traits<A>   alloc_traits;
273
 
   typedef typename base_t::value_type             value_type;
274
 
   typedef typename base_t::size_type              size_type;
275
 
   typedef typename base_t::index_tuple_t          index_tuple_t;
276
 
 
277
 
   explicit insert_emplace_proxy(A &a, Args&&... args)
278
 
      : base_t(a, ::boost::forward<Args>(args)...)
279
 
   {}
280
 
 
281
 
   void copy_n_and_update(Iterator p, size_type n)
282
 
   {  this->priv_copy_some_and_update(index_tuple_t(), p, n);  }
283
 
 
284
 
   private:
285
 
 
286
 
   template<int ...IdxPack>
287
 
   void priv_copy_some_and_update(const index_tuple<IdxPack...>&, Iterator p, size_type n)
288
 
   {
289
 
      BOOST_ASSERT(n ==1); (void)n;
290
 
      aligned_storage<sizeof(value_type), alignment_of<value_type>::value> v;
291
 
      value_type *vp = static_cast<value_type *>(static_cast<void *>(&v));
292
 
      alloc_traits::construct(this->a_, vp,
293
 
         ::boost::forward<Args>(get<IdxPack>(this->args_))...);
294
 
      BOOST_TRY{
295
 
         *p = ::boost::move(*vp);
296
 
      }
297
 
      BOOST_CATCH(...){
298
 
         alloc_traits::destroy(this->a_, vp);
299
 
         BOOST_RETHROW
300
 
      }
301
 
      BOOST_CATCH_END
302
 
      alloc_traits::destroy(this->a_, vp);
303
 
   }
304
 
};
305
 
 
306
 
}}}   //namespace boost { namespace container { namespace container_detail {
307
 
 
308
 
#else //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING
309
 
 
310
 
#include <boost/container/detail/preprocessor.hpp>
311
 
#include <boost/container/detail/value_init.hpp>
312
 
 
313
 
namespace boost {
314
 
namespace container {
315
 
namespace container_detail {
316
 
 
317
 
#define BOOST_PP_LOCAL_MACRO(N)                                                     \
318
 
template<class A, class Iterator BOOST_PP_ENUM_TRAILING_PARAMS(N, class P) >        \
319
 
struct BOOST_PP_CAT(insert_non_movable_emplace_proxy_arg, N)                        \
320
 
{                                                                                   \
321
 
   typedef boost::container::allocator_traits<A> alloc_traits;                      \
322
 
   typedef typename alloc_traits::size_type size_type;                              \
323
 
   typedef typename alloc_traits::value_type value_type;                            \
324
 
                                                                                    \
325
 
   BOOST_PP_CAT(insert_non_movable_emplace_proxy_arg, N)                            \
326
 
      ( A &a BOOST_PP_ENUM_TRAILING(N, BOOST_CONTAINER_PP_PARAM_LIST, _) )          \
327
 
      : a_(a)                                                                       \
328
 
      BOOST_PP_ENUM_TRAILING(N, BOOST_CONTAINER_PP_PARAM_INIT, _)                   \
329
 
   {}                                                                               \
330
 
                                                                                    \
331
 
   void uninitialized_copy_n_and_update(Iterator p, size_type n)                    \
332
 
   {                                                                                \
333
 
      BOOST_ASSERT(n == 1); (void)n;                                                \
334
 
      alloc_traits::construct                                                       \
335
 
         ( this->a_                                                                 \
336
 
         , container_detail::to_raw_pointer(&*p)                                    \
337
 
         BOOST_PP_ENUM_TRAILING(N, BOOST_CONTAINER_PP_MEMBER_FORWARD, _)            \
338
 
         );                                                                         \
339
 
   }                                                                                \
340
 
                                                                                    \
341
 
   void copy_n_and_update(Iterator, size_type)                                      \
342
 
   {  BOOST_ASSERT(false);   }                                                      \
343
 
                                                                                    \
344
 
   protected:                                                                       \
345
 
   A &a_;                                                                           \
346
 
   BOOST_PP_REPEAT(N, BOOST_CONTAINER_PP_PARAM_DEFINE, _)                           \
347
 
};                                                                                  \
348
 
                                                                                    \
349
 
template<class A, class Iterator BOOST_PP_ENUM_TRAILING_PARAMS(N, class P) >        \
350
 
struct BOOST_PP_CAT(insert_emplace_proxy_arg, N)                                    \
351
 
   : BOOST_PP_CAT(insert_non_movable_emplace_proxy_arg, N)                          \
352
 
         < A, Iterator BOOST_PP_ENUM_TRAILING_PARAMS(N, P) >                        \
353
 
{                                                                                   \
354
 
   typedef BOOST_PP_CAT(insert_non_movable_emplace_proxy_arg, N)                    \
355
 
         <A, Iterator BOOST_PP_ENUM_TRAILING_PARAMS(N, P) > base_t;                 \
356
 
   typedef typename base_t::value_type       value_type;                            \
357
 
   typedef typename base_t::size_type  size_type;                                   \
358
 
   typedef boost::container::allocator_traits<A> alloc_traits;                      \
359
 
                                                                                    \
360
 
   BOOST_PP_CAT(insert_emplace_proxy_arg, N)                                        \
361
 
      ( A &a BOOST_PP_ENUM_TRAILING(N, BOOST_CONTAINER_PP_PARAM_LIST, _) )          \
362
 
      : base_t(a BOOST_PP_ENUM_TRAILING(N, BOOST_CONTAINER_PP_PARAM_FORWARD, _) )   \
363
 
   {}                                                                               \
364
 
                                                                                    \
365
 
   void copy_n_and_update(Iterator p, size_type n)                                  \
366
 
   {                                                                                \
367
 
      BOOST_ASSERT(n == 1); (void)n;                                                \
368
 
      aligned_storage<sizeof(value_type), alignment_of<value_type>::value> v;       \
369
 
      value_type *vp = static_cast<value_type *>(static_cast<void *>(&v));          \
370
 
      alloc_traits::construct(this->a_, vp                                          \
371
 
         BOOST_PP_ENUM_TRAILING(N, BOOST_CONTAINER_PP_MEMBER_FORWARD, _));          \
372
 
      BOOST_TRY{                                                                    \
373
 
         *p = ::boost::move(*vp);                                                   \
374
 
      }                                                                             \
375
 
      BOOST_CATCH(...){                                                             \
376
 
         alloc_traits::destroy(this->a_, vp);                                       \
377
 
         BOOST_RETHROW                                                              \
378
 
      }                                                                             \
379
 
      BOOST_CATCH_END                                                               \
380
 
      alloc_traits::destroy(this->a_, vp);                                          \
381
 
   }                                                                                \
382
 
};                                                                                  \
383
 
//!
384
 
#define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS)
385
 
#include BOOST_PP_LOCAL_ITERATE()
386
 
 
387
 
}}}   //namespace boost { namespace container { namespace container_detail {
388
 
 
389
 
#endif   //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING
390
 
 
391
 
#include <boost/container/detail/config_end.hpp>
392
 
 
393
 
#endif //#ifndef BOOST_CONTAINER_ADVANCED_INSERT_INT_HPP