From 8752c00ebfce63d5081f2aad8f89bfd4af3645ea Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 19 Nov 2002 14:22:58 +0000 Subject: [PATCH] enable_shared_from_this documentation added. [SVN r16319] --- enable_shared_from_this.html | 93 ++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 enable_shared_from_this.html diff --git a/enable_shared_from_this.html b/enable_shared_from_this.html new file mode 100644 index 0000000..425a781 --- /dev/null +++ b/enable_shared_from_this.html @@ -0,0 +1,93 @@ + + + + Boost: enable_shared_from_this.hpp documentation + + + + + + + + + + + +
+ c++boost.gif (8819 bytes) + +

enable_shared_from_this.hpp

+
 
+

Purpose

+

+ The header <boost/enable_shared_from_this.hpp> defines + the class template enable_shared_from_this. It is used as a + base class that allows a shared_ptr to the current + object to be obtained from within a member function. +

+

enable_shared_from_this<T> defines two member functions + called shared_from_this that return a shared_ptr<T> + and shared_ptr<T const>, depending on constness, to this.

+

Example

+
+class Y: public enable_shared_from_this<Y>
+{
+public:
+
+    shared_ptr<Y> f()
+    {
+        return shared_from_this();
+    }
+}
+
+int main()
+{
+    shared_ptr<Y> p(new Y);
+    shared_ptr<Y> q = p->f();
+    assert(p == q);
+    assert(!(p < q || q < p)); // p and q must share ownership
+}
+
+

Synopsis

+
+namespace boost
+{
+
+template<class T> class enable_shared_from_this
+{
+public:
+
+    shared_ptr<T> shared_from_this();
+    shared_ptr<T const> shared_from_this() const;
+}
+
+}
+
+

template<class T> shared_ptr<T> + enable_shared_from_this<T>::shared_from_this();

+

template<class T> shared_ptr<T const> + enable_shared_from_this<T>::shared_from_this() const;

+
+

+ Requires: enable_shared_from_this<T> must be an + accessible base class of T. *this must be a subobject + of an instance t of type T. There must have + existed at least one shared_ptr instance p pointing + to t. +

+

+ Returns: A shared_ptr<T> instance r that shares + ownership with p. +

+

+ Postconditions: r.get() == this. +

+
+

+
+ Copyright © 2002 by Peter Dimov. Permission to copy, use, modify, sell and + distribute this document is granted provided this copyright notice appears in + all copies. This document is provided "as is" without express or implied + warranty, and with no claim as to its suitability for any purpose.

+ +