fix doc example typo
[boost.git] / boost / interprocess / smart_ptr / enable_shared_from_this.hpp
blob5d1c98e698b3c2b9d9a47c001ee1964d3555fefd
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // This file is the adaptation for Interprocess of boost/enable_shared_from_this.hpp
4 //
5 // (C) Copyright Peter Dimov 2002
6 // (C) Copyright Ion Gaztanaga 2006. Distributed under the Boost
7 // Software License, Version 1.0. (See accompanying file
8 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10 // See http://www.boost.org/libs/interprocess for documentation.
12 //////////////////////////////////////////////////////////////////////////////
14 #ifndef BOOST_INTERPROCESS_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
15 #define BOOST_INTERPROCESS_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
17 #include <boost/interprocess/detail/workaround.hpp>
18 #include <boost/interprocess/detail/config_begin.hpp>
20 #include <boost/assert.hpp>
21 #include <boost/interprocess/smart_ptr/weak_ptr.hpp>
22 #include <boost/interprocess/smart_ptr/shared_ptr.hpp>
24 //!\file
25 //!Describes an utility to form a shared pointer from this
27 namespace boost{
28 namespace interprocess{
30 //!This class is used as a base class that allows a shared_ptr to the current
31 //!object to be obtained from within a member function.
32 //!enable_shared_from_this defines two member functions called shared_from_this
33 //!that return a shared_ptr<T> and shared_ptr<T const>, depending on constness, to this.
34 template<class T, class A, class D>
35 class enable_shared_from_this
37 /// @cond
38 protected:
39 enable_shared_from_this()
42 enable_shared_from_this(enable_shared_from_this const &)
45 enable_shared_from_this & operator=(enable_shared_from_this const &)
46 { return *this; }
48 ~enable_shared_from_this()
50 /// @endcond
52 public:
53 shared_ptr<T, A, D> shared_from_this()
55 shared_ptr<T, A, D> p(_internal_weak_this);
56 BOOST_ASSERT(detail::get_pointer(p.get()) == this);
57 return p;
60 shared_ptr<T const, A, D> shared_from_this() const
62 shared_ptr<T const, A, D> p(_internal_weak_this);
63 BOOST_ASSERT(detail::get_pointer(p.get()) == this);
64 return p;
67 /// @cond
68 typedef T element_type;
69 mutable weak_ptr<element_type, A, D> _internal_weak_this;
70 /// @endcond
73 } // namespace interprocess
74 } // namespace boost
76 #include <boost/interprocess/detail/config_end.hpp>
78 #endif // #ifndef BOOST_INTERPROCESS_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED