shared_ptr.hpp

来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 412 行 · 第 1/2 页

HPP
412
字号
   #else   shared_ptr & operator=(shared_ptr &&other) // never throws   {      this_type(other).swap(*this);      return *this;   }   #endif   //!This is equivalent to:   //!this_type().swap(*this);   void reset()   {        this_type().swap(*this);      }   //!This is equivalent to:   //!this_type(p, a, d).swap(*this);   template<class Pointer>   void reset(const Pointer &p, const VoidAllocator &a = VoidAllocator(), const Deleter &d = Deleter())   {        //Check that the pointer passed is of the same type that      //the pointer the allocator defines or it's a raw pointer      typedef typename detail::pointer_to_other<Pointer, T>::type ParameterPointer;      BOOST_STATIC_ASSERT((detail::is_same<pointer, ParameterPointer>::value) ||                          (detail::is_pointer<Pointer>::value));      this_type(p, a, d).swap(*this);     }   template<class Y>   void reset(shared_ptr<Y, VoidAllocator, Deleter> const & r, const pointer &p)   {      this_type(r, p).swap(*this);   }   //!Returns a reference to the   //!pointed type   reference operator* () const // never throws   {  BOOST_ASSERT(m_pn.get_pointer() != 0);  return *m_pn.get_pointer(); }   //!Returns the pointer pointing    //!to the owned object   pointer operator-> () const // never throws   {  BOOST_ASSERT(m_pn.get_pointer() != 0);  return m_pn.get_pointer();  }   //!Returns the pointer pointing    //!to the owned object   pointer get() const  // never throws   {  return m_pn.get_pointer();  }   /// @cond   // implicit conversion to "bool"   void unspecified_bool_type_func() const {}   typedef void (this_type::*unspecified_bool_type)() const;   operator unspecified_bool_type() const // never throws   {  return !m_pn.get_pointer() ? 0 : &this_type::unspecified_bool_type_func;  }   /// @endcond   //!Not operator.   //!Returns true if this->get() != 0, false otherwise   bool operator! () const // never throws   {  return !m_pn.get_pointer();   }   //!Returns use_count() == 1.   //!unique() might be faster than use_count()   bool unique() const // never throws   {  return m_pn.unique();  }   //!Returns the number of shared_ptr objects, *this included,   //!that share ownership with *this, or an unspecified nonnegative   //!value when *this is empty.   //!use_count() is not necessarily efficient. Use only for   //!debugging and testing purposes, not for production code.   long use_count() const // never throws   {  return m_pn.use_count();  }   //!Exchanges the contents of the two   //!smart pointers.   void swap(shared_ptr<T, VoidAllocator, Deleter> & other) // never throws   {  m_pn.swap(other.m_pn);   }   /// @cond   template<class T2, class A2, class Deleter2>    bool _internal_less(shared_ptr<T2, A2, Deleter2> const & rhs) const   {  return m_pn < rhs.m_pn;  }   const_deleter_pointer get_deleter() const   {  return m_pn.get_deleter(); }//   const_allocator_pointer get_allocator() const//   {  return m_pn.get_allocator(); }   private:   template<class T2, class A2, class Deleter2> friend class shared_ptr;   template<class T2, class A2, class Deleter2> friend class weak_ptr;   detail::shared_count<T, VoidAllocator, Deleter>   m_pn;    // reference counter   /// @endcond};  // shared_ptrtemplate<class T, class VoidAllocator, class Deleter, class U, class VoidAllocator2, class Deleter2> inline bool operator==(shared_ptr<T, VoidAllocator, Deleter> const & a, shared_ptr<U, VoidAllocator2, Deleter2> const & b){  return a.get() == b.get(); }template<class T, class VoidAllocator, class Deleter, class U, class VoidAllocator2, class Deleter2> inline bool operator!=(shared_ptr<T, VoidAllocator, Deleter> const & a, shared_ptr<U, VoidAllocator2, Deleter2> const & b){  return a.get() != b.get(); }template<class T, class VoidAllocator, class Deleter, class U, class VoidAllocator2, class Deleter2> inline bool operator<(shared_ptr<T, VoidAllocator, Deleter> const & a, shared_ptr<U, VoidAllocator2, Deleter2> const & b){  return a._internal_less(b);   }template<class T, class VoidAllocator, class Deleter> inline void swap(shared_ptr<T, VoidAllocator, Deleter> & a, shared_ptr<T, VoidAllocator, Deleter> & b){  a.swap(b);  }template<class T, class VoidAllocator, class Deleter, class U> inlineshared_ptr<T, VoidAllocator, Deleter> static_pointer_cast(shared_ptr<U, VoidAllocator, Deleter> const & r){  return shared_ptr<T, VoidAllocator, Deleter>(r, detail::static_cast_tag());   }template<class T, class VoidAllocator, class Deleter, class U> inline shared_ptr<T, VoidAllocator, Deleter> const_pointer_cast(shared_ptr<U, VoidAllocator, Deleter> const & r){  return shared_ptr<T, VoidAllocator, Deleter>(r, detail::const_cast_tag()); }template<class T, class VoidAllocator, class Deleter, class U> inline shared_ptr<T, VoidAllocator, Deleter> dynamic_pointer_cast(shared_ptr<U, VoidAllocator, Deleter> const & r){  return shared_ptr<T, VoidAllocator, Deleter>(r, detail::dynamic_cast_tag());  }// get_pointer() enables boost::mem_fn to recognize shared_ptrtemplate<class T, class VoidAllocator, class Deleter> inlineT * get_pointer(shared_ptr<T, VoidAllocator, Deleter> const & p){  return p.get();   }// operator<<template<class E, class T, class Y, class VoidAllocator, class Deleter> inlinestd::basic_ostream<E, T> & operator<<    (std::basic_ostream<E, T> & os, shared_ptr<Y, VoidAllocator, Deleter> const & p){  os << p.get();   return os;   }//!Returns the type of a shared pointer//!of type T with the allocator boost::interprocess::allocator allocator//!and boost::interprocess::deleter deleter//!that can be constructed in the given managed segment type.template<class T, class ManagedMemory>struct managed_shared_ptr{   typedef typename ManagedMemory::template allocator<void>::type void_allocator;   typedef typename ManagedMemory::template deleter<T>::type      deleter;   typedef shared_ptr< T, void_allocator, deleter>                type;};//!Returns an instance of a shared pointer constructed//!with the default allocator and deleter from a pointer//!of type T that has been allocated in the passed managed segmenttemplate<class T, class ManagedMemory>inline typename managed_shared_ptr<T, ManagedMemory>::type   make_managed_shared_ptr(T *constructed_object, ManagedMemory &managed_memory){   return typename managed_shared_ptr<T, ManagedMemory>::type   ( constructed_object   , managed_memory.template get_allocator<void>()   , managed_memory.template get_deleter<T>()   );}/*// get_deleter (experimental)template<class T, class VoidAllocator, class Deleter> typename detail::pointer_to_other<shared_ptr<T, VoidAllocator, Deleter>, Deleter>::type   get_deleter(shared_ptr<T, VoidAllocator, Deleter> const & p){  return static_cast<Deleter *>(p._internal_get_deleter(typeid(Deleter)));   }*//// @cond//!This class has move constructortemplate <class T, class VA, class D>struct is_movable<boost::interprocess::shared_ptr<T, VA, D> >{   enum {   value = true };};/// @endcond} // namespace interprocess/// @cond#if defined(_MSC_VER) && (_MSC_VER < 1400)// get_pointer() enables boost::mem_fn to recognize shared_ptrtemplate<class T, class VoidAllocator, class Deleter> inlineT * get_pointer(boost::interprocess::shared_ptr<T, VoidAllocator, Deleter> const & p){  return p.get();   }#endif/// @endcond} // namespace boost#include <boost/interprocess/detail/config_end.hpp>#endif  // #ifndef BOOST_INTERPROCESS_SHARED_PTR_HPP_INCLUDED

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?