Publishing R3
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / common / boost / 1.64.0 / include / boost-1_64 / boost / smart_ptr / shared_ptr.hpp
1 #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
2 #define BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
3
4 //
5 //  shared_ptr.hpp
6 //
7 //  (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
8 //  Copyright (c) 2001-2008 Peter Dimov
9 //
10 //  Distributed under the Boost Software License, Version 1.0. (See
11 //  accompanying file LICENSE_1_0.txt or copy at
12 //  http://www.boost.org/LICENSE_1_0.txt)
13 //
14 //  See http://www.boost.org/libs/smart_ptr/shared_ptr.htm for documentation.
15 //
16
17 #include <boost/config.hpp>   // for broken compiler workarounds
18
19 // In order to avoid circular dependencies with Boost.TR1
20 // we make sure that our include of <memory> doesn't try to
21 // pull in the TR1 headers: that's why we use this header 
22 // rather than including <memory> directly:
23 #include <boost/config/no_tr1/memory.hpp>  // std::auto_ptr
24
25 #include <boost/assert.hpp>
26 #include <boost/checked_delete.hpp>
27 #include <boost/throw_exception.hpp>
28 #include <boost/smart_ptr/detail/shared_count.hpp>
29 #include <boost/detail/workaround.hpp>
30 #include <boost/smart_ptr/detail/sp_convertible.hpp>
31 #include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
32 #include <boost/smart_ptr/detail/sp_disable_deprecated.hpp>
33 #include <boost/smart_ptr/detail/sp_noexcept.hpp>
34
35 #if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
36 #include <boost/smart_ptr/detail/spinlock_pool.hpp>
37 #endif
38
39 #include <algorithm>            // for std::swap
40 #include <functional>           // for std::less
41 #include <typeinfo>             // for std::bad_cast
42 #include <cstddef>              // for std::size_t
43
44 #if !defined(BOOST_NO_IOSTREAM)
45 #if !defined(BOOST_NO_IOSFWD)
46 #include <iosfwd>               // for std::basic_ostream
47 #else
48 #include <ostream>
49 #endif
50 #endif
51
52 #if defined( BOOST_SP_DISABLE_DEPRECATED )
53 #pragma GCC diagnostic push
54 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
55 #endif
56
57 namespace boost
58 {
59
60 template<class T> class shared_ptr;
61 template<class T> class weak_ptr;
62 template<class T> class enable_shared_from_this;
63 class enable_shared_from_raw;
64
65 namespace movelib
66 {
67
68     template< class T, class D > class unique_ptr;
69
70 } // namespace movelib
71
72 namespace detail
73 {
74
75 // sp_element, element_type
76
77 template< class T > struct sp_element
78 {
79     typedef T type;
80 };
81
82 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
83
84 template< class T > struct sp_element< T[] >
85 {
86     typedef T type;
87 };
88
89 #if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
90
91 template< class T, std::size_t N > struct sp_element< T[N] >
92 {
93     typedef T type;
94 };
95
96 #endif
97
98 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
99
100 // sp_dereference, return type of operator*
101
102 template< class T > struct sp_dereference
103 {
104     typedef T & type;
105 };
106
107 template<> struct sp_dereference< void >
108 {
109     typedef void type;
110 };
111
112 #if !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS)
113
114 template<> struct sp_dereference< void const >
115 {
116     typedef void type;
117 };
118
119 template<> struct sp_dereference< void volatile >
120 {
121     typedef void type;
122 };
123
124 template<> struct sp_dereference< void const volatile >
125 {
126     typedef void type;
127 };
128
129 #endif // !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS)
130
131 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
132
133 template< class T > struct sp_dereference< T[] >
134 {
135     typedef void type;
136 };
137
138 #if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
139
140 template< class T, std::size_t N > struct sp_dereference< T[N] >
141 {
142     typedef void type;
143 };
144
145 #endif
146
147 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
148
149 // sp_member_access, return type of operator->
150
151 template< class T > struct sp_member_access
152 {
153     typedef T * type;
154 };
155
156 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
157
158 template< class T > struct sp_member_access< T[] >
159 {
160     typedef void type;
161 };
162
163 #if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
164
165 template< class T, std::size_t N > struct sp_member_access< T[N] >
166 {
167     typedef void type;
168 };
169
170 #endif
171
172 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
173
174 // sp_array_access, return type of operator[]
175
176 template< class T > struct sp_array_access
177 {
178     typedef void type;
179 };
180
181 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
182
183 template< class T > struct sp_array_access< T[] >
184 {
185     typedef T & type;
186 };
187
188 #if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
189
190 template< class T, std::size_t N > struct sp_array_access< T[N] >
191 {
192     typedef T & type;
193 };
194
195 #endif
196
197 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
198
199 // sp_extent, for operator[] index check
200
201 template< class T > struct sp_extent
202 {
203     enum _vt { value = 0 };
204 };
205
206 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
207
208 template< class T, std::size_t N > struct sp_extent< T[N] >
209 {
210     enum _vt { value = N };
211 };
212
213 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
214
215 // enable_shared_from_this support
216
217 template< class X, class Y, class T > inline void sp_enable_shared_from_this( boost::shared_ptr<X> const * ppx, Y const * py, boost::enable_shared_from_this< T > const * pe )
218 {
219     if( pe != 0 )
220     {
221         pe->_internal_accept_owner( ppx, const_cast< Y* >( py ) );
222     }
223 }
224
225 template< class X, class Y > inline void sp_enable_shared_from_this( boost::shared_ptr<X> * ppx, Y const * py, boost::enable_shared_from_raw const * pe );
226
227 #ifdef _MANAGED
228
229 // Avoid C4793, ... causes native code generation
230
231 struct sp_any_pointer
232 {
233     template<class T> sp_any_pointer( T* ) {}
234 };
235
236 inline void sp_enable_shared_from_this( sp_any_pointer, sp_any_pointer, sp_any_pointer )
237 {
238 }
239
240 #else // _MANAGED
241
242 inline void sp_enable_shared_from_this( ... )
243 {
244 }
245
246 #endif // _MANAGED
247
248 #if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) && !defined( BOOST_NO_AUTO_PTR )
249
250 // rvalue auto_ptr support based on a technique by Dave Abrahams
251
252 template< class T, class R > struct sp_enable_if_auto_ptr
253 {
254 };
255
256 template< class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr< T >, R >
257 {
258     typedef R type;
259 }; 
260
261 #endif
262
263 // sp_assert_convertible
264
265 template< class Y, class T > inline void sp_assert_convertible()
266 {
267 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
268
269     // static_assert( sp_convertible< Y, T >::value );
270     typedef char tmp[ sp_convertible< Y, T >::value? 1: -1 ];
271     (void)sizeof( tmp );
272
273 #else
274
275     T* p = static_cast< Y* >( 0 );
276     (void)p;
277
278 #endif
279 }
280
281 // pointer constructor helper
282
283 template< class T, class Y > inline void sp_pointer_construct( boost::shared_ptr< T > * ppx, Y * p, boost::detail::shared_count & pn )
284 {
285     boost::detail::shared_count( p ).swap( pn );
286     boost::detail::sp_enable_shared_from_this( ppx, p, p );
287 }
288
289 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
290
291 template< class T, class Y > inline void sp_pointer_construct( boost::shared_ptr< T[] > * /*ppx*/, Y * p, boost::detail::shared_count & pn )
292 {
293     sp_assert_convertible< Y[], T[] >();
294     boost::detail::shared_count( p, boost::checked_array_deleter< T >() ).swap( pn );
295 }
296
297 template< class T, std::size_t N, class Y > inline void sp_pointer_construct( boost::shared_ptr< T[N] > * /*ppx*/, Y * p, boost::detail::shared_count & pn )
298 {
299     sp_assert_convertible< Y[N], T[N] >();
300     boost::detail::shared_count( p, boost::checked_array_deleter< T >() ).swap( pn );
301 }
302
303 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
304
305 // deleter constructor helper
306
307 template< class T, class Y > inline void sp_deleter_construct( boost::shared_ptr< T > * ppx, Y * p )
308 {
309     boost::detail::sp_enable_shared_from_this( ppx, p, p );
310 }
311
312 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
313
314 template< class T, class Y > inline void sp_deleter_construct( boost::shared_ptr< T[] > * /*ppx*/, Y * /*p*/ )
315 {
316     sp_assert_convertible< Y[], T[] >();
317 }
318
319 template< class T, std::size_t N, class Y > inline void sp_deleter_construct( boost::shared_ptr< T[N] > * /*ppx*/, Y * /*p*/ )
320 {
321     sp_assert_convertible< Y[N], T[N] >();
322 }
323
324 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
325
326 } // namespace detail
327
328
329 //
330 //  shared_ptr
331 //
332 //  An enhanced relative of scoped_ptr with reference counted copy semantics.
333 //  The object pointed to is deleted when the last shared_ptr pointing to it
334 //  is destroyed or reset.
335 //
336
337 template<class T> class shared_ptr
338 {
339 private:
340
341     // Borland 5.5.1 specific workaround
342     typedef shared_ptr<T> this_type;
343
344 public:
345
346     typedef typename boost::detail::sp_element< T >::type element_type;
347
348     shared_ptr() BOOST_SP_NOEXCEPT : px( 0 ), pn() // never throws in 1.30+
349     {
350     }
351
352 #if !defined( BOOST_NO_CXX11_NULLPTR )
353
354     shared_ptr( boost::detail::sp_nullptr_t ) BOOST_SP_NOEXCEPT : px( 0 ), pn() // never throws
355     {
356     }
357
358 #endif
359
360     template<class Y>
361     explicit shared_ptr( Y * p ): px( p ), pn() // Y must be complete
362     {
363         boost::detail::sp_pointer_construct( this, p, pn );
364     }
365
366     //
367     // Requirements: D's copy constructor must not throw
368     //
369     // shared_ptr will release p by calling d(p)
370     //
371
372     template<class Y, class D> shared_ptr( Y * p, D d ): px( p ), pn( p, d )
373     {
374         boost::detail::sp_deleter_construct( this, p );
375     }
376
377 #if !defined( BOOST_NO_CXX11_NULLPTR )
378
379     template<class D> shared_ptr( boost::detail::sp_nullptr_t p, D d ): px( p ), pn( p, d )
380     {
381     }
382
383 #endif
384
385     // As above, but with allocator. A's copy constructor shall not throw.
386
387     template<class Y, class D, class A> shared_ptr( Y * p, D d, A a ): px( p ), pn( p, d, a )
388     {
389         boost::detail::sp_deleter_construct( this, p );
390     }
391
392 #if !defined( BOOST_NO_CXX11_NULLPTR )
393
394     template<class D, class A> shared_ptr( boost::detail::sp_nullptr_t p, D d, A a ): px( p ), pn( p, d, a )
395     {
396     }
397
398 #endif
399
400 //  generated copy constructor, destructor are fine...
401
402 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
403
404 // ... except in C++0x, move disables the implicit copy
405
406     shared_ptr( shared_ptr const & r ) BOOST_SP_NOEXCEPT : px( r.px ), pn( r.pn )
407     {
408     }
409
410 #endif
411
412     template<class Y>
413     explicit shared_ptr( weak_ptr<Y> const & r ): pn( r.pn ) // may throw
414     {
415         boost::detail::sp_assert_convertible< Y, T >();
416
417         // it is now safe to copy r.px, as pn(r.pn) did not throw
418         px = r.px;
419     }
420
421     template<class Y>
422     shared_ptr( weak_ptr<Y> const & r, boost::detail::sp_nothrow_tag )
423     BOOST_NOEXCEPT : px( 0 ), pn( r.pn, boost::detail::sp_nothrow_tag() )
424     {
425         if( !pn.empty() )
426         {
427             px = r.px;
428         }
429     }
430
431     template<class Y>
432 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
433
434     shared_ptr( shared_ptr<Y> const & r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
435
436 #else
437
438     shared_ptr( shared_ptr<Y> const & r )
439
440 #endif
441     BOOST_NOEXCEPT : px( r.px ), pn( r.pn )
442     {
443         boost::detail::sp_assert_convertible< Y, T >();
444     }
445
446     // aliasing
447     template< class Y >
448     shared_ptr( shared_ptr<Y> const & r, element_type * p ) BOOST_NOEXCEPT : px( p ), pn( r.pn )
449     {
450     }
451
452 #ifndef BOOST_NO_AUTO_PTR
453
454     template<class Y>
455     explicit shared_ptr( std::auto_ptr<Y> & r ): px(r.get()), pn()
456     {
457         boost::detail::sp_assert_convertible< Y, T >();
458
459         Y * tmp = r.get();
460         pn = boost::detail::shared_count( r );
461
462         boost::detail::sp_deleter_construct( this, tmp );
463     }
464
465 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
466
467     template<class Y>
468     shared_ptr( std::auto_ptr<Y> && r ): px(r.get()), pn()
469     {
470         boost::detail::sp_assert_convertible< Y, T >();
471
472         Y * tmp = r.get();
473         pn = boost::detail::shared_count( r );
474
475         boost::detail::sp_deleter_construct( this, tmp );
476     }
477
478 #elif !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
479
480     template<class Ap>
481     explicit shared_ptr( Ap r, typename boost::detail::sp_enable_if_auto_ptr<Ap, int>::type = 0 ): px( r.get() ), pn()
482     {
483         typedef typename Ap::element_type Y;
484
485         boost::detail::sp_assert_convertible< Y, T >();
486
487         Y * tmp = r.get();
488         pn = boost::detail::shared_count( r );
489
490         boost::detail::sp_deleter_construct( this, tmp );
491     }
492
493 #endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
494
495 #endif // BOOST_NO_AUTO_PTR
496
497 #if !defined( BOOST_NO_CXX11_SMART_PTR ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
498
499     template< class Y, class D >
500     shared_ptr( std::unique_ptr< Y, D > && r ): px( r.get() ), pn()
501     {
502         boost::detail::sp_assert_convertible< Y, T >();
503
504         typename std::unique_ptr< Y, D >::pointer tmp = r.get();
505         pn = boost::detail::shared_count( r );
506
507         boost::detail::sp_deleter_construct( this, tmp );
508     }
509
510 #endif
511
512     template< class Y, class D >
513     shared_ptr( boost::movelib::unique_ptr< Y, D > r ): px( r.get() ), pn()
514     {
515         boost::detail::sp_assert_convertible< Y, T >();
516
517         typename boost::movelib::unique_ptr< Y, D >::pointer tmp = r.get();
518         pn = boost::detail::shared_count( r );
519
520         boost::detail::sp_deleter_construct( this, tmp );
521     }
522
523     // assignment
524
525     shared_ptr & operator=( shared_ptr const & r ) BOOST_SP_NOEXCEPT
526     {
527         this_type(r).swap(*this);
528         return *this;
529     }
530
531 #if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1400)
532
533     template<class Y>
534     shared_ptr & operator=(shared_ptr<Y> const & r) BOOST_NOEXCEPT
535     {
536         this_type(r).swap(*this);
537         return *this;
538     }
539
540 #endif
541
542 #ifndef BOOST_NO_AUTO_PTR
543
544     template<class Y>
545     shared_ptr & operator=( std::auto_ptr<Y> & r )
546     {
547         this_type( r ).swap( *this );
548         return *this;
549     }
550
551 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
552
553     template<class Y>
554     shared_ptr & operator=( std::auto_ptr<Y> && r )
555     {
556         this_type( static_cast< std::auto_ptr<Y> && >( r ) ).swap( *this );
557         return *this;
558     }
559
560 #elif !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
561
562     template<class Ap>
563     typename boost::detail::sp_enable_if_auto_ptr< Ap, shared_ptr & >::type operator=( Ap r )
564     {
565         this_type( r ).swap( *this );
566         return *this;
567     }
568
569 #endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
570
571 #endif // BOOST_NO_AUTO_PTR
572
573 #if !defined( BOOST_NO_CXX11_SMART_PTR ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
574
575     template<class Y, class D>
576     shared_ptr & operator=( std::unique_ptr<Y, D> && r )
577     {
578         this_type( static_cast< std::unique_ptr<Y, D> && >( r ) ).swap(*this);
579         return *this;
580     }
581
582 #endif
583
584     template<class Y, class D>
585     shared_ptr & operator=( boost::movelib::unique_ptr<Y, D> r )
586     {
587         // this_type( static_cast< unique_ptr<Y, D> && >( r ) ).swap( *this );
588
589         boost::detail::sp_assert_convertible< Y, T >();
590
591         typename boost::movelib::unique_ptr< Y, D >::pointer p = r.get();
592
593         shared_ptr tmp;
594
595         tmp.px = p;
596         tmp.pn = boost::detail::shared_count( r );
597
598         boost::detail::sp_deleter_construct( &tmp, p );
599
600         tmp.swap( *this );
601
602         return *this;
603     }
604
605 // Move support
606
607 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
608
609     shared_ptr( shared_ptr && r ) BOOST_SP_NOEXCEPT : px( r.px ), pn()
610     {
611         pn.swap( r.pn );
612         r.px = 0;
613     }
614
615     template<class Y>
616 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
617
618     shared_ptr( shared_ptr<Y> && r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
619
620 #else
621
622     shared_ptr( shared_ptr<Y> && r )
623
624 #endif
625     BOOST_NOEXCEPT : px( r.px ), pn()
626     {
627         boost::detail::sp_assert_convertible< Y, T >();
628
629         pn.swap( r.pn );
630         r.px = 0;
631     }
632
633     shared_ptr & operator=( shared_ptr && r ) BOOST_SP_NOEXCEPT
634     {
635         this_type( static_cast< shared_ptr && >( r ) ).swap( *this );
636         return *this;
637     }
638
639     template<class Y>
640     shared_ptr & operator=( shared_ptr<Y> && r ) BOOST_NOEXCEPT
641     {
642         this_type( static_cast< shared_ptr<Y> && >( r ) ).swap( *this );
643         return *this;
644     }
645
646     // aliasing move
647     template<class Y>
648     shared_ptr( shared_ptr<Y> && r, element_type * p ) BOOST_NOEXCEPT : px( p ), pn()
649     {
650         pn.swap( r.pn );
651         r.px = 0;
652     }
653
654 #endif
655
656 #if !defined( BOOST_NO_CXX11_NULLPTR )
657
658     shared_ptr & operator=( boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT // never throws
659     {
660         this_type().swap(*this);
661         return *this;
662     }
663
664 #endif
665
666     void reset() BOOST_NOEXCEPT // never throws in 1.30+
667     {
668         this_type().swap(*this);
669     }
670
671     template<class Y> void reset( Y * p ) // Y must be complete
672     {
673         BOOST_ASSERT( p == 0 || p != px ); // catch self-reset errors
674         this_type( p ).swap( *this );
675     }
676
677     template<class Y, class D> void reset( Y * p, D d )
678     {
679         this_type( p, d ).swap( *this );
680     }
681
682     template<class Y, class D, class A> void reset( Y * p, D d, A a )
683     {
684         this_type( p, d, a ).swap( *this );
685     }
686
687     template<class Y> void reset( shared_ptr<Y> const & r, element_type * p )
688     {
689         this_type( r, p ).swap( *this );
690     }
691
692 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
693
694     template<class Y> void reset( shared_ptr<Y> && r, element_type * p )
695     {
696         this_type( static_cast< shared_ptr<Y> && >( r ), p ).swap( *this );
697     }
698
699 #endif
700
701     // never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
702     typename boost::detail::sp_dereference< T >::type operator* () const
703     {
704         BOOST_ASSERT( px != 0 );
705         return *px;
706     }
707     
708     // never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
709     typename boost::detail::sp_member_access< T >::type operator-> () const 
710     {
711         BOOST_ASSERT( px != 0 );
712         return px;
713     }
714     
715     // never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
716     typename boost::detail::sp_array_access< T >::type operator[] ( std::ptrdiff_t i ) const
717     {
718         BOOST_ASSERT( px != 0 );
719         BOOST_ASSERT( i >= 0 && ( i < boost::detail::sp_extent< T >::value || boost::detail::sp_extent< T >::value == 0 ) );
720
721         return static_cast< typename boost::detail::sp_array_access< T >::type >( px[ i ] );
722     }
723
724     element_type * get() const BOOST_NOEXCEPT
725     {
726         return px;
727     }
728
729 // implicit conversion to "bool"
730 #include <boost/smart_ptr/detail/operator_bool.hpp>
731
732     bool unique() const BOOST_NOEXCEPT
733     {
734         return pn.unique();
735     }
736
737     long use_count() const BOOST_NOEXCEPT
738     {
739         return pn.use_count();
740     }
741
742     void swap( shared_ptr & other ) BOOST_NOEXCEPT
743     {
744         std::swap(px, other.px);
745         pn.swap(other.pn);
746     }
747
748     template<class Y> bool owner_before( shared_ptr<Y> const & rhs ) const BOOST_NOEXCEPT
749     {
750         return pn < rhs.pn;
751     }
752
753     template<class Y> bool owner_before( weak_ptr<Y> const & rhs ) const BOOST_NOEXCEPT
754     {
755         return pn < rhs.pn;
756     }
757
758     void * _internal_get_deleter( boost::detail::sp_typeinfo const & ti ) const BOOST_NOEXCEPT
759     {
760         return pn.get_deleter( ti );
761     }
762
763     void * _internal_get_untyped_deleter() const BOOST_NOEXCEPT
764     {
765         return pn.get_untyped_deleter();
766     }
767
768     bool _internal_equiv( shared_ptr const & r ) const BOOST_NOEXCEPT
769     {
770         return px == r.px && pn == r.pn;
771     }
772
773 // Tasteless as this may seem, making all members public allows member templates
774 // to work in the absence of member template friends. (Matthew Langston)
775
776 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
777
778 private:
779
780     template<class Y> friend class shared_ptr;
781     template<class Y> friend class weak_ptr;
782
783
784 #endif
785
786     element_type * px;                 // contained pointer
787     boost::detail::shared_count pn;    // reference counter
788
789 };  // shared_ptr
790
791 template<class T, class U> inline bool operator==(shared_ptr<T> const & a, shared_ptr<U> const & b) BOOST_NOEXCEPT
792 {
793     return a.get() == b.get();
794 }
795
796 template<class T, class U> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<U> const & b) BOOST_NOEXCEPT
797 {
798     return a.get() != b.get();
799 }
800
801 #if __GNUC__ == 2 && __GNUC_MINOR__ <= 96
802
803 // Resolve the ambiguity between our op!= and the one in rel_ops
804
805 template<class T> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<T> const & b) BOOST_NOEXCEPT
806 {
807     return a.get() != b.get();
808 }
809
810 #endif
811
812 #if !defined( BOOST_NO_CXX11_NULLPTR )
813
814 template<class T> inline bool operator==( shared_ptr<T> const & p, boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT
815 {
816     return p.get() == 0;
817 }
818
819 template<class T> inline bool operator==( boost::detail::sp_nullptr_t, shared_ptr<T> const & p ) BOOST_NOEXCEPT
820 {
821     return p.get() == 0;
822 }
823
824 template<class T> inline bool operator!=( shared_ptr<T> const & p, boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT
825 {
826     return p.get() != 0;
827 }
828
829 template<class T> inline bool operator!=( boost::detail::sp_nullptr_t, shared_ptr<T> const & p ) BOOST_NOEXCEPT
830 {
831     return p.get() != 0;
832 }
833
834 #endif
835
836 template<class T, class U> inline bool operator<(shared_ptr<T> const & a, shared_ptr<U> const & b) BOOST_NOEXCEPT
837 {
838     return a.owner_before( b );
839 }
840
841 template<class T> inline void swap(shared_ptr<T> & a, shared_ptr<T> & b) BOOST_NOEXCEPT
842 {
843     a.swap(b);
844 }
845
846 template<class T, class U> shared_ptr<T> static_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
847 {
848     (void) static_cast< T* >( static_cast< U* >( 0 ) );
849
850     typedef typename shared_ptr<T>::element_type E;
851
852     E * p = static_cast< E* >( r.get() );
853     return shared_ptr<T>( r, p );
854 }
855
856 template<class T, class U> shared_ptr<T> const_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
857 {
858     (void) const_cast< T* >( static_cast< U* >( 0 ) );
859
860     typedef typename shared_ptr<T>::element_type E;
861
862     E * p = const_cast< E* >( r.get() );
863     return shared_ptr<T>( r, p );
864 }
865
866 template<class T, class U> shared_ptr<T> dynamic_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
867 {
868     (void) dynamic_cast< T* >( static_cast< U* >( 0 ) );
869
870     typedef typename shared_ptr<T>::element_type E;
871
872     E * p = dynamic_cast< E* >( r.get() );
873     return p? shared_ptr<T>( r, p ): shared_ptr<T>();
874 }
875
876 template<class T, class U> shared_ptr<T> reinterpret_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
877 {
878     (void) reinterpret_cast< T* >( static_cast< U* >( 0 ) );
879
880     typedef typename shared_ptr<T>::element_type E;
881
882     E * p = reinterpret_cast< E* >( r.get() );
883     return shared_ptr<T>( r, p );
884 }
885
886 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
887
888 template<class T, class U> shared_ptr<T> static_pointer_cast( shared_ptr<U> && r ) BOOST_NOEXCEPT
889 {
890     (void) static_cast< T* >( static_cast< U* >( 0 ) );
891
892     typedef typename shared_ptr<T>::element_type E;
893
894     E * p = static_cast< E* >( r.get() );
895     return shared_ptr<T>( std::move(r), p );
896 }
897
898 template<class T, class U> shared_ptr<T> const_pointer_cast( shared_ptr<U> && r ) BOOST_NOEXCEPT
899 {
900     (void) const_cast< T* >( static_cast< U* >( 0 ) );
901
902     typedef typename shared_ptr<T>::element_type E;
903
904     E * p = const_cast< E* >( r.get() );
905     return shared_ptr<T>( std::move(r), p );
906 }
907
908 template<class T, class U> shared_ptr<T> dynamic_pointer_cast( shared_ptr<U> && r ) BOOST_NOEXCEPT
909 {
910     (void) dynamic_cast< T* >( static_cast< U* >( 0 ) );
911
912     typedef typename shared_ptr<T>::element_type E;
913
914     E * p = dynamic_cast< E* >( r.get() );
915     return p? shared_ptr<T>( std::move(r), p ): shared_ptr<T>();
916 }
917
918 template<class T, class U> shared_ptr<T> reinterpret_pointer_cast( shared_ptr<U> && r ) BOOST_NOEXCEPT
919 {
920     (void) reinterpret_cast< T* >( static_cast< U* >( 0 ) );
921
922     typedef typename shared_ptr<T>::element_type E;
923
924     E * p = reinterpret_cast< E* >( r.get() );
925     return shared_ptr<T>( std::move(r), p );
926 }
927
928 #endif // !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
929
930 // get_pointer() enables boost::mem_fn to recognize shared_ptr
931
932 template<class T> inline typename shared_ptr<T>::element_type * get_pointer(shared_ptr<T> const & p) BOOST_NOEXCEPT
933 {
934     return p.get();
935 }
936
937 // operator<<
938
939 #if !defined(BOOST_NO_IOSTREAM)
940
941 #if defined(BOOST_NO_TEMPLATED_IOSTREAMS) || ( defined(__GNUC__) &&  (__GNUC__ < 3) )
942
943 template<class Y> std::ostream & operator<< (std::ostream & os, shared_ptr<Y> const & p)
944 {
945     os << p.get();
946     return os;
947 }
948
949 #else
950
951 // in STLport's no-iostreams mode no iostream symbols can be used
952 #ifndef _STLP_NO_IOSTREAMS
953
954 # if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300 && __SGI_STL_PORT)
955 // MSVC6 has problems finding std::basic_ostream through the using declaration in namespace _STL
956 using std::basic_ostream;
957 template<class E, class T, class Y> basic_ostream<E, T> & operator<< (basic_ostream<E, T> & os, shared_ptr<Y> const & p)
958 # else
959 template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, shared_ptr<Y> const & p)
960 # endif
961 {
962     os << p.get();
963     return os;
964 }
965
966 #endif // _STLP_NO_IOSTREAMS
967
968 #endif // __GNUC__ < 3
969
970 #endif // !defined(BOOST_NO_IOSTREAM)
971
972 // get_deleter
973
974 namespace detail
975 {
976
977 #if ( defined(__GNUC__) && BOOST_WORKAROUND(__GNUC__, < 3) ) || \
978     ( defined(__EDG_VERSION__) && BOOST_WORKAROUND(__EDG_VERSION__, <= 238) ) || \
979     ( defined(__HP_aCC) && BOOST_WORKAROUND(__HP_aCC, <= 33500) )
980
981 // g++ 2.9x doesn't allow static_cast<X const *>(void *)
982 // apparently EDG 2.38 and HP aCC A.03.35 also don't accept it
983
984 template<class D, class T> D * basic_get_deleter(shared_ptr<T> const & p)
985 {
986     void const * q = p._internal_get_deleter(BOOST_SP_TYPEID(D));
987     return const_cast<D *>(static_cast<D const *>(q));
988 }
989
990 #else
991
992 template<class D, class T> D * basic_get_deleter( shared_ptr<T> const & p ) BOOST_NOEXCEPT
993 {
994     return static_cast<D *>( p._internal_get_deleter(BOOST_SP_TYPEID(D)) );
995 }
996
997 #endif
998
999 class esft2_deleter_wrapper
1000 {
1001 private:
1002
1003     shared_ptr<void const volatile> deleter_;
1004
1005 public:
1006
1007     esft2_deleter_wrapper()
1008     {
1009     }
1010
1011     template< class T > void set_deleter( shared_ptr<T> const & deleter )
1012     {
1013         deleter_ = deleter;
1014     }
1015
1016     template<typename D> D* get_deleter() const BOOST_NOEXCEPT
1017     {
1018         return boost::detail::basic_get_deleter<D>( deleter_ );
1019     }
1020
1021     template< class T> void operator()( T* )
1022     {
1023         BOOST_ASSERT( deleter_.use_count() <= 1 );
1024         deleter_.reset();
1025     }
1026 };
1027
1028 } // namespace detail
1029
1030 template<class D, class T> D * get_deleter( shared_ptr<T> const & p ) BOOST_NOEXCEPT
1031 {
1032     D *del = boost::detail::basic_get_deleter<D>(p);
1033
1034     if(del == 0)
1035     {
1036         boost::detail::esft2_deleter_wrapper *del_wrapper = boost::detail::basic_get_deleter<boost::detail::esft2_deleter_wrapper>(p);
1037 // The following get_deleter method call is fully qualified because
1038 // older versions of gcc (2.95, 3.2.3) fail to compile it when written del_wrapper->get_deleter<D>()
1039         if(del_wrapper) del = del_wrapper->::boost::detail::esft2_deleter_wrapper::get_deleter<D>();
1040     }
1041
1042     return del;
1043 }
1044
1045 // atomic access
1046
1047 #if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
1048
1049 template<class T> inline bool atomic_is_lock_free( shared_ptr<T> const * /*p*/ ) BOOST_NOEXCEPT
1050 {
1051     return false;
1052 }
1053
1054 template<class T> shared_ptr<T> atomic_load( shared_ptr<T> const * p )
1055 {
1056     boost::detail::spinlock_pool<2>::scoped_lock lock( p );
1057     return *p;
1058 }
1059
1060 template<class T> inline shared_ptr<T> atomic_load_explicit( shared_ptr<T> const * p, /*memory_order mo*/ int )
1061 {
1062     return atomic_load( p );
1063 }
1064
1065 template<class T> void atomic_store( shared_ptr<T> * p, shared_ptr<T> r )
1066 {
1067     boost::detail::spinlock_pool<2>::scoped_lock lock( p );
1068     p->swap( r );
1069 }
1070
1071 template<class T> inline void atomic_store_explicit( shared_ptr<T> * p, shared_ptr<T> r, /*memory_order mo*/ int )
1072 {
1073     atomic_store( p, r ); // std::move( r )
1074 }
1075
1076 template<class T> shared_ptr<T> atomic_exchange( shared_ptr<T> * p, shared_ptr<T> r )
1077 {
1078     boost::detail::spinlock & sp = boost::detail::spinlock_pool<2>::spinlock_for( p );
1079
1080     sp.lock();
1081     p->swap( r );
1082     sp.unlock();
1083
1084     return r; // return std::move( r )
1085 }
1086
1087 template<class T> shared_ptr<T> atomic_exchange_explicit( shared_ptr<T> * p, shared_ptr<T> r, /*memory_order mo*/ int )
1088 {
1089     return atomic_exchange( p, r ); // std::move( r )
1090 }
1091
1092 template<class T> bool atomic_compare_exchange( shared_ptr<T> * p, shared_ptr<T> * v, shared_ptr<T> w )
1093 {
1094     boost::detail::spinlock & sp = boost::detail::spinlock_pool<2>::spinlock_for( p );
1095
1096     sp.lock();
1097
1098     if( p->_internal_equiv( *v ) )
1099     {
1100         p->swap( w );
1101
1102         sp.unlock();
1103
1104         return true;
1105     }
1106     else
1107     {
1108         shared_ptr<T> tmp( *p );
1109
1110         sp.unlock();
1111
1112         tmp.swap( *v );
1113         return false;
1114     }
1115 }
1116
1117 template<class T> inline bool atomic_compare_exchange_explicit( shared_ptr<T> * p, shared_ptr<T> * v, shared_ptr<T> w, /*memory_order success*/ int, /*memory_order failure*/ int )
1118 {
1119     return atomic_compare_exchange( p, v, w ); // std::move( w )
1120 }
1121
1122 #endif // !defined(BOOST_SP_NO_ATOMIC_ACCESS)
1123
1124 // hash_value
1125
1126 template< class T > struct hash;
1127
1128 template< class T > std::size_t hash_value( boost::shared_ptr<T> const & p ) BOOST_NOEXCEPT
1129 {
1130     return boost::hash< typename boost::shared_ptr<T>::element_type* >()( p.get() );
1131 }
1132
1133 } // namespace boost
1134
1135 #if defined( BOOST_SP_DISABLE_DEPRECATED )
1136 #pragma GCC diagnostic pop
1137 #endif
1138
1139 #endif  // #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED