mirror of
https://github.com/boostorg/python.git
synced 2026-01-21 17:12:22 +00:00
889 lines
23 KiB
HTML
Executable File
889 lines
23 KiB
HTML
Executable File
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
|
|
<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/operators.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="../../../../c++boost.gif" 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/operators.hpp></h2>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<hr>
|
|
|
|
<h2>Contents</h2>
|
|
|
|
<dl class="page-index">
|
|
<dt><a href="#introduction">Introduction</a></dt>
|
|
|
|
<dt><a href="#classes">Classes</a></dt>
|
|
|
|
<dd>
|
|
<dl class="page-index">
|
|
<dt><a href="#self_t-spec">Class
|
|
<code>self_ns::self_t</code></a></dt>
|
|
|
|
<dd>
|
|
<dl class="page-index">
|
|
<dt><a href="#self_t-spec-synopsis">Class <code>self_t</code>
|
|
synopsis</a></dt>
|
|
|
|
<dt><a href="#self_t-spec-inplace">Class <code>self_t</code>
|
|
inplace operators</a></dt>
|
|
|
|
<dt><a href="#self_t-spec-comparisons">Class
|
|
<code>self_t</code> comparison functions</a></dt>
|
|
|
|
<dt><a href="#self_t-spec-ops">Class <code>self_t</code>
|
|
non-member operations</a></dt>
|
|
|
|
<dt><a href="#self_t-spec-value-unary-ops">Class
|
|
<code>self_t</code> unary operations</a></dt>
|
|
|
|
<dt><a href="#self_t-spec-value-value-ops">Class
|
|
<code>self_t</code> value operations</a></dt>
|
|
</dl>
|
|
</dd>
|
|
|
|
<dt><a href="#other-spec">Class template
|
|
<code>other</code></a></dt>
|
|
|
|
<dd>
|
|
<dl class="page-index">
|
|
<dt><a href="#other-spec-synopsis">Class <code>other</code>
|
|
synopsis</a></dt>
|
|
</dl>
|
|
</dd>
|
|
|
|
<dt><a href="#operator_-spec">Class template
|
|
<code>operator_</code></a></dt>
|
|
|
|
<dd>
|
|
<dl class="page-index">
|
|
<dt><a href="#operator_-spec-synopsis">Class
|
|
<code>operator_</code> synopsis</a></dt>
|
|
</dl>
|
|
</dd>
|
|
</dl>
|
|
</dd>
|
|
|
|
<dt><a href="#objects">Objects</a></dt>
|
|
|
|
<dd>
|
|
<dl class="page-index">
|
|
<dt><a href="#self-spec">self</a></dt>
|
|
</dl>
|
|
</dd>
|
|
|
|
<dt><a href="#examples">Examples</a></dt>
|
|
</dl>
|
|
<hr>
|
|
|
|
<h2><a name="introduction"></a>Introduction</h2>
|
|
|
|
<p><code><boost/python/operators.hpp></code> provides types and
|
|
functions for automatically generating Python <a href=
|
|
"http://www.python.org/doc/ref/specialnames.html">special methods</a>
|
|
from the corresponding C++ constructs. Most of these constructs are
|
|
operator expressions, hence the name. To use the facility, substitute the
|
|
<code><a href="#self-spec">self</a></code> object for an object of the
|
|
class type being wrapped in the expression to be exposed, and pass the
|
|
result to <a href=
|
|
"class.html#class_-spec-modifiers">class_<>::def()</a>. Much of
|
|
what is exposed in this header should be considered part of the
|
|
implementation, so is not documented in detail here.</p>
|
|
|
|
<h2><a name="classes"></a>Classes</h2>
|
|
|
|
<h3><a name="self_t-spec"></a>Class <code>self_ns::self_t</code></h3>
|
|
|
|
<p><code>self_ns::self_t</code> is the actual type of the <a href=
|
|
"#self-spec"><code>self</code></a> object. The library isolates
|
|
<code>self_t</code> in its own namespace, <code>self_ns</code>, in order
|
|
to prevent the generalized operator templates which operate on it from
|
|
being found by argument-dependent lookup in other contexts. This should
|
|
be considered an implementation detail, since users should never have to
|
|
mention <code>self_t</code> directly.</p>
|
|
|
|
<h4><a name="self_t-spec-synopsis"></a>Class <code>self_ns::self_t</code>
|
|
synopsis</h4>
|
|
<pre>
|
|
namespace boost { namespace python { namespace self_ns {
|
|
{
|
|
<i>unspecified-type-declaration</i> self_t;
|
|
|
|
// inplace operators
|
|
template <class T> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator+=(self_t, T);
|
|
template <class T> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator-=(self_t, T);
|
|
template <class T> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator*=(self_t, T);
|
|
template <class T> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator/=(self_t, T);
|
|
template <class T> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator%=(self_t, T);
|
|
template <class T> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator>>=(self_t, T);
|
|
template <class T> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator<<=(self_t, T);
|
|
template <class T> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator&=(self_t, T);
|
|
template <class T> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator^=(self_t, T);
|
|
template <class T> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator|=(self_t, T);
|
|
|
|
// comparisons
|
|
template <class L, class R> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator==(L const&, R const&);
|
|
template <class L, class R> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator!=(L const&, R const&);
|
|
template <class L, class R> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator<(L const&, R const&);
|
|
template <class L, class R> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator>(L const&, R const&);
|
|
template <class L, class R> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator<=(L const&, R const&);
|
|
template <class L, class R> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator>=(L const&, R const&);
|
|
|
|
// non-member operations
|
|
template <class L, class R> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator+(L const&, R const&);
|
|
template <class L, class R> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator-(L const&, R const&);
|
|
template <class L, class R> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator*(L const&, R const&);
|
|
template <class L, class R> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator/(L const&, R const&);
|
|
template <class L, class R> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator%(L const&, R const&);
|
|
template <class L, class R> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator>>(L const&, R const&);
|
|
template <class L, class R> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator<<(L const&, R const&);
|
|
template <class L, class R> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator&(L const&, R const&);
|
|
template <class L, class R> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator^(L const&, R const&);
|
|
template <class L, class R> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator|(L const&, R const&);
|
|
template <class L, class R> <a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> pow(L const&, R const&);
|
|
|
|
// unary operations
|
|
<a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator-(self_t);
|
|
<a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator+(self_t);
|
|
<a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> operator~(self_t);
|
|
|
|
// value operations
|
|
<a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> int_(self_t);
|
|
<a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> long_(self_t);
|
|
<a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> float_(self_t);
|
|
<a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> complex_(self_t);
|
|
<a href=
|
|
"#operator_-spec">operator_</a><<i>unspecified</i>> str(self_t);
|
|
|
|
}}};
|
|
</pre>
|
|
The tables below describe the methods generated when the results of the
|
|
expressions described are passed as arguments to <a href=
|
|
"class.html#class_-spec-modifiers">class_<>::def()</a>.
|
|
<code><b>x</b></code> is an object of the class type being wrapped.
|
|
|
|
<h4><a name="self_t-spec-inplace"></a>Class <code>self_t</code> inplace
|
|
operators</h4>
|
|
In the table below, If <code><b>r</b></code> is an object of type
|
|
<code><a href="#other-spec">other</a><T></code>,
|
|
<code><b>y</b></code> is an object of type <code>T</code>; otherwise,
|
|
<code><b>y</b></code> is an object of the same type as
|
|
<code><b>r</b></code>.
|
|
|
|
<table border="1" summary="self_t inplace operators">
|
|
<tr>
|
|
<th>C++ Expression</th>
|
|
|
|
<th>Python Method Name</th>
|
|
|
|
<th>C++ Implementation</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>self += r</code></td>
|
|
|
|
<td><code>__iadd__</code></td>
|
|
|
|
<td><code>x += y</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>self -= r</code></td>
|
|
|
|
<td><code>__isub__</code></td>
|
|
|
|
<td><code>x -= y</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>self *= r</code></td>
|
|
|
|
<td><code>__imul__</code></td>
|
|
|
|
<td><code>x *= y</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>self /= r</code></td>
|
|
|
|
<td><code>__idiv__</code></td>
|
|
|
|
<td><code>x /= y</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>self %= r</code></td>
|
|
|
|
<td><code>__imod__</code></td>
|
|
|
|
<td><code>x %= y</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>self >>= r</code></td>
|
|
|
|
<td><code>__irshift__</code></td>
|
|
|
|
<td><code>x >>= y</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>self <<= r</code></td>
|
|
|
|
<td><code>__ilshift__</code></td>
|
|
|
|
<td><code>x <<= y</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>self &= r</code></td>
|
|
|
|
<td><code>__iand__</code></td>
|
|
|
|
<td><code>x &= y</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>self ^= r</code></td>
|
|
|
|
<td><code>__ixor__</code></td>
|
|
|
|
<td><code>x ^= y</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td><code>self |= r</code></td>
|
|
|
|
<td><code>__ior__</code></td>
|
|
|
|
<td><code>x |= y</code></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h4><a name="self_t-spec-comparisons"></a>Class <code>self_t</code>
|
|
comparison functions</h4>
|
|
In the tables below, if <code><b>r</b></code> is of type <code><a href=
|
|
"#self_t-spec">self_t</a></code>, <code><b>y</b></code> is an object of
|
|
the same type as <code>x</code>; <br>
|
|
if <code><b>l</b></code> or <code><b>r</b></code> is an object of type
|
|
<code><a href="#other-spec">other</a><T></code>,
|
|
<code><b>y</b></code> is an object of type <code>T</code>; <br>
|
|
otherwise, <code><b>y</b></code> is an object of the same type as
|
|
<code><b>l</b></code> or <code><b>r</b></code>.<br>
|
|
<code><b>l</b></code> is never of type <code><a href=
|
|
"#self_t-spec">self_t</a></code>.
|
|
|
|
<p>The column of <b>Python Expressions</b> illustrates the expressions
|
|
that will be supported in Python for objects convertible to the types of
|
|
<code>x</code> and <code>y</code>. The secondary operation arises due to
|
|
Python's <a href=
|
|
"http://www.python.org/doc/ref/customization.html#l2h-89">reflection
|
|
rules</a> for rich comparison operators, and are only used when the
|
|
corresponding operation is not defined as a method of the <code>y</code>
|
|
object.</p>
|
|
|
|
<table border="1" summary="self_t comparison functions">
|
|
<tr>
|
|
<th>C++ Expression</th>
|
|
|
|
<th>Python Method Name</th>
|
|
|
|
<th>C++ Implementation</th>
|
|
|
|
<th>Python Expressions<br>
|
|
(primary, secondary)</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>self == r</td>
|
|
|
|
<td>__eq__</td>
|
|
|
|
<td>x == y</td>
|
|
|
|
<td>x == y, y == x</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>l == self</td>
|
|
|
|
<td>__eq__</td>
|
|
|
|
<td>y == x</td>
|
|
|
|
<td>y == x, x == y</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>self != r</td>
|
|
|
|
<td>__ne__</td>
|
|
|
|
<td>x != y</td>
|
|
|
|
<td>x != y, y != x</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>l != self</td>
|
|
|
|
<td>__ne__</td>
|
|
|
|
<td>y != x</td>
|
|
|
|
<td>y != x, x != y</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>self < r</td>
|
|
|
|
<td>__lt__</td>
|
|
|
|
<td>x < y</td>
|
|
|
|
<td>x < y, y > x</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>l < self</td>
|
|
|
|
<td>__gt__</td>
|
|
|
|
<td>y < x</td>
|
|
|
|
<td>y > x, x < y</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>self > r</td>
|
|
|
|
<td>__gt__</td>
|
|
|
|
<td>x > y</td>
|
|
|
|
<td>x > y, y < x</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>l > self</td>
|
|
|
|
<td>__lt__</td>
|
|
|
|
<td>y > x</td>
|
|
|
|
<td>y < x, x > y</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>self <= r</td>
|
|
|
|
<td>__le__</td>
|
|
|
|
<td>x <= y</td>
|
|
|
|
<td>x <= y, y >= x</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>l <= self</td>
|
|
|
|
<td>__ge__</td>
|
|
|
|
<td>y <= x</td>
|
|
|
|
<td>y >= x, x <= y</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>self >= r</td>
|
|
|
|
<td>__ge__</td>
|
|
|
|
<td>x >= y</td>
|
|
|
|
<td>x >= y, y <= x</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>l >= self</td>
|
|
|
|
<td>__le__</td>
|
|
|
|
<td>y >= x</td>
|
|
|
|
<td>y <= x, x >= y</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h4><a name="self_t-spec-ops"></a>Class <code>self_t</code> non-member
|
|
operations</h4>
|
|
The operations whose names begin with "<code>__r</code>" below will only
|
|
be called if the left-hand operand does not already support the given
|
|
operation, as described <a href=
|
|
"http://www.python.org/doc/current/ref/numeric-types.html#l2h-152">here</a>.
|
|
|
|
|
|
<table border="1" summary="self_t non-member operations">
|
|
<tr>
|
|
<th>C++ Expression</th>
|
|
|
|
<th>Python Method Name</th>
|
|
|
|
<th>C++ Implementation</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>self + r</td>
|
|
|
|
<td>__add__</td>
|
|
|
|
<td>x + y</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>l + self</td>
|
|
|
|
<td>__radd__</td>
|
|
|
|
<td>y + x</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>self - r</td>
|
|
|
|
<td>__sub__</td>
|
|
|
|
<td>x - y</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>l - self</td>
|
|
|
|
<td>__rsub__</td>
|
|
|
|
<td>y - x</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>self * r</td>
|
|
|
|
<td>__mul__</td>
|
|
|
|
<td>x * y</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>l * self</td>
|
|
|
|
<td>__rmul__</td>
|
|
|
|
<td>y * x</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>self / r</td>
|
|
|
|
<td>__div__</td>
|
|
|
|
<td>x / y</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>l / self</td>
|
|
|
|
<td>__rdiv__</td>
|
|
|
|
<td>y / x</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>self % r</td>
|
|
|
|
<td>__mod__</td>
|
|
|
|
<td>x % y</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>l % self</td>
|
|
|
|
<td>__rmod__</td>
|
|
|
|
<td>y % x</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>self >> r</td>
|
|
|
|
<td>__rshift__</td>
|
|
|
|
<td>x >> y</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>l >> self</td>
|
|
|
|
<td>__rrshift__</td>
|
|
|
|
<td>y >> x</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>self << r</td>
|
|
|
|
<td>__lshift__</td>
|
|
|
|
<td>x << y</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>l << self</td>
|
|
|
|
<td>__rlshift__</td>
|
|
|
|
<td>y << x</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>self & r</td>
|
|
|
|
<td>__and__</td>
|
|
|
|
<td>x & y</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>l & self</td>
|
|
|
|
<td>__rand__</td>
|
|
|
|
<td>y & x</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>self ^ r</td>
|
|
|
|
<td>__xor__</td>
|
|
|
|
<td>x ^ y</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>l ^ self</td>
|
|
|
|
<td>__rxor__</td>
|
|
|
|
<td>y ^ x</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>self | r</td>
|
|
|
|
<td>__or__</td>
|
|
|
|
<td>x | y</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>l | self</td>
|
|
|
|
<td>__ror__</td>
|
|
|
|
<td>y | x</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>pow(self, r)</td>
|
|
|
|
<td>__pow__</td>
|
|
|
|
<td>pow(x, y)</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>pow(l, self)</td>
|
|
|
|
<td>__rpow__</td>
|
|
|
|
<td>pow(y, x)</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h4><a name="self_t-spec-unary-ops"></a>Class <code>self_t</code> unary
|
|
operations</h4>
|
|
|
|
<table border="1" summary="self_t unary operations">
|
|
<tr>
|
|
<th>C++ Expression</th>
|
|
|
|
<th>Python Method Name</th>
|
|
|
|
<th>C++ Implementation</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>-self</td>
|
|
|
|
<td>__neg__</td>
|
|
|
|
<td>-x</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>+self</td>
|
|
|
|
<td>__pos__</td>
|
|
|
|
<td>+x</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>~self</td>
|
|
|
|
<td>__invert__</td>
|
|
|
|
<td>~x</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h4><a name="self_t-spec-value-ops"></a>Class <code>self_t</code> value
|
|
operations</h4>
|
|
|
|
<table border="1" summary="self_t value operations">
|
|
<tr>
|
|
<th>C++ Expression</th>
|
|
|
|
<th>Python Method Name</th>
|
|
|
|
<th>C++ Implementation</th>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>int_(self)</td>
|
|
|
|
<td>__int__</td>
|
|
|
|
<td>long(x)</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>long_</td>
|
|
|
|
<td>__long__</td>
|
|
|
|
<td>PyLong_FromLong(x)</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>float_</td>
|
|
|
|
<td>__float__</td>
|
|
|
|
<td>double(x)</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>complex_</td>
|
|
|
|
<td>__complex__</td>
|
|
|
|
<td>std::complex<double>(x)</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>str</td>
|
|
|
|
<td>__str__</td>
|
|
|
|
<td><a href=
|
|
"../../../conversion/lexical_cast.htm#lexical_cast">lexical_cast</a><std::string>(x)</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<h3><a name="other-spec"></a>Class Template <code>other</code></h3>
|
|
|
|
<p>Instances of <code>other<T></code> can be used in operator
|
|
expressions with <a href="#self-spec">self</a>; the result is equivalent
|
|
to the same expression with a <code>T</code> object in place of
|
|
<code>other<T></code>. Use <code>other<T></code> to prevent
|
|
construction of a <code>T</code> object in case it is heavyweight, when
|
|
no constructor is available, or simply for clarity.</p>
|
|
|
|
<h4><a name="other-spec-synopsis"></a>Class Template other synopsis</h4>
|
|
<pre>
|
|
namespace boost { namespace python
|
|
{
|
|
template <class T>
|
|
struct other
|
|
{
|
|
};
|
|
}}
|
|
</pre>
|
|
<!-- -->
|
|
|
|
<h3><a name="operator_-spec"></a>Class Template
|
|
<code>detail::operator_</code></h3>
|
|
|
|
<p>Instantiations of <code>detail::operator_<></code> are used as
|
|
the return type of operator expressions involving <code><a href=
|
|
"#self-spec">self</a></code>. This should be considered an implementation
|
|
detail and is only documented here as a way of showing how the result of
|
|
<code>self</code>-expressions match calls to <a href=
|
|
"class.html#class_-spec-modifiers">class_<>::def()</a>.</p>
|
|
|
|
<h4><a name="operator_-spec-synopsis"></a>Class Template
|
|
<code>detail::operator_</code> synopsis</h4>
|
|
<pre>
|
|
namespace boost { namespace python { namespace detail
|
|
{
|
|
template <<i>unspecified</i>>
|
|
struct operator_
|
|
{
|
|
};
|
|
}}}
|
|
</pre>
|
|
|
|
<h2><a name="objects"></a>Objects</h2>
|
|
|
|
<p><a name="self-spec"><code>self</code></a></p>
|
|
<pre>
|
|
namespace boost { namespace python
|
|
{
|
|
using self_ns::self;
|
|
}}
|
|
</pre>
|
|
|
|
<h2><a name="examples"></a>Example</h2>
|
|
<pre>
|
|
#include <boost/python/module.hpp>
|
|
#include <boost/python/class.hpp>
|
|
#include <boost/python/operators.hpp>
|
|
#include <boost/operators.hpp>
|
|
|
|
struct number
|
|
: boost::<a href=
|
|
"../../../utility/operators.htm#grpd_oprs">integer_arithmetic</a><number>
|
|
{
|
|
number(long x_) : x(x_) {}
|
|
operator long() const { return x; }
|
|
|
|
number& operator+=(number const& rhs)
|
|
{ x += rhs }
|
|
number& operator-=(number const& rhs);
|
|
{ x -= rhs }
|
|
number& operator*=(number const& rhs)
|
|
{ x *= rhs }
|
|
number& operator/=(number const& rhs);
|
|
{ x /= rhs }
|
|
number& operator%=(number const& rhs);
|
|
{ x %= rhs }
|
|
|
|
long x;
|
|
};
|
|
|
|
using namespace boost::python;
|
|
BOOST_PYTHON_MODULE(demo)
|
|
{
|
|
class_<number>("number")
|
|
// interoperate with self
|
|
.def(self += self)
|
|
.def(self + self)
|
|
.def(self -= self)
|
|
.def(self - self)
|
|
.def(self *= self)
|
|
.def(self * self)
|
|
.def(self /= self)
|
|
.def(self / self)
|
|
.def(self %= self)
|
|
.def(self % self)
|
|
|
|
// Convert to Python int
|
|
.def(int_(self))
|
|
|
|
// interoperate with long
|
|
.def(self += long())
|
|
.def(self + long())
|
|
.def(long() + self)
|
|
.def(self -= long())
|
|
.def(self - long())
|
|
.def(long() - self)
|
|
.def(self *= long())
|
|
.def(self * long())
|
|
.def(long() * self)
|
|
.def(self /= long())
|
|
.def(self / long())
|
|
.def(long() / self)
|
|
.def(self %= long())
|
|
.def(self % long())
|
|
.def(long() % self)
|
|
;
|
|
}
|
|
</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=
|
|
"../../../../people/dave_abrahams.htm">Dave Abrahams</a> 2002. All Rights
|
|
Reserved.</i></p>
|
|
</body>
|
|
</html>
|
|
|