mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 16:32:16 +00:00
https://svn.boost.org/svn/boost/trunk ........ r43206 | danieljames | 2008-02-10 09:55:03 +0000 (Sun, 10 Feb 2008) | 1 line Fix some broken links. ........ r43209 | danieljames | 2008-02-10 14:56:22 +0000 (Sun, 10 Feb 2008) | 1 line Link to people pages on the website, as they've been removed from the download. ........ r43210 | danieljames | 2008-02-10 15:02:17 +0000 (Sun, 10 Feb 2008) | 1 line Point links to the pages that used to be in 'more' to the site. ........ r43212 | danieljames | 2008-02-10 16:10:16 +0000 (Sun, 10 Feb 2008) | 1 line Fix links on the home page as well. ........ r43213 | danieljames | 2008-02-10 16:21:22 +0000 (Sun, 10 Feb 2008) | 1 line Generated documentation which is no longer generated. ........ [SVN r43214]
150 lines
4.3 KiB
HTML
150 lines
4.3 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
|
|
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
|
<!-- Software License, Version 1.0. (See accompanying -->
|
|
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content=
|
|
"HTML Tidy for Windows (vers 1st August 2002), 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/copy_const_reference.hpp></title>
|
|
</head>
|
|
|
|
<body>
|
|
<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>
|
|
|
|
<td valign="top">
|
|
<h1 align="center"><a href="../index.html">Boost.Python</a></h1>
|
|
|
|
<h2 align="center">Header
|
|
<boost/python/copy_const_reference.hpp></h2>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<hr>
|
|
|
|
<h2>Contents</h2>
|
|
|
|
<dl class="page-index">
|
|
<dt><a href="#classes">Classes</a></dt>
|
|
|
|
<dd>
|
|
<dl class="page-index">
|
|
<dt><a href="#copy_const_reference-spec">Class
|
|
<code>copy_const_reference</code></a></dt>
|
|
|
|
<dd>
|
|
<dl class="page-index">
|
|
<dt><a href="#copy_const_reference-spec-synopsis">Class
|
|
<code>copy_const_reference</code> synopsis</a></dt>
|
|
|
|
<dt><a href="#copy_const_reference-spec-metafunctions">Class
|
|
<code>copy_const_reference</code> metafunctions</a></dt>
|
|
</dl>
|
|
</dd>
|
|
</dl>
|
|
</dd>
|
|
|
|
<dt><a href="#examples">Example</a></dt>
|
|
</dl>
|
|
<hr>
|
|
|
|
<h2><a name="classes"></a>Classes</h2>
|
|
|
|
<h3><a name="copy_const_reference-spec"></a>Class
|
|
<code>copy_const_reference</code></h3>
|
|
|
|
<p><code>copy_const_reference</code> is a model of <a href=
|
|
"ResultConverter.html#ResultConverterGenerator-concept">ResultConverterGenerator</a>
|
|
which can be used to wrap C++ functions returning a reference-to-const
|
|
type such that the referenced value is copied into a new Python
|
|
object.</p>
|
|
|
|
<h4><a name="copy_const_reference-spec-synopsis"></a>Class
|
|
<code>copy_const_reference</code> synopsis</h4>
|
|
<pre>
|
|
namespace boost { namespace python
|
|
{
|
|
struct copy_const_reference
|
|
{
|
|
template <class T> struct apply;
|
|
};
|
|
}}
|
|
</pre>
|
|
|
|
<h4><a name="copy_const_reference-spec-metafunctions"></a>Class
|
|
<code>copy_const_reference</code> metafunctions</h4>
|
|
<pre>
|
|
template <class T> struct apply
|
|
</pre>
|
|
|
|
<dl class="metafunction-semantics">
|
|
<dt><b>Requires:</b> <code>T</code> is <code>U const&</code> for
|
|
some <code>U</code>.</dt>
|
|
|
|
<dt><b>Returns:</b> <code>typedef <a href=
|
|
"to_python_value.html#to_python_value-spec">to_python_value</a><T>
|
|
type;</code></dt>
|
|
</dl>
|
|
|
|
<h2><a name="examples"></a>Example</h2>
|
|
|
|
<h3>C++ Module Definition</h3>
|
|
<pre>
|
|
#include <boost/python/module.hpp>
|
|
#include <boost/python/class.hpp>
|
|
#include <boost/python/copy_const_reference.hpp>
|
|
#include <boost/python/return_value_policy.hpp>
|
|
|
|
// classes to wrap
|
|
struct Bar { int x; }
|
|
|
|
struct Foo {
|
|
Foo(int x) : { b.x = x; }
|
|
Bar const& get_bar() const { return b; }
|
|
private:
|
|
Bar b;
|
|
};
|
|
|
|
// Wrapper code
|
|
using namespace boost::python;
|
|
BOOST_PYTHON_MODULE(my_module)
|
|
{
|
|
class_<Bar>("Bar");
|
|
|
|
class_<Foo>("Foo", init<int>())
|
|
.def("get_bar", &Foo::get_bar
|
|
, return_value_policy<copy_const_reference>())
|
|
;
|
|
}
|
|
</pre>
|
|
|
|
<h3>Python Code</h3>
|
|
<pre>
|
|
>>> from my_module import *
|
|
>>> f = Foo(3) # create a Foo object
|
|
>>> b = f.get_bar() # make a copy of the internal Bar object
|
|
</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>
|
|
|
|
<p><i>© Copyright <a href=
|
|
"http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a> 2002.</i></p>
|
|
</body>
|
|
</html>
|
|
|