1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>boost/python/long.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="../object_wrappers.html" title="Chapter 3. Object Wrappers"> 9<link rel="prev" href="boost_python_list_hpp.html" title="boost_python_list.hpp"> 10<link rel="next" href="boost_python_object_hpp.html" title="boost/python/object.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_list_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../object_wrappers.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_object_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="object_wrappers.boost_python_long_hpp"></a><a class="link" href="boost_python_long_hpp.html" title="boost/python/long.hpp">boost/python/long.hpp</a> 21</h2></div></div></div> 22<div class="toc"><dl class="toc"> 23<dt><span class="section"><a href="boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.introduction">Introduction</a></span></dt> 24<dt><span class="section"><a href="boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.class_long">Class 25 <code class="computeroutput"><span class="identifier">long_</span></code></a></span></dt> 26<dt><span class="section"><a href="boost_python_long_hpp.html#object_wrappers.boost_python_long_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="object_wrappers.boost_python_long_hpp.introduction"></a><a class="link" href="boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.introduction" title="Introduction">Introduction</a> 31</h3></div></div></div> 32<p> 33 Exposes a <a class="link" href="../concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements" title="TypeWrapper Concept Requirements">TypeWrapper</a> 34 for the Python <a href="http://www.python.org/doc/current/lib/typesnumeric.html" target="_top">long</a> 35 integer type. 36 </p> 37</div> 38<div class="section"> 39<div class="titlepage"><div><div><h3 class="title"> 40<a name="object_wrappers.boost_python_long_hpp.class_long"></a><a class="link" href="boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.class_long" title="Class long_">Class 41 <code class="computeroutput"><span class="identifier">long_</span></code></a> 42</h3></div></div></div> 43<p> 44 Exposes the <a href="http://www.python.org/doc/current/lib/typesnumeric.html" target="_top">numeric 45 type protocol</a> of Python's built-in <code class="computeroutput"><span class="keyword">long</span></code> 46 type. The semantics of the constructors and member functions defined below 47 can be fully understood by reading the <a class="link" href="../concepts/objectwrapper.html#concepts.objectwrapper.typewrapper_concept_requirements" title="TypeWrapper Concept Requirements">TypeWrapper</a> 48 concept definition. Since <code class="computeroutput"><span class="identifier">long_</span></code> 49 is publicly derived from <a class="link" href="boost_python_object_hpp.html#object_wrappers.boost_python_object_hpp.class_object" title="Class object"><code class="computeroutput"><span class="identifier">object</span></code></a>, the public <code class="computeroutput"><span class="identifier">object</span></code> interface applies to <code class="computeroutput"><span class="identifier">long_</span></code> instances as well. 50 </p> 51<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> 52<span class="special">{</span> 53 <span class="keyword">class</span> <span class="identifier">long_</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">object</span> 54 <span class="special">{</span> 55 <span class="keyword">public</span><span class="special">:</span> 56 <span class="identifier">long_</span><span class="special">();</span> <span class="comment">// new long_</span> 57 58 <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> 59 <span class="keyword">explicit</span> <span class="identifier">long_</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">rhs</span><span class="special">);</span> 60 61 <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">class</span> <span class="identifier">U</span><span class="special">></span> 62 <span class="identifier">long_</span><span class="special">(</span><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">rhs</span><span class="special">,</span> <span class="identifier">U</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">base</span><span class="special">);</span> 63 <span class="special">};</span> 64<span class="special">}}</span> 65</pre> 66</div> 67<div class="section"> 68<div class="titlepage"><div><div><h3 class="title"> 69<a name="object_wrappers.boost_python_long_hpp.example"></a><a class="link" href="boost_python_long_hpp.html#object_wrappers.boost_python_long_hpp.example" title="Example">Example</a> 70</h3></div></div></div> 71<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">python</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span> 72 73<span class="comment">// compute a factorial without overflowing</span> 74<span class="identifier">python</span><span class="special">::</span><span class="identifier">long_</span> <span class="identifier">fact</span><span class="special">(</span><span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span> 75<span class="special">{</span> 76 <span class="keyword">if</span> <span class="special">(</span><span class="identifier">n</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> 77 <span class="keyword">return</span> <span class="identifier">python</span><span class="special">::</span><span class="identifier">long_</span><span class="special">(</span><span class="number">1</span><span class="special">);</span> 78 <span class="keyword">else</span> 79 <span class="keyword">return</span> <span class="identifier">n</span> <span class="special">*</span> <span class="identifier">fact</span><span class="special">(</span><span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">);</span> 80<span class="special">}</span> 81</pre> 82</div> 83</div> 84<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 85<td align="left"></td> 86<td align="right"><div class="copyright-footer">Copyright © 2002-2005, 2015 David Abrahams, Stefan Seefeld<p> 87 Distributed under the Boost Software License, Version 1.0. (See accompanying 88 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> 89 </p> 90</div></td> 91</tr></table> 92<hr> 93<div class="spirit-nav"> 94<a accesskey="p" href="boost_python_list_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../object_wrappers.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_object_hpp.html"><img src="../../images/next.png" alt="Next"></a> 95</div> 96</body> 97</html> 98