...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
enable_shared_from_this.hpp |
|
The header
enable_shared_from_this
#include#include #include class Y: public boost::enable_shared_from_this { public: boost::shared_ptr f() { return shared_from_this(); } }; int main() { boost::shared_ptr p(new Y); boost::shared_ptr q = p->f(); assert(p == q); assert(!(p < q || q < p)); // p and q must share ownership }
namespace boost { templateclass enable_shared_from_this { public: shared_ptr shared_from_this(); shared_ptr shared_from_this() const; } }
Requires: enable_shared_from_this
must be an accessible base class of T. *this must be a subobject of an instance t of type T . There must exist at least one shared_ptr instance p that owns t. Returns: A shared_ptr
instance r that shares ownership with p. Postconditions: r.get() == this.
Copyright © 2002, 2003 by Peter Dimov. Distributed under the Boost Software License, Version
1.0. See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt.