//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // template // class enable_shared_from_this // { // protected: // enable_shared_from_this(); // enable_shared_from_this(enable_shared_from_this const&); // enable_shared_from_this& operator=(enable_shared_from_this const&); // ~enable_shared_from_this(); // public: // shared_ptr shared_from_this(); // shared_ptr shared_from_this() const; // }; #include #include struct T : public std::enable_shared_from_this { }; struct Y : T {}; struct Z : Y {}; int main() { { std::shared_ptr p(new Z); std::shared_ptr q = p->shared_from_this(); assert(p == q); assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership } { std::shared_ptr p = std::make_shared(); std::shared_ptr q = p->shared_from_this(); assert(p == q); assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership } }