blob: 513dfc232cadde30622ed45aa8ab8157d45155b8 [file] [log] [blame]
Jeff Thompsonf7d49942013-08-01 16:47:40 -07001#ifndef BOOST_SMART_PTR_MAKE_SHARED_OBJECT_HPP_INCLUDED
2#define BOOST_SMART_PTR_MAKE_SHARED_OBJECT_HPP_INCLUDED
3
4// make_shared_object.hpp
5//
6// Copyright (c) 2007, 2008, 2012 Peter Dimov
7//
8// Distributed under the Boost Software License, Version 1.0.
9// See accompanying file LICENSE_1_0.txt or copy at
10// http://www.boost.org/LICENSE_1_0.txt
11//
12// See http://www.boost.org/libs/smart_ptr/make_shared.html
13// for documentation.
14
Jeff Thompson2277ce52013-08-01 17:34:11 -070015#include <ndnboost/config.hpp>
16#include <ndnboost/smart_ptr/shared_ptr.hpp>
17#include <ndnboost/smart_ptr/detail/sp_forward.hpp>
18#include <ndnboost/type_traits/type_with_alignment.hpp>
19#include <ndnboost/type_traits/alignment_of.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070020#include <cstddef>
21#include <new>
22
23namespace ndnboost
24{
25
26namespace detail
27{
28
29template< std::size_t N, std::size_t A > struct sp_aligned_storage
30{
31 union type
32 {
33 char data_[ N ];
34 typename ndnboost::type_with_alignment< A >::type align_;
35 };
36};
37
38template< class T > class sp_ms_deleter
39{
40private:
41
42 typedef typename sp_aligned_storage< sizeof( T ), ::ndnboost::alignment_of< T >::value >::type storage_type;
43
44 bool initialized_;
45 storage_type storage_;
46
47private:
48
49 void destroy()
50 {
51 if( initialized_ )
52 {
53#if defined( __GNUC__ )
54
55 // fixes incorrect aliasing warning
56 T * p = reinterpret_cast< T* >( storage_.data_ );
57 p->~T();
58
59#else
60
61 reinterpret_cast< T* >( storage_.data_ )->~T();
62
63#endif
64
65 initialized_ = false;
66 }
67 }
68
69public:
70
71 sp_ms_deleter() BOOST_NOEXCEPT : initialized_( false )
72 {
73 }
74
75 // optimization: do not copy storage_
76 sp_ms_deleter( sp_ms_deleter const & ) BOOST_NOEXCEPT : initialized_( false )
77 {
78 }
79
80 ~sp_ms_deleter()
81 {
82 destroy();
83 }
84
85 void operator()( T * )
86 {
87 destroy();
88 }
89
Jeff Thompsona28eed82013-08-22 16:21:10 -070090 static void operator_fn( T* ) // operator() can't be static
91 {
92 }
93
Jeff Thompsonf7d49942013-08-01 16:47:40 -070094 void * address() BOOST_NOEXCEPT
95 {
96 return storage_.data_;
97 }
98
99 void set_initialized() BOOST_NOEXCEPT
100 {
101 initialized_ = true;
102 }
103};
104
105template< class T > struct sp_if_not_array
106{
107 typedef ndnboost::shared_ptr< T > type;
108};
109
110#if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
111
112template< class T > struct sp_if_not_array< T[] >
113{
114};
115
116#if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
117
118template< class T, std::size_t N > struct sp_if_not_array< T[N] >
119{
120};
121
122#endif
123
124#endif
125
126} // namespace detail
127
128#if !defined( BOOST_NO_FUNCTION_TEMPLATE_ORDERING )
129# define BOOST_SP_MSD( T ) ndnboost::detail::sp_inplace_tag< ndnboost::detail::sp_ms_deleter< T > >()
130#else
131# define BOOST_SP_MSD( T ) ndnboost::detail::sp_ms_deleter< T >()
132#endif
133
134// Zero-argument versions
135//
136// Used even when variadic templates are available because of the new T() vs new T issue
137
138template< class T > typename ndnboost::detail::sp_if_not_array< T >::type make_shared()
139{
140 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
141
142 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
143
144 void * pv = pd->address();
145
146 ::new( pv ) T();
147 pd->set_initialized();
148
149 T * pt2 = static_cast< T* >( pv );
150
151 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
152 return ndnboost::shared_ptr< T >( pt, pt2 );
153}
154
155template< class T > typename ndnboost::detail::sp_if_not_array< T >::type make_shared_noinit()
156{
157 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
158
159 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
160
161 void * pv = pd->address();
162
163 ::new( pv ) T;
164 pd->set_initialized();
165
166 T * pt2 = static_cast< T* >( pv );
167
168 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
169 return ndnboost::shared_ptr< T >( pt, pt2 );
170}
171
172template< class T, class A > typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a )
173{
174 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
175
176 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
177
178 void * pv = pd->address();
179
180 ::new( pv ) T();
181 pd->set_initialized();
182
183 T * pt2 = static_cast< T* >( pv );
184
185 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
186 return ndnboost::shared_ptr< T >( pt, pt2 );
187}
188
189template< class T, class A > typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared_noinit( A const & a )
190{
191 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
192
193 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
194
195 void * pv = pd->address();
196
197 ::new( pv ) T;
198 pd->set_initialized();
199
200 T * pt2 = static_cast< T* >( pv );
201
202 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
203 return ndnboost::shared_ptr< T >( pt, pt2 );
204}
205
206#if !defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
207
208// Variadic templates, rvalue reference
209
210template< class T, class Arg1, class... Args > typename ndnboost::detail::sp_if_not_array< T >::type make_shared( Arg1 && arg1, Args && ... args )
211{
212 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
213
214 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
215
216 void * pv = pd->address();
217
218 ::new( pv ) T( ndnboost::detail::sp_forward<Arg1>( arg1 ), ndnboost::detail::sp_forward<Args>( args )... );
219 pd->set_initialized();
220
221 T * pt2 = static_cast< T* >( pv );
222
223 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
224 return ndnboost::shared_ptr< T >( pt, pt2 );
225}
226
227template< class T, class A, class Arg1, class... Args > typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, Arg1 && arg1, Args && ... args )
228{
229 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
230
231 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
232
233 void * pv = pd->address();
234
235 ::new( pv ) T( ndnboost::detail::sp_forward<Arg1>( arg1 ), ndnboost::detail::sp_forward<Args>( args )... );
236 pd->set_initialized();
237
238 T * pt2 = static_cast< T* >( pv );
239
240 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
241 return ndnboost::shared_ptr< T >( pt, pt2 );
242}
243
244#elif !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
245
246// For example MSVC 10.0
247
248template< class T, class A1 >
249typename ndnboost::detail::sp_if_not_array< T >::type make_shared( A1 && a1 )
250{
251 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
252
253 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
254
255 void * pv = pd->address();
256
257 ::new( pv ) T(
258 ndnboost::detail::sp_forward<A1>( a1 )
259 );
260
261 pd->set_initialized();
262
263 T * pt2 = static_cast< T* >( pv );
264
265 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
266 return ndnboost::shared_ptr< T >( pt, pt2 );
267}
268
269template< class T, class A, class A1 >
270typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 && a1 )
271{
272 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
273
274 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
275
276 void * pv = pd->address();
277
278 ::new( pv ) T(
279 ndnboost::detail::sp_forward<A1>( a1 )
280 );
281
282 pd->set_initialized();
283
284 T * pt2 = static_cast< T* >( pv );
285
286 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
287 return ndnboost::shared_ptr< T >( pt, pt2 );
288}
289
290template< class T, class A1, class A2 >
291typename ndnboost::detail::sp_if_not_array< T >::type make_shared( A1 && a1, A2 && a2 )
292{
293 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
294
295 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
296
297 void * pv = pd->address();
298
299 ::new( pv ) T(
300 ndnboost::detail::sp_forward<A1>( a1 ),
301 ndnboost::detail::sp_forward<A2>( a2 )
302 );
303
304 pd->set_initialized();
305
306 T * pt2 = static_cast< T* >( pv );
307
308 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
309 return ndnboost::shared_ptr< T >( pt, pt2 );
310}
311
312template< class T, class A, class A1, class A2 >
313typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 && a1, A2 && a2 )
314{
315 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
316
317 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
318
319 void * pv = pd->address();
320
321 ::new( pv ) T(
322 ndnboost::detail::sp_forward<A1>( a1 ),
323 ndnboost::detail::sp_forward<A2>( a2 )
324 );
325
326 pd->set_initialized();
327
328 T * pt2 = static_cast< T* >( pv );
329
330 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
331 return ndnboost::shared_ptr< T >( pt, pt2 );
332}
333
334template< class T, class A1, class A2, class A3 >
335typename ndnboost::detail::sp_if_not_array< T >::type make_shared( A1 && a1, A2 && a2, A3 && a3 )
336{
337 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
338
339 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
340
341 void * pv = pd->address();
342
343 ::new( pv ) T(
344 ndnboost::detail::sp_forward<A1>( a1 ),
345 ndnboost::detail::sp_forward<A2>( a2 ),
346 ndnboost::detail::sp_forward<A3>( a3 )
347 );
348
349 pd->set_initialized();
350
351 T * pt2 = static_cast< T* >( pv );
352
353 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
354 return ndnboost::shared_ptr< T >( pt, pt2 );
355}
356
357template< class T, class A, class A1, class A2, class A3 >
358typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 && a1, A2 && a2, A3 && a3 )
359{
360 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
361
362 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
363
364 void * pv = pd->address();
365
366 ::new( pv ) T(
367 ndnboost::detail::sp_forward<A1>( a1 ),
368 ndnboost::detail::sp_forward<A2>( a2 ),
369 ndnboost::detail::sp_forward<A3>( a3 )
370 );
371
372 pd->set_initialized();
373
374 T * pt2 = static_cast< T* >( pv );
375
376 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
377 return ndnboost::shared_ptr< T >( pt, pt2 );
378}
379
380template< class T, class A1, class A2, class A3, class A4 >
381typename ndnboost::detail::sp_if_not_array< T >::type make_shared( A1 && a1, A2 && a2, A3 && a3, A4 && a4 )
382{
383 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
384
385 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
386
387 void * pv = pd->address();
388
389 ::new( pv ) T(
390 ndnboost::detail::sp_forward<A1>( a1 ),
391 ndnboost::detail::sp_forward<A2>( a2 ),
392 ndnboost::detail::sp_forward<A3>( a3 ),
393 ndnboost::detail::sp_forward<A4>( a4 )
394 );
395
396 pd->set_initialized();
397
398 T * pt2 = static_cast< T* >( pv );
399
400 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
401 return ndnboost::shared_ptr< T >( pt, pt2 );
402}
403
404template< class T, class A, class A1, class A2, class A3, class A4 >
405typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 && a1, A2 && a2, A3 && a3, A4 && a4 )
406{
407 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
408
409 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
410
411 void * pv = pd->address();
412
413 ::new( pv ) T(
414 ndnboost::detail::sp_forward<A1>( a1 ),
415 ndnboost::detail::sp_forward<A2>( a2 ),
416 ndnboost::detail::sp_forward<A3>( a3 ),
417 ndnboost::detail::sp_forward<A4>( a4 )
418 );
419
420 pd->set_initialized();
421
422 T * pt2 = static_cast< T* >( pv );
423
424 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
425 return ndnboost::shared_ptr< T >( pt, pt2 );
426}
427
428template< class T, class A1, class A2, class A3, class A4, class A5 >
429typename ndnboost::detail::sp_if_not_array< T >::type make_shared( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5 )
430{
431 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
432
433 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
434
435 void * pv = pd->address();
436
437 ::new( pv ) T(
438 ndnboost::detail::sp_forward<A1>( a1 ),
439 ndnboost::detail::sp_forward<A2>( a2 ),
440 ndnboost::detail::sp_forward<A3>( a3 ),
441 ndnboost::detail::sp_forward<A4>( a4 ),
442 ndnboost::detail::sp_forward<A5>( a5 )
443 );
444
445 pd->set_initialized();
446
447 T * pt2 = static_cast< T* >( pv );
448
449 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
450 return ndnboost::shared_ptr< T >( pt, pt2 );
451}
452
453template< class T, class A, class A1, class A2, class A3, class A4, class A5 >
454typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5 )
455{
456 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
457
458 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
459
460 void * pv = pd->address();
461
462 ::new( pv ) T(
463 ndnboost::detail::sp_forward<A1>( a1 ),
464 ndnboost::detail::sp_forward<A2>( a2 ),
465 ndnboost::detail::sp_forward<A3>( a3 ),
466 ndnboost::detail::sp_forward<A4>( a4 ),
467 ndnboost::detail::sp_forward<A5>( a5 )
468 );
469
470 pd->set_initialized();
471
472 T * pt2 = static_cast< T* >( pv );
473
474 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
475 return ndnboost::shared_ptr< T >( pt, pt2 );
476}
477
478template< class T, class A1, class A2, class A3, class A4, class A5, class A6 >
479typename ndnboost::detail::sp_if_not_array< T >::type make_shared( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6 )
480{
481 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
482
483 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
484
485 void * pv = pd->address();
486
487 ::new( pv ) T(
488 ndnboost::detail::sp_forward<A1>( a1 ),
489 ndnboost::detail::sp_forward<A2>( a2 ),
490 ndnboost::detail::sp_forward<A3>( a3 ),
491 ndnboost::detail::sp_forward<A4>( a4 ),
492 ndnboost::detail::sp_forward<A5>( a5 ),
493 ndnboost::detail::sp_forward<A6>( a6 )
494 );
495
496 pd->set_initialized();
497
498 T * pt2 = static_cast< T* >( pv );
499
500 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
501 return ndnboost::shared_ptr< T >( pt, pt2 );
502}
503
504template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6 >
505typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6 )
506{
507 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
508
509 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
510
511 void * pv = pd->address();
512
513 ::new( pv ) T(
514 ndnboost::detail::sp_forward<A1>( a1 ),
515 ndnboost::detail::sp_forward<A2>( a2 ),
516 ndnboost::detail::sp_forward<A3>( a3 ),
517 ndnboost::detail::sp_forward<A4>( a4 ),
518 ndnboost::detail::sp_forward<A5>( a5 ),
519 ndnboost::detail::sp_forward<A6>( a6 )
520 );
521
522 pd->set_initialized();
523
524 T * pt2 = static_cast< T* >( pv );
525
526 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
527 return ndnboost::shared_ptr< T >( pt, pt2 );
528}
529
530template< class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7 >
531typename ndnboost::detail::sp_if_not_array< T >::type make_shared( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7 )
532{
533 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
534
535 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
536
537 void * pv = pd->address();
538
539 ::new( pv ) T(
540 ndnboost::detail::sp_forward<A1>( a1 ),
541 ndnboost::detail::sp_forward<A2>( a2 ),
542 ndnboost::detail::sp_forward<A3>( a3 ),
543 ndnboost::detail::sp_forward<A4>( a4 ),
544 ndnboost::detail::sp_forward<A5>( a5 ),
545 ndnboost::detail::sp_forward<A6>( a6 ),
546 ndnboost::detail::sp_forward<A7>( a7 )
547 );
548
549 pd->set_initialized();
550
551 T * pt2 = static_cast< T* >( pv );
552
553 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
554 return ndnboost::shared_ptr< T >( pt, pt2 );
555}
556
557template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6, class A7 >
558typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7 )
559{
560 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
561
562 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
563
564 void * pv = pd->address();
565
566 ::new( pv ) T(
567 ndnboost::detail::sp_forward<A1>( a1 ),
568 ndnboost::detail::sp_forward<A2>( a2 ),
569 ndnboost::detail::sp_forward<A3>( a3 ),
570 ndnboost::detail::sp_forward<A4>( a4 ),
571 ndnboost::detail::sp_forward<A5>( a5 ),
572 ndnboost::detail::sp_forward<A6>( a6 ),
573 ndnboost::detail::sp_forward<A7>( a7 )
574 );
575
576 pd->set_initialized();
577
578 T * pt2 = static_cast< T* >( pv );
579
580 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
581 return ndnboost::shared_ptr< T >( pt, pt2 );
582}
583
584template< class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8 >
585typename ndnboost::detail::sp_if_not_array< T >::type make_shared( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7, A8 && a8 )
586{
587 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
588
589 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
590
591 void * pv = pd->address();
592
593 ::new( pv ) T(
594 ndnboost::detail::sp_forward<A1>( a1 ),
595 ndnboost::detail::sp_forward<A2>( a2 ),
596 ndnboost::detail::sp_forward<A3>( a3 ),
597 ndnboost::detail::sp_forward<A4>( a4 ),
598 ndnboost::detail::sp_forward<A5>( a5 ),
599 ndnboost::detail::sp_forward<A6>( a6 ),
600 ndnboost::detail::sp_forward<A7>( a7 ),
601 ndnboost::detail::sp_forward<A8>( a8 )
602 );
603
604 pd->set_initialized();
605
606 T * pt2 = static_cast< T* >( pv );
607
608 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
609 return ndnboost::shared_ptr< T >( pt, pt2 );
610}
611
612template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8 >
613typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7, A8 && a8 )
614{
615 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
616
617 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
618
619 void * pv = pd->address();
620
621 ::new( pv ) T(
622 ndnboost::detail::sp_forward<A1>( a1 ),
623 ndnboost::detail::sp_forward<A2>( a2 ),
624 ndnboost::detail::sp_forward<A3>( a3 ),
625 ndnboost::detail::sp_forward<A4>( a4 ),
626 ndnboost::detail::sp_forward<A5>( a5 ),
627 ndnboost::detail::sp_forward<A6>( a6 ),
628 ndnboost::detail::sp_forward<A7>( a7 ),
629 ndnboost::detail::sp_forward<A8>( a8 )
630 );
631
632 pd->set_initialized();
633
634 T * pt2 = static_cast< T* >( pv );
635
636 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
637 return ndnboost::shared_ptr< T >( pt, pt2 );
638}
639
640template< class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9 >
641typename ndnboost::detail::sp_if_not_array< T >::type make_shared( A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7, A8 && a8, A9 && a9 )
642{
643 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
644
645 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
646
647 void * pv = pd->address();
648
649 ::new( pv ) T(
650 ndnboost::detail::sp_forward<A1>( a1 ),
651 ndnboost::detail::sp_forward<A2>( a2 ),
652 ndnboost::detail::sp_forward<A3>( a3 ),
653 ndnboost::detail::sp_forward<A4>( a4 ),
654 ndnboost::detail::sp_forward<A5>( a5 ),
655 ndnboost::detail::sp_forward<A6>( a6 ),
656 ndnboost::detail::sp_forward<A7>( a7 ),
657 ndnboost::detail::sp_forward<A8>( a8 ),
658 ndnboost::detail::sp_forward<A9>( a9 )
659 );
660
661 pd->set_initialized();
662
663 T * pt2 = static_cast< T* >( pv );
664
665 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
666 return ndnboost::shared_ptr< T >( pt, pt2 );
667}
668
669template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9 >
670typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 && a1, A2 && a2, A3 && a3, A4 && a4, A5 && a5, A6 && a6, A7 && a7, A8 && a8, A9 && a9 )
671{
672 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
673
674 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
675
676 void * pv = pd->address();
677
678 ::new( pv ) T(
679 ndnboost::detail::sp_forward<A1>( a1 ),
680 ndnboost::detail::sp_forward<A2>( a2 ),
681 ndnboost::detail::sp_forward<A3>( a3 ),
682 ndnboost::detail::sp_forward<A4>( a4 ),
683 ndnboost::detail::sp_forward<A5>( a5 ),
684 ndnboost::detail::sp_forward<A6>( a6 ),
685 ndnboost::detail::sp_forward<A7>( a7 ),
686 ndnboost::detail::sp_forward<A8>( a8 ),
687 ndnboost::detail::sp_forward<A9>( a9 )
688 );
689
690 pd->set_initialized();
691
692 T * pt2 = static_cast< T* >( pv );
693
694 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
695 return ndnboost::shared_ptr< T >( pt, pt2 );
696}
697
698#else
699
700// C++03 version
701
702template< class T, class A1 >
703typename ndnboost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1 )
704{
705 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
706
707 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
708
709 void * pv = pd->address();
710
711 ::new( pv ) T( a1 );
712 pd->set_initialized();
713
714 T * pt2 = static_cast< T* >( pv );
715
716 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
717 return ndnboost::shared_ptr< T >( pt, pt2 );
718}
719
720template< class T, class A, class A1 >
721typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 const & a1 )
722{
723 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
724
725 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
726
727 void * pv = pd->address();
728
729 ::new( pv ) T( a1 );
730 pd->set_initialized();
731
732 T * pt2 = static_cast< T* >( pv );
733
734 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
735 return ndnboost::shared_ptr< T >( pt, pt2 );
736}
737
738template< class T, class A1, class A2 >
739typename ndnboost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A2 const & a2 )
740{
741 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
742
743 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
744
745 void * pv = pd->address();
746
747 ::new( pv ) T( a1, a2 );
748 pd->set_initialized();
749
750 T * pt2 = static_cast< T* >( pv );
751
752 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
753 return ndnboost::shared_ptr< T >( pt, pt2 );
754}
755
756template< class T, class A, class A1, class A2 >
757typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 const & a1, A2 const & a2 )
758{
759 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
760
761 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
762
763 void * pv = pd->address();
764
765 ::new( pv ) T( a1, a2 );
766 pd->set_initialized();
767
768 T * pt2 = static_cast< T* >( pv );
769
770 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
771 return ndnboost::shared_ptr< T >( pt, pt2 );
772}
773
774template< class T, class A1, class A2, class A3 >
775typename ndnboost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A2 const & a2, A3 const & a3 )
776{
777 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
778
779 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
780
781 void * pv = pd->address();
782
783 ::new( pv ) T( a1, a2, a3 );
784 pd->set_initialized();
785
786 T * pt2 = static_cast< T* >( pv );
787
788 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
789 return ndnboost::shared_ptr< T >( pt, pt2 );
790}
791
792template< class T, class A, class A1, class A2, class A3 >
793typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3 )
794{
795 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
796
797 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
798
799 void * pv = pd->address();
800
801 ::new( pv ) T( a1, a2, a3 );
802 pd->set_initialized();
803
804 T * pt2 = static_cast< T* >( pv );
805
806 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
807 return ndnboost::shared_ptr< T >( pt, pt2 );
808}
809
810template< class T, class A1, class A2, class A3, class A4 >
811typename ndnboost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4 )
812{
813 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
814
815 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
816
817 void * pv = pd->address();
818
819 ::new( pv ) T( a1, a2, a3, a4 );
820 pd->set_initialized();
821
822 T * pt2 = static_cast< T* >( pv );
823
824 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
825 return ndnboost::shared_ptr< T >( pt, pt2 );
826}
827
828template< class T, class A, class A1, class A2, class A3, class A4 >
829typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4 )
830{
831 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
832
833 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
834
835 void * pv = pd->address();
836
837 ::new( pv ) T( a1, a2, a3, a4 );
838 pd->set_initialized();
839
840 T * pt2 = static_cast< T* >( pv );
841
842 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
843 return ndnboost::shared_ptr< T >( pt, pt2 );
844}
845
846template< class T, class A1, class A2, class A3, class A4, class A5 >
847typename ndnboost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5 )
848{
849 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
850
851 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
852
853 void * pv = pd->address();
854
855 ::new( pv ) T( a1, a2, a3, a4, a5 );
856 pd->set_initialized();
857
858 T * pt2 = static_cast< T* >( pv );
859
860 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
861 return ndnboost::shared_ptr< T >( pt, pt2 );
862}
863
864template< class T, class A, class A1, class A2, class A3, class A4, class A5 >
865typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5 )
866{
867 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
868
869 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
870
871 void * pv = pd->address();
872
873 ::new( pv ) T( a1, a2, a3, a4, a5 );
874 pd->set_initialized();
875
876 T * pt2 = static_cast< T* >( pv );
877
878 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
879 return ndnboost::shared_ptr< T >( pt, pt2 );
880}
881
882template< class T, class A1, class A2, class A3, class A4, class A5, class A6 >
883typename ndnboost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6 )
884{
885 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
886
887 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
888
889 void * pv = pd->address();
890
891 ::new( pv ) T( a1, a2, a3, a4, a5, a6 );
892 pd->set_initialized();
893
894 T * pt2 = static_cast< T* >( pv );
895
896 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
897 return ndnboost::shared_ptr< T >( pt, pt2 );
898}
899
900template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6 >
901typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6 )
902{
903 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
904
905 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
906
907 void * pv = pd->address();
908
909 ::new( pv ) T( a1, a2, a3, a4, a5, a6 );
910 pd->set_initialized();
911
912 T * pt2 = static_cast< T* >( pv );
913
914 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
915 return ndnboost::shared_ptr< T >( pt, pt2 );
916}
917
918template< class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7 >
919typename ndnboost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6, A7 const & a7 )
920{
921 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
922
923 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
924
925 void * pv = pd->address();
926
927 ::new( pv ) T( a1, a2, a3, a4, a5, a6, a7 );
928 pd->set_initialized();
929
930 T * pt2 = static_cast< T* >( pv );
931
932 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
933 return ndnboost::shared_ptr< T >( pt, pt2 );
934}
935
936template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6, class A7 >
937typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6, A7 const & a7 )
938{
939 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
940
941 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
942
943 void * pv = pd->address();
944
945 ::new( pv ) T( a1, a2, a3, a4, a5, a6, a7 );
946 pd->set_initialized();
947
948 T * pt2 = static_cast< T* >( pv );
949
950 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
951 return ndnboost::shared_ptr< T >( pt, pt2 );
952}
953
954template< class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8 >
955typename ndnboost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6, A7 const & a7, A8 const & a8 )
956{
957 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
958
959 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
960
961 void * pv = pd->address();
962
963 ::new( pv ) T( a1, a2, a3, a4, a5, a6, a7, a8 );
964 pd->set_initialized();
965
966 T * pt2 = static_cast< T* >( pv );
967
968 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
969 return ndnboost::shared_ptr< T >( pt, pt2 );
970}
971
972template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8 >
973typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6, A7 const & a7, A8 const & a8 )
974{
975 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
976
977 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
978
979 void * pv = pd->address();
980
981 ::new( pv ) T( a1, a2, a3, a4, a5, a6, a7, a8 );
982 pd->set_initialized();
983
984 T * pt2 = static_cast< T* >( pv );
985
986 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
987 return ndnboost::shared_ptr< T >( pt, pt2 );
988}
989
990template< class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9 >
991typename ndnboost::detail::sp_if_not_array< T >::type make_shared( A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6, A7 const & a7, A8 const & a8, A9 const & a9 )
992{
993 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) );
994
995 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
996
997 void * pv = pd->address();
998
999 ::new( pv ) T( a1, a2, a3, a4, a5, a6, a7, a8, a9 );
1000 pd->set_initialized();
1001
1002 T * pt2 = static_cast< T* >( pv );
1003
1004 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
1005 return ndnboost::shared_ptr< T >( pt, pt2 );
1006}
1007
1008template< class T, class A, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9 >
1009typename ndnboost::detail::sp_if_not_array< T >::type allocate_shared( A const & a, A1 const & a1, A2 const & a2, A3 const & a3, A4 const & a4, A5 const & a5, A6 const & a6, A7 const & a7, A8 const & a8, A9 const & a9 )
1010{
1011 ndnboost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ), a );
1012
1013 ndnboost::detail::sp_ms_deleter< T > * pd = static_cast<ndnboost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() );
1014
1015 void * pv = pd->address();
1016
1017 ::new( pv ) T( a1, a2, a3, a4, a5, a6, a7, a8, a9 );
1018 pd->set_initialized();
1019
1020 T * pt2 = static_cast< T* >( pv );
1021
1022 ndnboost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
1023 return ndnboost::shared_ptr< T >( pt, pt2 );
1024}
1025
1026#endif
1027
1028#undef BOOST_SP_MSD
1029
1030} // namespace ndnboost
1031
1032#endif // #ifndef BOOST_SMART_PTR_MAKE_SHARED_OBJECT_HPP_INCLUDED