MADNESS  version 0.9
shared_ptr_bits.h
Go to the documentation of this file.
1 #ifndef MADNESS_SHARED_PTR_BITS_H
2 #define MADNESS_SHARED_PTR_BITS_H
3 
7 
8 // shared_ptr.hpp
9 //
10 // (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
11 // Copyright (c) 2001-2008 Peter Dimov
12 //
13 // Distributed under the Boost Software License, Version 1.0. (See
14 // accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
16 //
17 // See http://www.boost.org/libs/smart_ptr/shared_ptr.htm for documentation.
18 //
19 // Ported by JC into madness 9/20/2011
20 // X86 assembly replaced by madness::AtomicInt by RJH 9/20/2011
21 
22 #include <algorithm> // for std::swap
23 #include <functional> // for std::less
24 #include <typeinfo> // for std::bad_cast
25 #include <cstddef> // for std::size_t
26 #include <iosfwd> // for std::basic_ostream
27 
28 namespace madness {
29 
30  // hash_value
31 
32  template <class T> struct Hash;
33 
34  namespace tr1 {
35 
36  namespace shptr {
37 
38  template <class T> class shared_ptr;
39  template <class T> class weak_ptr;
40  template <class T> class enable_shared_from_this;
41  template <class T> class enable_shared_from_this2;
42 
43  struct bad_weak_ptr : public std::exception { };
44 
45  namespace detail {
46 
47  template <class Y, class T> struct sp_convertible {
48  typedef char (&yes)[1];
49  typedef char (&no)[2];
50 
51  static yes f(T*);
52  static no f(... );
53 
54  enum _vt {
55  value = sizeof((f)(static_cast<Y*>(0))) == sizeof(yes)
56  };
57  };
58 
59  struct sp_empty { };
60 
61  template <bool> struct enable_if_convertible_impl;
62 
63  template <> struct enable_if_convertible_impl<true> { typedef sp_empty type; };
64 
65  template <> struct enable_if_convertible_impl<false> { };
66 
67  template <class Y, class T> struct enable_if_convertible :
68  public enable_if_convertible_impl< sp_convertible<Y, T>::value>
69  { };
70 
71  struct static_cast_tag { };
72  struct const_cast_tag { };
73  struct dynamic_cast_tag { };
74 
75  struct sp_nothrow_tag { };
76 
77  // Shared pointer reference trait types for handling void pointers
78  template <class T> struct shared_ptr_traits { typedef T & reference; };
79  template <> struct shared_ptr_traits<void> { typedef void reference; };
80  template <> struct shared_ptr_traits<void const> { typedef void reference; };
81  template <> struct shared_ptr_traits<void volatile> { typedef void reference; };
82  template <> struct shared_ptr_traits<void const volatile> { typedef void reference; };
83 
84  // enable_shared_from_this support
85  template <class X, class Y, class T>
86  inline void sp_enable_shared_from_this(shared_ptr<X> const * ppx, Y const * py, enable_shared_from_this<T> const * pe) {
87  if(pe != 0)
88  pe->_internal_accept_owner(ppx, const_cast<Y*>(py));
89  }
90 
91  template <class X, class Y, class T>
92  inline void sp_enable_shared_from_this( shared_ptr<X> * ppx, Y const * py, enable_shared_from_this2<T> const * pe) {
93  if(pe != 0)
94  pe->_internal_accept_owner(ppx, const_cast<Y*>(py));
95  }
96 
97  inline void sp_enable_shared_from_this(... ) { }
98 
99 
101  {
102  private:
103 
104  sp_counted_base( sp_counted_base const & );
105  sp_counted_base & operator= ( sp_counted_base const & );
106 
107  madness::AtomicInt use_count_; // #shared
108  madness::AtomicInt weak_count_; // #weak + (#shared != 0)
109 
110  public:
111 
113  {
114  use_count_ = 1;
115  weak_count_ = 1;
116  }
117 
118  virtual ~sp_counted_base() // nothrow
119  {
120  }
121 
122  // dispose() is called when use_count_ drops to zero, to release
123  // the resources managed by *this.
124 
125  virtual void dispose() = 0; // nothrow
126 
127  // destroy() is called when weak_count_ drops to zero.
128 
129  virtual void destroy() // nothrow
130  {
131  delete this;
132  }
133 
134  virtual void * get_deleter( std::type_info const & ti ) = 0;
135 
137  {
138  use_count_++;
139  }
140 
141  bool add_ref_lock() // true on success
142  {
143  //return atomic_conditional_increment( &use_count_ ) != 0;
144  throw "shared_ptr::add_ref_lock - not supported";
145  }
146 
147  void release() // nothrow
148  {
149  // if (atomic_exchange_and_add( &use_count_, -1 ) == 1 )
150  if (use_count_.dec_and_test())
151  {
152  dispose();
153  weak_release();
154  }
155  }
156 
157  void weak_add_ref() { weak_count_++; }
158 
159  void weak_release() {
160  //if( atomic_exchange_and_add( &weak_count_, -1 ) == 1 )
161  if( weak_count_.dec_and_test())
162  destroy();
163  }
164 
165  long use_count() const { return use_count_; }
166  };
167 
168  template<class X>
170  private:
171 
172  X * px_;
173 
175  sp_counted_impl_p & operator= ( sp_counted_impl_p const & );
176 
178 
179  public:
180 
181  explicit sp_counted_impl_p( X * px ): px_( px ) { }
182 
183  virtual void dispose() { madness::detail::checked_delete( px_ ); }
184 
185  virtual void * get_deleter( std::type_info const & ) { return 0; }
186  };
187 
188  template<class Y, class D>
190  private:
191 
192  Y* ptr; // copy constructor must not throw
193  D del; // copy constructor must not throw
194 
196  sp_counted_impl_pd & operator= ( sp_counted_impl_pd const & );
197 
199 
200  public:
201 
202  // pre: d(p) must not throw
203 
204  sp_counted_impl_pd( Y* p, D d ): ptr( p ), del( d ) { }
205 
206  sp_counted_impl_pd( Y* p ): ptr( p ), del() { }
207 
208  virtual void dispose() { del( ptr ); }
209 
210  virtual void * get_deleter( std::type_info const & ti ) {
211  return ti == typeid(D)? &reinterpret_cast<char&>( del ): 0;
212  }
213  };
214 
215  class weak_count;
216 
218  {
219  private:
220 
221  sp_counted_base * pi_;
222 
223  friend class weak_count;
224 
225  public:
226 
227  shared_count(): pi_(0) { }
228 
229  template<class Y> explicit shared_count( Y * p ): pi_( 0 )
230  {
231  try {
232  pi_ = new sp_counted_impl_p<Y>( p );
233  } catch(...) {
235  throw;
236  }
237  }
238 
239  template<class Y, class D> shared_count( Y * p, D d ): pi_(0)
240  {
241  try {
242  pi_ = new sp_counted_impl_pd<Y, D>(p, d);
243  } catch(...) {
244  d(p); // delete p
245  throw;
246  }
247  }
248 
250  if( pi_ != 0 ) pi_->release();
251  }
252 
253  shared_count(shared_count const & r): pi_(r.pi_) {
254  if( pi_ != 0 ) pi_->add_ref_copy();
255  }
256 
257  explicit shared_count(weak_count const & r); // throws bad_weak_ptr when r.use_count() == 0
258 
259  shared_count & operator= (shared_count const & r) {
260  sp_counted_base * tmp = r.pi_;
261 
262  if( tmp != pi_ )
263  {
264  if( tmp != 0 ) tmp->add_ref_copy();
265  if( pi_ != 0 ) pi_->release();
266  pi_ = tmp;
267  }
268 
269  return *this;
270  }
271 
272  void swap(shared_count & r) {
273  sp_counted_base * tmp = r.pi_;
274  r.pi_ = pi_;
275  pi_ = tmp;
276  }
277 
278  long use_count() const { return pi_ != 0? pi_->use_count(): 0; }
279 
280  bool unique() const { return use_count() == 1; }
281 
282  bool empty() const { return pi_ == 0; }
283 
284  friend inline bool operator==(shared_count const & a, shared_count const & b) {
285  return a.pi_ == b.pi_;
286  }
287 
288  friend inline bool operator<(shared_count const & a, shared_count const & b) {
289  return std::less<sp_counted_base *>()( a.pi_, b.pi_ );
290  }
291 
292  void * get_deleter( std::type_info const & ti ) const {
293  return pi_? pi_->get_deleter( ti ): 0;
294  }
295  };
296 
297 
298  class weak_count {
299  private:
300 
301  sp_counted_base * pi_;
302 
303  friend class shared_count;
304 
305  public:
306 
307  weak_count() : pi_(0) { }
308 
309  weak_count(shared_count const & r) : pi_(r.pi_) {
310  if(pi_ != 0) pi_->weak_add_ref();
311  }
312 
313  weak_count(weak_count const & r) : pi_(r.pi_) {
314  if(pi_ != 0) pi_->weak_add_ref();
315  }
316 
317  ~weak_count() { if(pi_ != 0) pi_->weak_release(); }
318 
319  weak_count & operator= (shared_count const & r) {
320  sp_counted_base * tmp = r.pi_;
321 
322  if( tmp != pi_ ) {
323  if(tmp != 0) tmp->weak_add_ref();
324  if(pi_ != 0) pi_->weak_release();
325  pi_ = tmp;
326  }
327 
328  return *this;
329  }
330 
331  weak_count & operator= (weak_count const & r) {
332  sp_counted_base * tmp = r.pi_;
333 
334  if( tmp != pi_ ) {
335  if(tmp != 0) tmp->weak_add_ref();
336  if(pi_ != 0) pi_->weak_release();
337  pi_ = tmp;
338  }
339 
340  return *this;
341  }
342 
343  void swap(weak_count & r) {
344  sp_counted_base * tmp = r.pi_;
345  r.pi_ = pi_;
346  pi_ = tmp;
347  }
348 
349  long use_count() const { return pi_ != 0 ? pi_->use_count() : 0; }
350 
351  bool empty() const { return pi_ == 0; }
352 
353  friend inline bool operator==(weak_count const & a, weak_count const & b) {
354  return a.pi_ == b.pi_;
355  }
356 
357  friend inline bool operator<(weak_count const & a, weak_count const & b) {
358  return std::less<sp_counted_base *>()(a.pi_, b.pi_);
359  }
360  };
361 
362  inline shared_count::shared_count( weak_count const & r ) : pi_( r.pi_ ) {
363  if( pi_ == 0 || !pi_->add_ref_lock() )
364  throw bad_weak_ptr();
365  }
366 
367 
368  } // namespace detail
369 
370  //
371  // shared_ptr
372  //
373  // An enhanced relative of scoped_ptr with reference counted copy semantics.
374  // The object pointed to is deleted when the last shared_ptr pointing to it
375  // is destroyed or reset.
376  //
377  template <class T> class shared_ptr {
378  private:
379  typedef shared_ptr<T> this_type;
380 
381  public:
382 
383  typedef T element_type;
384  typedef T value_type;
385  typedef T * pointer;
387 
389  px(0), pn() // never throws in 1.30+
390  { }
391 
392  template <class Y>
393  explicit shared_ptr(Y * p) :
394  px(p), pn(p) // Y must be complete
395  {
397  }
398 
399  //
400  // Requirements: D's copy constructor must not throw
401  //
402  // shared_ptr will release p by calling d(p)
403  //
404 
405  template <class Y, class D> shared_ptr(Y * p, D d) :
406  px(p), pn(p, d)
407  {
409  }
410 
411  // generated copy constructor, destructor are fine
412 
413  template <class Y>
414  explicit shared_ptr(weak_ptr<Y> const & r) :
415  pn(r.pn) // may throw
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>
424  detail::sp_empty()) :
425  px(r.px), pn(r.pn) // never throws
426  { }
427 
428  // aliasing
429  template <class Y>
430  shared_ptr(shared_ptr<Y> const & r, T * p) :
431  px(p), pn(r.pn) // never throws
432  { }
433 
434  template <class Y>
436  px(static_cast<element_type *>(r.px)), pn(r.pn)
437  { }
438 
439  template <class Y>
441  px(const_cast<element_type *>(r.px)), pn(r.pn)
442  { }
443 
444  template <class Y>
446  px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
447  {
448  if(px == 0) // need to allocate new counter -- the cast failed
449  pn = detail::shared_count();
450  }
451 
452  // assignment
453 
455  this_type(r).swap(*this);
456  return *this;
457  }
458 
459  void reset() { this_type().swap(*this); }
460 
461  template <class Y>
462  void reset(Y * p) { // Y must be complete
463  MADNESS_ASSERT(p == 0 || p != px); // catch self-reset errors
464  this_type(p).swap(*this);
465  }
466 
467  template <class Y, class D>
468  void reset(Y * p, D d) { this_type(p, d).swap(*this); }
469 
470  template <class Y>
471  void reset(shared_ptr<Y> const & r, T * p) {
472  this_type(r, p).swap(*this);
473  }
474 
475  reference operator*() const {
476  MADNESS_ASSERT(px != 0);
477  return *px;
478  }
479 
480  T * operator->() const {
481  MADNESS_ASSERT(px != 0);
482  return px;
483  }
484 
485  T * get() const { return px; }
486 
487  operator bool() const { return px != NULL; }
488 
489 
490  // operator! is redundant, but some compilers need it
491  bool operator! () const { return px == 0; }
492 
493  bool unique() const { return pn.unique(); }
494 
495  long use_count() const { return pn.use_count(); }
496 
497  void swap(shared_ptr<T> & other) {
498  std::swap(px, other.px);
499  pn.swap(other.pn);
500  }
501 
502  template <class Y> bool _internal_less(shared_ptr<Y> const & rhs) const {
503  return pn < rhs.pn;
504  }
505 
506  void * _internal_get_deleter(std::type_info const & ti) const {
507  return pn.get_deleter(ti);
508  }
509 
510  bool _internal_equiv(shared_ptr const & r) const {
511  return px == r.px && pn == r.pn;
512  }
513 
514  private:
515 
516  template <class Y> friend class shared_ptr;
517  template <class Y> friend class weak_ptr;
518 
519  T * px; // contained pointer
520  detail::shared_count pn; // reference counter
521 
522  };
523  // shared_ptr
524 
525  template <class T, class U> inline bool operator==(shared_ptr<T> const & a,
526  shared_ptr<U> const & b) {
527  return a.get() == b.get();
528  }
529 
530  template <class T, class U> inline bool operator!=(shared_ptr<T> const & a,
531  shared_ptr<U> const & b) {
532  return a.get() != b.get();
533  }
534 
535  template <class T, class U> inline bool operator<(shared_ptr<T> const & a,
536  shared_ptr<U> const & b) {
537  return a._internal_less(b);
538  }
539 
540  template <class T> inline void swap(shared_ptr<T> & a, shared_ptr<T> & b) {
541  a.swap(b);
542  }
543 
544  template <class T, class U> shared_ptr<T> static_pointer_cast(shared_ptr<U> const & r) {
546  }
547 
548  template <class T, class U> shared_ptr<T> const_pointer_cast(shared_ptr<U> const & r) {
550  }
551 
552  template <class T, class U> shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const & r) {
554  }
555 
556  // get_pointer() enables boost::mem_fn to recognize shared_ptr
557 
558  template <class T>
559  inline T * get_pointer(shared_ptr<T> const & p) { return p.get(); }
560 
561  // operator<<
562 
563  template <class Y>
564  std::ostream & operator<<(std::ostream & os, shared_ptr<Y> const & p) {
565  os << p.get();
566  return os;
567  }
568 
569  // get_deleter
570 
571  template <class D, class T>
572  D * get_deleter(shared_ptr<T> const & p) {
573  return static_cast<D *>(p._internal_get_deleter(typeid(D)));
574  }
575 
576  template <class T> std::size_t hash_value(shared_ptr<T> const & p) {
577  return madness::Hash<T*>()(p.get());
578  }
579 
580  template<class T>
581  class weak_ptr {
582  private:
583 
584  typedef weak_ptr<T> this_type;
585 
586  public:
587 
588  typedef T element_type;
589 
590  weak_ptr(): px(0), pn() { }
591 
592  // generated copy constructor, assignment, destructor are fine
593 
594 
595  //
596  // The "obvious" converting constructor implementation:
597  //
598  // template<class Y>
599  // weak_ptr(weak_ptr<Y> const & r): px(r.px), pn(r.pn) // never throws
600  // {
601  // }
602  //
603  // has a serious problem.
604  //
605  // r.px may already have been invalidated. The px(r.px)
606  // conversion may require access to *r.px (virtual inheritance).
607  //
608  // It is not possible to avoid spurious access violations since
609  // in multithreaded programs r.px may be invalidated at any point.
610  //
611 
612  template<class Y>
614  : px(r.lock().get()), pn(r.pn) // never throws
615  { }
616 
617  template<class Y>
619  : px( r.px ), pn( r.pn ) // never throws
620  { }
621 
623 
624  long use_count() const { return pn.use_count(); }
625 
626  bool expired() const { return pn.use_count() == 0; }
627 
628  void reset() { this_type().swap(*this); }
629 
630  void swap(this_type & other) {
631  std::swap(px, other.px);
632  pn.swap(other.pn);
633  }
634 
635  void _internal_assign(T * px2, detail::shared_count const & pn2) {
636  px = px2;
637  pn = pn2;
638  }
639 
640  template<class Y> bool _internal_less(weak_ptr<Y> const & rhs) const {
641  return pn < rhs.pn;
642  }
643 
644  private:
645 
646  template<class Y> friend class weak_ptr;
647  template<class Y> friend class shared_ptr;
648 
649 
650  T * px; // contained pointer
651  detail::weak_count pn; // reference counter
652 
653  }; // weak_ptr
654 
655  template<class T, class U>
656  inline bool operator<(weak_ptr<T> const & a, weak_ptr<U> const & b) {
657  return a._internal_less(b);
658  }
659 
660  template<class T>
661  void swap(weak_ptr<T> & a, weak_ptr<T> & b) {
662  a.swap(b);
663  }
664 
665  template <class T>
666  class enable_shared_from_this {
667  protected:
668 
670 
672 
674  operator=(enable_shared_from_this const &) { return *this; }
675 
677 
678  public:
679 
681  shared_ptr<T> p( weak_this_ );
682  MADNESS_ASSERT( p.get() == this );
683  return p;
684  }
685 
687  shared_ptr<T const> p( weak_this_ );
688  MADNESS_ASSERT( p.get() == this );
689  return p;
690  }
691 
692  public: // actually private, but avoids compiler template friendship issues
693 
694  // Note: invoked automatically by shared_ptr; do not call
695  template <class X, class Y>
696  void _internal_accept_owner( shared_ptr<X> const * ppx, Y * py ) const {
697  if( weak_this_.expired() )
698  weak_this_ = shared_ptr<T>( *ppx, py );
699  }
700 
701  private:
702 
703  mutable weak_ptr<T> weak_this_;
704  };
705 
706  namespace detail {
707 
709  {
710  private:
711 
712  shared_ptr<void> deleter_;
713 
714  public:
715 
717 
718  template< class T >
719  void set_deleter( shared_ptr<T> const & deleter ) { deleter_ = deleter; }
720 
721  template< class T>
722  void operator()( T* ) {
723  MADNESS_ASSERT( deleter_.use_count() <= 1 );
724  deleter_.reset();
725  }
726  };
727 
728  } // namespace detail
729 
730  template< class T >
731  class enable_shared_from_this2 {
732  protected:
733 
735 
737 
739 
741  MADNESS_ASSERT( shared_this_.use_count() <= 1 ); // make sure no dangling shared_ptr objects exist
742  }
743 
744  private:
745 
746  mutable weak_ptr<T> weak_this_;
747  mutable shared_ptr<T> shared_this_;
748 
749  public:
750 
752  init_weak_once();
753  return shared_ptr<T>( weak_this_ );
754  }
755 
757  init_weak_once();
758  return shared_ptr<T>( weak_this_ );
759  }
760 
761  private:
762 
763  void init_weak_once() const {
764  if( weak_this_._empty() ) {
765  shared_this_.reset( static_cast< T* >( 0 ), detail::esft2_deleter_wrapper() );
766  weak_this_ = shared_this_;
767  }
768  }
769 
770  public: // actually private, but avoids compiler template friendship issues
771 
772  // Note: invoked automatically by shared_ptr; do not call
773  template<class X, class Y>
774  void _internal_accept_owner( shared_ptr<X> * ppx, Y * py ) const {
775  MADNESS_ASSERT( ppx != 0 );
776 
777  if( weak_this_.use_count() == 0 ) {
778  weak_this_ = shared_ptr<T>( *ppx, py );
779  } else if( shared_this_.use_count() != 0 ) {
780  MADNESS_ASSERT( ppx->unique() ); // no weak_ptrs should exist either, but there's no way to check that
781 
782  detail::esft2_deleter_wrapper * pd = get_deleter<detail::esft2_deleter_wrapper>( shared_this_ );
783  MADNESS_ASSERT( pd != 0 );
784 
785  pd->set_deleter( *ppx );
786 
787  ppx->reset( shared_this_, ppx->get() );
788  shared_this_.reset();
789  }
790  }
791  }; // class enable_shared_from_this2
792 
793  } // namespace shptr
794  } // namespace tr1
795 } // namespace madness
796 
797 #endif
shared_count(Y *p)
Definition: shared_ptr_bits.h:229
bool unique() const
Definition: shared_ptr_bits.h:493
void swap(this_type &other)
Definition: shared_ptr_bits.h:630
virtual void destroy()
Definition: shared_ptr_bits.h:129
Definition: shared_ptr_bits.h:38
reference operator*() const
Definition: shared_ptr_bits.h:475
void _internal_assign(T *px2, detail::shared_count const &pn2)
Definition: shared_ptr_bits.h:635
shared_count(Y *p, D d)
Definition: shared_ptr_bits.h:239
virtual void * get_deleter(std::type_info const &ti)=0
~weak_count()
Definition: shared_ptr_bits.h:317
D * get_deleter(shared_ptr< T > const &p)
Definition: shared_ptr_bits.h:572
Definition: shared_ptr_bits.h:71
Definition: shared_ptr_bits.h:100
char(& yes)[1]
Definition: shared_ptr_bits.h:48
void reset(Y *p, D d)
Definition: shared_ptr_bits.h:468
T & reference
Definition: shared_ptr_bits.h:78
weak_ptr(shared_ptr< Y > const &r, typename detail::enable_if_convertible< Y, T >::type=detail::sp_empty())
Definition: shared_ptr_bits.h:618
bool expired() const
Definition: shared_ptr_bits.h:626
bool add_ref_lock()
Definition: shared_ptr_bits.h:141
_vt
Definition: shared_ptr_bits.h:54
bool _internal_less(shared_ptr< Y > const &rhs) const
Definition: shared_ptr_bits.h:502
shared_ptr< T > shared_from_this()
Definition: shared_ptr_bits.h:680
void release()
Definition: shared_ptr_bits.h:147
Definition: shared_ptr_bits.h:75
void * _internal_get_deleter(std::type_info const &ti) const
Definition: shared_ptr_bits.h:506
~enable_shared_from_this()
Definition: shared_ptr_bits.h:676
void operator()(T *)
Definition: shared_ptr_bits.h:722
shared_ptr(Y *p)
Definition: shared_ptr_bits.h:393
friend bool operator==(shared_count const &a, shared_count const &b)
Definition: shared_ptr_bits.h:284
void _internal_accept_owner(shared_ptr< X > const *ppx, Y *py) const
Definition: shared_ptr_bits.h:696
enable_shared_from_this(enable_shared_from_this const &)
Definition: shared_ptr_bits.h:671
void reset(shared_ptr< Y > const &r, T *p)
Definition: shared_ptr_bits.h:471
bool operator!() const
Definition: shared_ptr_bits.h:491
sp_counted_impl_pd(Y *p, D d)
Definition: shared_ptr_bits.h:204
bool operator!=(shared_ptr< T > const &a, shared_ptr< U > const &b)
Definition: shared_ptr_bits.h:530
detail::shared_ptr_traits< T >::reference reference
Definition: shared_ptr_bits.h:386
void sp_enable_shared_from_this(shared_ptr< X > const *ppx, Y const *py, enable_shared_from_this< T > const *pe)
Definition: shared_ptr_bits.h:86
shared_ptr(shared_ptr< Y > const &r, detail::const_cast_tag)
Definition: shared_ptr_bits.h:440
void reset(Y *p)
Definition: shared_ptr_bits.h:462
void swap(shared_ptr< T > &other)
Definition: shared_ptr_bits.h:497
void swap(weak_count &r)
Definition: shared_ptr_bits.h:343
bool dec_and_test()
Decrements the counter and returns true if the new value is zero.
Definition: atomicint.h:178
~shared_count()
Definition: shared_ptr_bits.h:249
Definition: shared_ptr_bits.h:169
Definition: shared_ptr_bits.h:41
Definition: shared_ptr_bits.h:298
enable_shared_from_this()
Definition: shared_ptr_bits.h:669
Definition: shared_ptr_bits.h:59
enable_shared_from_this2()
Definition: shared_ptr_bits.h:734
shared_ptr< T const > shared_from_this() const
Definition: shared_ptr_bits.h:756
shared_ptr(shared_ptr< Y > const &r, detail::dynamic_cast_tag)
Definition: shared_ptr_bits.h:445
shared_ptr(shared_ptr< Y > const &r, detail::static_cast_tag)
Definition: shared_ptr_bits.h:435
char(& no)[2]
Definition: shared_ptr_bits.h:49
void reference
Definition: shared_ptr_bits.h:79
shared_ptr< T > lock() const
Definition: shared_ptr_bits.h:622
Definition: shared_ptr_bits.h:47
void reset()
Definition: shared_ptr_bits.h:628
weak_count(shared_count const &r)
Definition: shared_ptr_bits.h:309
T * get() const
Definition: shared_ptr_bits.h:485
bool empty() const
Definition: shared_ptr_bits.h:282
weak_ptr()
Definition: shared_ptr_bits.h:590
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
shared_ptr(weak_ptr< Y > const &r)
Definition: shared_ptr_bits.h:414
sp_counted_impl_pd(Y *p)
Definition: shared_ptr_bits.h:206
weak_ptr(weak_ptr< Y > const &r, typename detail::enable_if_convertible< Y, T >::type=detail::sp_empty())
Definition: shared_ptr_bits.h:613
shared_count()
Definition: shared_ptr_bits.h:227
void _internal_accept_owner(shared_ptr< X > *ppx, Y *py) const
Definition: shared_ptr_bits.h:774
void add_ref_copy()
Definition: shared_ptr_bits.h:136
FLOAT a(int j, FLOAT z)
Definition: y1.cc:86
friend bool operator<(weak_count const &a, weak_count const &b)
Definition: shared_ptr_bits.h:357
T * pointer
Definition: shared_ptr_bits.h:385
T element_type
Definition: shared_ptr_bits.h:588
weak_count(weak_count const &r)
Definition: shared_ptr_bits.h:313
T * get_pointer(shared_ptr< T > const &p)
Definition: shared_ptr_bits.h:559
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r)
Definition: shared_ptr_bits.h:544
friend bool operator<(shared_count const &a, shared_count const &b)
Definition: shared_ptr_bits.h:288
Definition: shared_ptr_bits.h:72
void * get_deleter(std::type_info const &ti) const
Definition: shared_ptr_bits.h:292
long use_count() const
Definition: shared_ptr_bits.h:278
An integer with atomic set, get, read+inc, read+dec, dec+test operations.
Definition: atomicint.h:73
Definition: shared_ptr_bits.h:39
virtual void dispose()
Definition: shared_ptr_bits.h:183
friend bool operator==(weak_count const &a, weak_count const &b)
Definition: shared_ptr_bits.h:353
sp_counted_base()
Definition: shared_ptr_bits.h:112
void checked_delete(T *p)
Checked pointer delete function.
Definition: boost_checked_delete_bits.h:15
enable_shared_from_this & operator=(enable_shared_from_this const &)
Definition: shared_ptr_bits.h:674
virtual void * get_deleter(std::type_info const &)
Definition: shared_ptr_bits.h:185
void swap(shared_ptr< T > &a, shared_ptr< T > &b)
Definition: shared_ptr_bits.h:540
esft2_deleter_wrapper()
Definition: shared_ptr_bits.h:716
shared_ptr< T > const_pointer_cast(shared_ptr< U > const &r)
Definition: shared_ptr_bits.h:548
long use_count() const
Definition: shared_ptr_bits.h:495
Definition: shared_ptr_bits.h:217
void reset()
Definition: shared_ptr_bits.h:459
bool operator==(shared_ptr< T > const &a, shared_ptr< U > const &b)
Definition: shared_ptr_bits.h:525
shared_ptr(Y *p, D d)
Definition: shared_ptr_bits.h:405
void weak_add_ref()
Definition: shared_ptr_bits.h:157
bool _internal_less(weak_ptr< Y > const &rhs) const
Definition: shared_ptr_bits.h:640
virtual void * get_deleter(std::type_info const &ti)
Definition: shared_ptr_bits.h:210
shared_count(shared_count const &r)
Definition: shared_ptr_bits.h:253
bool unique() const
Definition: shared_ptr_bits.h:280
T element_type
Definition: shared_ptr_bits.h:383
virtual void dispose()
Definition: shared_ptr_bits.h:208
shared_ptr & operator=(shared_ptr const &r)
Definition: shared_ptr_bits.h:454
T * operator->() const
Definition: shared_ptr_bits.h:480
Implements MadnessException.
shared_ptr()
Definition: shared_ptr_bits.h:388
enable_shared_from_this2 & operator=(enable_shared_from_this2 const &)
Definition: shared_ptr_bits.h:738
enable_shared_from_this2(enable_shared_from_this2 const &)
Definition: shared_ptr_bits.h:736
weak_count()
Definition: shared_ptr_bits.h:307
shared_ptr< T > shared_from_this()
Definition: shared_ptr_bits.h:751
long use_count() const
Definition: shared_ptr_bits.h:349
shared_ptr(shared_ptr< Y > const &r, T *p)
Definition: shared_ptr_bits.h:430
std::size_t hash_value(shared_ptr< T > const &p)
Definition: shared_ptr_bits.h:576
Definition: shared_ptr_bits.h:73
void weak_release()
Definition: shared_ptr_bits.h:159
Definition: shared_ptr_bits.h:40
shared_ptr< T const > shared_from_this() const
Definition: shared_ptr_bits.h:686
virtual ~sp_counted_base()
Definition: shared_ptr_bits.h:118
~enable_shared_from_this2()
Definition: shared_ptr_bits.h:740
T value_type
Definition: shared_ptr_bits.h:384
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
Definition: shared_ptr_bits.h:43
long use_count() const
Definition: shared_ptr_bits.h:624
FLOAT b(int j, FLOAT z)
Definition: y1.cc:79
void swap(shared_count &r)
Definition: shared_ptr_bits.h:272
shared_ptr(shared_ptr< Y > const &r, typename detail::enable_if_convertible< Y, T >::type=detail::sp_empty())
Definition: shared_ptr_bits.h:422
void swap(mpfr::mpreal &x, mpfr::mpreal &y)
Definition: mpreal.h:3069
Hash functor.
Definition: shared_ptr_bits.h:32
Definition: shared_ptr_bits.h:189
sp_counted_impl_p(X *px)
Definition: shared_ptr_bits.h:181
bool _internal_equiv(shared_ptr const &r) const
Definition: shared_ptr_bits.h:510
Definition: shared_ptr_bits.h:78
void set_deleter(shared_ptr< T > const &deleter)
Definition: shared_ptr_bits.h:719
shared_ptr< T > dynamic_pointer_cast(shared_ptr< U > const &r)
Definition: shared_ptr_bits.h:552
long use_count() const
Definition: shared_ptr_bits.h:165
bool empty() const
Definition: shared_ptr_bits.h:351