1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../boost.css">
<title>Boost.Python - <boost/python/pointee.hpp></title>
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../../../../index.htm"><img height="86" width="277" alt=
"C++ Boost" src="../../../../boost.png" border="0"></a></h3>
<td valign="top">
<h1 align="center"><a href="../index.html">Boost.Python</a></h1>
<h2 align="center">Header <boost/python/pointee.hpp></h2>
</table>
<hr>
<h2>Contents</h2>
<dl class="page-index">
<dt><a href="#introduction">Introduction</a>
<dt><a href="#classes">Classes</a>
<dd>
<dl class="page-index">
<dt><a href="#pointee-spec">Class Template<code>pointee</code></a>
<dd>
<dl class="page-index">
<dt><a href="#pointee-spec-synopsis">Class Template
<code>pointee</code> synopsis</a>
</dl>
</dl>
<dt><a href="#examples">Example</a>
</dl>
<hr>
<h2><a name="introduction"></a>Introduction</h2>
<p><code><boost/python/pointee.hpp></code> introduces a
traits <a
href="../../../mpl/doc/refmanual/metafunction.html">metafunction</a>
template <code>pointee<T></code> that can be used to extract the "pointed-to" type from the type of a pointer or smart pointer.
<h2><a name="classes"></a>Classes</h2>
<h3><a name="pointee-spec"></a>Class Template <code>pointee<class T></code></h3>
<p><code>pointee<T></code> is used by the <code><a
href="class.html#class_-spec">class_</a><...></code>
template to deduce the type being held when a pointer or smart
pointer type is used as its <code>HeldType</code> argument.
<h4><a name="pointee-spec-synopsis"></a>Class Template
<code>pointee</code> synopsis</h4>
<pre>
namespace boost { namespace python
{
template <class T> struct pointee
{
typedef T::element_type type;
};
// specialization for pointers
template <T> struct pointee<T*>
{
typedef T type;
};
}
</pre>
<h2><a name="examples"></a>Example</h2>
Given a 3rd-party smart pointer type
<code>smart_pointer<T></code>, one might partially specialize
<code>pointee<smart_pointer<T> ></code> so that it can be
used as the <code>HeldType</code> for a class wrapper:
<pre>
#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(...)
...
;
}
</pre>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
13 November, 2002
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
<p><i>© Copyright <a href="../../../../people/dave_abrahams.htm">Dave
Abrahams</a> 2002. </i>
|