|
enable_shared_from_this.hpp |
ヘッダーファイル <boost/enable_shared_from_this.hpp> は、クラステンプレート enable_shared_from_this を定義する。 このクラステンプレートは、 自身のオブジェクトを指す shared_ptr をメンバ関数により得ることができるクラスの基底クラスとして利用される。
enable_shared_from_this<T> は、this に与えるコンスト性に応じて shared_ptr<T> または shared_ptr<T const> を返す2つの shared_from_this というメンバ関数を定義する。
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
}
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;
}
}
Requires: enable_shared_from_this<T> は T からアクセス可能な T の基底クラスでなくてはならない。 *this は、型 T のインスタンス t のサブオブジェクトでなくてはならない。 t を 所有 する shared_ptr のインスタンス p が、少なくとも一つ存在しなくてはならない。
Returns: p と所有権を共有する shared_ptr<T> のインスタンス r。
Postconditions: r.get() == this.
Copyright (C) 2002, 2003 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.
Japanese Translation Copyright (C) 2003
Ryo Kobayashi.
オリジナルの、及びこの著作権表示が全ての複製の中に現れる限り、この文書の
複製、利用、変更、販売そして配布を認める。このドキュメントは「あるがまま」
に提供されており、いかなる明示的、暗黙的保証も行わない。また、
いかなる目的に対しても、その利用が適していることを関知しない。