• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[section boost/python/long.hpp]
2[section Introduction]
3Exposes a [link concepts.objectwrapper.typewrapper_concept_requirements TypeWrapper] for the Python [@http://www.python.org/doc/current/lib/typesnumeric.html long] integer type.
4[endsect]
5[section Class `long_`]
6Exposes the [@http://www.python.org/doc/current/lib/typesnumeric.html numeric type protocol] of Python's built-in `long` type. The semantics of the constructors and member functions defined below can be fully understood by reading the [link concepts.objectwrapper.typewrapper_concept_requirements TypeWrapper] concept definition. Since `long_` is publicly derived from [link object_wrappers.boost_python_object_hpp.class_object `object`], the public `object` interface applies to `long_` instances as well.
7``
8namespace boost { namespace python
9{
10  class long_ : public object
11  {
12   public:
13      long_(); // new long_
14
15      template <class T>
16      explicit long_(T const& rhs);
17
18      template <class T, class U>
19      long_(T const& rhs, U const& base);
20  };
21}}
22``
23[endsect]
24[section Example]
25``
26namespace python = boost::python;
27
28// compute a factorial without overflowing
29python::long_ fact(long n)
30{
31   if (n == 0)
32      return python::long_(1);
33   else
34      return n * fact(n - 1);
35}
36``
37[endsect]
38[endsect]
39