Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.

Boost.Python

Header <boost/python/def.hpp>

Contents

Introduction
Functions
def
Example

Introduction

def() is the function which can be used to expose C++ functions and callable objects as Python functions in the current scope.

Functions

def
template <class F>
void def(char const* name, F f);

template <class Fn, class A1>
void def(char const* name, Fn fn, A1 const&);

template <class Fn, class A1, class A2>
void def(char const* name, Fn fn, A1 const&, A2 const&);

template <class Fn, class A1, class A2, class A3>
void def(char const* name, Fn fn, A1 const&, A2 const&, A3 const&);
Requires: name is an ntbs which conforms to Python's identifier naming rules.
Memnonic Name Requirements/Type properties Effects
docstring Any ntbs. Value will be bound to the __doc__ attribute of the resulting method overload.
policies A model of CallPolicies A copy will be used as the call policies of the resulting method overload.
keywords The result of a keyword-expression specifying no more arguments than the arity of fn. A copy will be used as the call policies of the resulting method overload.

Example

#include <boost/python/def.hpp>
#include <boost/python/module.hpp>
#include <boost/python/args.hpp>

using namespace boost::python;

char const* foo(int x, int y) { return "foo"; }

BOOST_PYTHON_MODULE(def_test)
{
    def("foo", foo, args("x", "y"), "foo's docstring");
}

7 March, 2003

© Copyright Dave Abrahams 2002.