• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>boost/python/raw_function.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="../function_invocation_and_creation.html" title="Chapter 4. Function Invocation and Creation">
9<link rel="prev" href="boost_python_ptr_hpp.html" title="boost/python/ptr.hpp">
10<link rel="next" href="function_documentation.html" title="Function documentation">
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_ptr_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.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="function_documentation.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="function_invocation_and_creation.boost_python_raw_function_hpp"></a><a class="link" href="boost_python_raw_function_hpp.html" title="boost/python/raw_function.hpp">boost/python/raw_function.hpp</a>
21</h2></div></div></div>
22<div class="toc"><dl class="toc">
23<dt><span class="section"><a href="boost_python_raw_function_hpp.html#function_invocation_and_creation.boost_python_raw_function_hpp.introduction">Introduction</a></span></dt>
24<dt><span class="section"><a href="boost_python_raw_function_hpp.html#function_invocation_and_creation.boost_python_raw_function_hpp.function_raw_function">Function
25        <code class="computeroutput"><span class="identifier">raw_function</span></code></a></span></dt>
26<dt><span class="section"><a href="boost_python_raw_function_hpp.html#function_invocation_and_creation.boost_python_raw_function_hpp.example">Example</a></span></dt>
27</dl></div>
28<div class="section">
29<div class="titlepage"><div><div><h3 class="title">
30<a name="function_invocation_and_creation.boost_python_raw_function_hpp.introduction"></a><a class="link" href="boost_python_raw_function_hpp.html#function_invocation_and_creation.boost_python_raw_function_hpp.introduction" title="Introduction">Introduction</a>
31</h3></div></div></div>
32<p>
33          <code class="computeroutput"><span class="identifier">raw_function</span><span class="special">(...)</span></code>
34          is used to convert a function taking a <a class="link" href="../object_wrappers/boost_python_tuple_hpp.html#object_wrappers.boost_python_tuple_hpp.class_tuple" title="Class tuple"><code class="computeroutput"><span class="identifier">tuple</span></code></a> and a <a class="link" href="../object_wrappers.html#object_wrappers.boost_python_dict_hpp.class_dict" title="Class dict"><code class="computeroutput"><span class="identifier">dict</span></code></a> into a Python callable object
35          which accepts a variable number of arguments and arbitrary keyword arguments.
36        </p>
37</div>
38<div class="section">
39<div class="titlepage"><div><div><h3 class="title">
40<a name="function_invocation_and_creation.boost_python_raw_function_hpp.function_raw_function"></a><a class="link" href="boost_python_raw_function_hpp.html#function_invocation_and_creation.boost_python_raw_function_hpp.function_raw_function" title="Function raw_function">Function
41        <code class="computeroutput"><span class="identifier">raw_function</span></code></a>
42</h3></div></div></div>
43<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">&gt;</span>
44<span class="identifier">object</span> <span class="identifier">raw_function</span><span class="special">(</span><span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">min_args</span> <span class="special">=</span> <span class="number">0</span><span class="special">);</span>
45</pre>
46<div class="variablelist">
47<p class="title"><b></b></p>
48<dl class="variablelist">
49<dt><span class="term">Requires</span></dt>
50<dd><p>
51                f(tuple(), dict()) is well-formed.
52              </p></dd>
53<dt><span class="term">Returns</span></dt>
54<dd><p>
55                a callable object which requires at least min_args arguments. When
56                called, the actual non-keyword arguments will be passed in a tuple
57                as the first argument to f, and the keyword arguments will be passed
58                in a dict as the second argument to f.
59              </p></dd>
60</dl>
61</div>
62</div>
63<div class="section">
64<div class="titlepage"><div><div><h3 class="title">
65<a name="function_invocation_and_creation.boost_python_raw_function_hpp.example"></a><a class="link" href="boost_python_raw_function_hpp.html#function_invocation_and_creation.boost_python_raw_function_hpp.example" title="Example">Example</a>
66</h3></div></div></div>
67<p>
68          C++:
69        </p>
70<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">def</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
71<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">tuple</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
72<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">dict</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
73<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">module</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
74<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">raw_function</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
75
76<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span>
77
78<span class="identifier">tuple</span> <span class="identifier">raw</span><span class="special">(</span><span class="identifier">tuple</span> <span class="identifier">args</span><span class="special">,</span> <span class="identifier">dict</span> <span class="identifier">kw</span><span class="special">)</span>
79<span class="special">{</span>
80    <span class="keyword">return</span> <span class="identifier">make_tuple</span><span class="special">(</span><span class="identifier">args</span><span class="special">,</span> <span class="identifier">kw</span><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">raw_test</span><span class="special">)</span>
84<span class="special">{</span>
85    <span class="identifier">def</span><span class="special">(</span><span class="string">"raw"</span><span class="special">,</span> <span class="identifier">raw_function</span><span class="special">(</span><span class="identifier">raw</span><span class="special">));</span>
86<span class="special">}</span>
87</pre>
88<p>
89          Python:
90        </p>
91<pre class="programlisting"><span class="special">&gt;&gt;&gt;</span> <span class="identifier">from</span> <span class="identifier">raw_test</span> <span class="identifier">import</span> <span class="special">*</span>
92
93<span class="special">&gt;&gt;&gt;</span> <span class="identifier">raw</span><span class="special">(</span><span class="number">3</span><span class="special">,</span> <span class="number">4</span><span class="special">,</span> <span class="identifier">foo</span> <span class="special">=</span> <span class="char">'bar'</span><span class="special">,</span> <span class="identifier">baz</span> <span class="special">=</span> <span class="number">42</span><span class="special">)</span>
94<span class="special">((</span><span class="number">3</span><span class="special">,</span> <span class="number">4</span><span class="special">),</span> <span class="special">{</span><span class="char">'foo'</span><span class="special">:</span> <span class="char">'bar'</span><span class="special">,</span> <span class="char">'baz'</span><span class="special">:</span> <span class="number">42</span><span class="special">})</span>
95</pre>
96</div>
97</div>
98<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
99<td align="left"></td>
100<td align="right"><div class="copyright-footer">Copyright © 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
101        Distributed under the Boost Software License, Version 1.0. (See accompanying
102        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>
103      </p>
104</div></td>
105</tr></table>
106<hr>
107<div class="spirit-nav">
108<a accesskey="p" href="boost_python_ptr_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function_invocation_and_creation.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="function_documentation.html"><img src="../../images/next.png" alt="Next"></a>
109</div>
110</body>
111</html>
112