boost/python/pointee.hpp
はじめに
<boost/python/pointee.hpp> は、ポインタやスマートポインタの型から「ポイントされている」型を抽出する特性メタ関数テンプレート pointee<T> を導入する。
クラス
pointee<class T> クラステンプレート
-
template<class T>
struct pointee pointee<T>は、class_<>テンプレートでポインタやスマートポインタ型をHeldType引数に使用するときに保持する型を推論するのに使用する。
pointee クラステンプレートの概要
namespace boost { namespace python
{
template <class T> struct pointee
{
typedef T::element_type type;
};
// ポインタに対する特殊化
template <T> struct pointee<T*>
{
typedef T type;
};
}
例
サードパーティ製のスマートポインタ型 smart_pointer<T> があるとして、pointee を部分特殊化してクラスラッパの HeldType として使用可能にする。
#include <boost/python/pointee.hpp>
#include <boost/python/class.hpp>
#include <third_party_lib.hpp>
namespace boost { namespace python
{
template <class T> struct pointee<smart_pointer<T> >
{
typedef T type;
};
}}
BOOST_PYTHON_MODULE(pointee_demo)
{
class_<third_party_class, smart_pointer<third_party_class> >("third_party_class")
.def(...)
...
;
}