1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>boost/python/pointee.hpp</title> 5<link rel="stylesheet" href="../../boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../index.html" title="Boost.Python Reference Manual"> 8<link rel="up" href="../utility_and_infrastructure.html" title="Chapter 7. Utility and Infrastructure"> 9<link rel="prev" href="boost_python_instance_holder_hpp.html" title="boost/python/instance_holder.hpp"> 10<link rel="next" href="boost_python_handle_hpp.html" title="boost/python/handle.hpp"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table> 14<hr> 15<div class="spirit-nav"> 16<a accesskey="p" href="boost_python_instance_holder_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../utility_and_infrastructure.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_handle_hpp.html"><img src="../../images/next.png" alt="Next"></a> 17</div> 18<div class="section"> 19<div class="titlepage"><div><div><h2 class="title" style="clear: both"> 20<a name="utility_and_infrastructure.boost_python_pointee_hpp"></a><a class="link" href="boost_python_pointee_hpp.html" title="boost/python/pointee.hpp">boost/python/pointee.hpp</a> 21</h2></div></div></div> 22<div class="toc"><dl class="toc"> 23<dt><span class="section"><a href="boost_python_pointee_hpp.html#utility_and_infrastructure.boost_python_pointee_hpp.introduction">Introduction</a></span></dt> 24<dt><span class="section"><a href="boost_python_pointee_hpp.html#utility_and_infrastructure.boost_python_pointee_hpp.class_template_pointee">Class 25 template <code class="computeroutput"><span class="identifier">pointee</span></code></a></span></dt> 26<dt><span class="section"><a href="boost_python_pointee_hpp.html#utility_and_infrastructure.boost_python_pointee_hpp.examples">Examples</a></span></dt> 27</dl></div> 28<div class="section"> 29<div class="titlepage"><div><div><h3 class="title"> 30<a name="utility_and_infrastructure.boost_python_pointee_hpp.introduction"></a><a class="link" href="boost_python_pointee_hpp.html#utility_and_infrastructure.boost_python_pointee_hpp.introduction" title="Introduction">Introduction</a> 31</h3></div></div></div> 32<p> 33 <boost/python/pointee.hpp> introduces a traits metafunction <code class="computeroutput"><span class="keyword">template</span> <span class="identifier">pointee</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> that can be used to extract the "pointed-to" 34 type from the type of a pointer or smart pointer. 35 </p> 36</div> 37<div class="section"> 38<div class="titlepage"><div><div><h3 class="title"> 39<a name="utility_and_infrastructure.boost_python_pointee_hpp.class_template_pointee"></a><a class="link" href="boost_python_pointee_hpp.html#utility_and_infrastructure.boost_python_pointee_hpp.class_template_pointee" title="Class template pointee">Class 40 template <code class="computeroutput"><span class="identifier">pointee</span></code></a> 41</h3></div></div></div> 42<p> 43 <code class="computeroutput"><span class="identifier">pointee</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> 44 is used by the <a class="link" href="../high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel" title="Class template class_<T, Bases, HeldType, NonCopyable>"><code class="computeroutput"><span class="identifier">class_</span><span class="special"><...></span></code></a> 45 template to deduce the type being held when a pointer or smart pointer 46 type is used as its HeldType argument. 47 </p> 48<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span> 49<span class="special">{</span> 50 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> <span class="keyword">struct</span> <span class="identifier">pointee</span> 51 <span class="special">{</span> 52 <span class="keyword">typedef</span> <span class="identifier">T</span><span class="special">::</span><span class="identifier">element_type</span> <span class="identifier">type</span><span class="special">;</span> 53 <span class="special">};</span> 54 55 <span class="comment">// specialization for pointers</span> 56 <span class="keyword">template</span> <span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">struct</span> <span class="identifier">pointee</span><span class="special"><</span><span class="identifier">T</span><span class="special">*></span> 57 <span class="special">{</span> 58 <span class="keyword">typedef</span> <span class="identifier">T</span> <span class="identifier">type</span><span class="special">;</span> 59 <span class="special">};</span> 60<span class="special">}</span> 61</pre> 62</div> 63<div class="section"> 64<div class="titlepage"><div><div><h3 class="title"> 65<a name="utility_and_infrastructure.boost_python_pointee_hpp.examples"></a><a class="link" href="boost_python_pointee_hpp.html#utility_and_infrastructure.boost_python_pointee_hpp.examples" title="Examples">Examples</a> 66</h3></div></div></div> 67<p> 68 Given a 3rd-party smart pointer type <code class="computeroutput"><span class="identifier">smart_pointer</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code>, one might partially specialize <code class="computeroutput"><span class="identifier">pointee</span><span class="special"><</span><span class="identifier">smart_pointer</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="special">></span></code> so that it can be used as the HeldType 69 for a class wrapper: 70 </p> 71<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">pointee</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 72<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="keyword">class</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 73<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">third_party_lib</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 74 75<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span> 76<span class="special">{</span> 77 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> <span class="keyword">struct</span> <span class="identifier">pointee</span><span class="special"><</span><span class="identifier">smart_pointer</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="special">></span> 78 <span class="special">{</span> 79 <span class="keyword">typedef</span> <span class="identifier">T</span> <span class="identifier">type</span><span class="special">;</span> 80 <span class="special">};</span> 81<span class="special">}}</span> 82 83<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">pointee_demo</span><span class="special">)</span> 84<span class="special">{</span> 85 <span class="identifier">class_</span><span class="special"><</span><span class="identifier">third_party_class</span><span class="special">,</span> <span class="identifier">smart_pointer</span><span class="special"><</span><span class="identifier">third_party_class</span><span class="special">></span> <span class="special">>(</span><span class="string">"third_party_class"</span><span class="special">)</span> 86 <span class="special">.</span><span class="identifier">def</span><span class="special">(...)</span> 87 <span class="special">...</span> 88 <span class="special">;</span> 89<span class="special">}</span> 90</pre> 91</div> 92</div> 93<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 94<td align="left"></td> 95<td align="right"><div class="copyright-footer">Copyright © 2002-2005, 2015 David Abrahams, Stefan Seefeld<p> 96 Distributed under the Boost Software License, Version 1.0. (See accompanying 97 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a> 98 </p> 99</div></td> 100</tr></table> 101<hr> 102<div class="spirit-nav"> 103<a accesskey="p" href="boost_python_instance_holder_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../utility_and_infrastructure.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_handle_hpp.html"><img src="../../images/next.png" alt="Next"></a> 104</div> 105</body> 106</html> 107