Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Olivier B.
pybind11
Commits
8f4eb006
Commit
8f4eb006
authored
Oct 15, 2015
by
Wenzel Jakob
Browse files
last breaking change: be consistent about the project name
parent
607654f7
Changes
23
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
8f4eb006
...
...
@@ -7,7 +7,7 @@
cmake_minimum_required
(
VERSION 2.8
)
project
(
pybind
)
project
(
pybind
11
)
# Add a CMake parameter for choosing a desired Python version
set
(
PYBIND_PYTHON_VERSION
""
CACHE STRING
"Python version to use for compiling the example application"
)
...
...
@@ -55,13 +55,13 @@ include_directories(include)
# Create the binding library
add_library
(
example SHARED
include/pybind/cast.h
include/pybind/common.h
include/pybind/operators.h
include/pybind/pybind.h
include/pybind/pytypes.h
include/pybind/typeid.h
include/pybind/numpy.h
include/pybind
11
/cast.h
include/pybind
11
/common.h
include/pybind
11
/operators.h
include/pybind
11
/pybind
11
.h
include/pybind
11
/pytypes.h
include/pybind
11
/typeid.h
include/pybind
11
/numpy.h
example/example.cpp
example/example1.cpp
example/example2.cpp
...
...
docs/advanced.rst
View file @
8f4eb006
...
...
@@ -8,9 +8,9 @@ present:
.. code-block:: cpp
#include <pybind/pybind.h>
#include <pybind
11
/pybind
11
.h>
namespace py = pybind
;
namespace py = pybind
11
Operator overloading
====================
...
...
@@ -43,10 +43,10 @@ to Python.
.. code-block:: cpp
#include <pybind/operators.h>
#include <pybind
11
/operators.h>
PYBIND_PLUGIN(example) {
py::module m("example", "pybind example plugin");
py::module m("example", "pybind
11
example plugin");
py::class_<Vector2>(m, "Vector2")
.def(py::init<float, float>())
...
...
@@ -79,7 +79,7 @@ C++ side, or to perform other types of customization.
.. note::
To use the more convenient ``py::self`` notation, the additional
header file :file:`pybind/operators.h` must be included.
header file :file:`pybind
11
/operators.h` must be included.
.. seealso::
...
...
@@ -120,15 +120,15 @@ its return value upon execution.
};
}
After including the extra header file :file:`pybind/functional.h`, it is almost
After including the extra header file :file:`pybind
11
/functional.h`, it is almost
trivial to generate binding code for both of these functions.
.. code-block:: cpp
#include <pybind/functional.h>
#include <pybind
11
/functional.h>
PYBIND_PLUGIN(example) {
py::module m("example", "pybind example plugin");
py::module m("example", "pybind
11
example plugin");
m.def("func_arg", &func_arg);
m.def("func_ret", &func_ret);
...
...
@@ -200,7 +200,7 @@ Normally, the binding code for these classes would look as follows:
.. code-block:: cpp
PYBIND_PLUGIN(example) {
py::module m("example", "pybind example plugin");
py::module m("example", "pybind
11
example plugin");
py::class_<Animal> animal(m, "Animal");
animal
...
...
@@ -248,7 +248,7 @@ a default implementation. The binding code also needs a few minor adaptations
:emphasize-lines: 4,6,7
PYBIND_PLUGIN(example) {
py::module m("example", "pybind example plugin");
py::module m("example", "pybind
11
example plugin");
py::class_<PyAnimal> animal(m, "Animal");
animal
...
...
@@ -295,11 +295,11 @@ a virtual method call.
Passing STL data structures
===========================
When including the additional header file :file:`pybind/stl.h`, conversions
When including the additional header file :file:`pybind
11
/stl.h`, conversions
between ``std::vector<>`` and ``std::map<>`` and the Python ``list`` and
``dict`` data structures are automatically enabled. The types ``std::pair<>``
and ``std::tuple<>`` are already supported out of the box with just the core
:file:`pybind/pybind.h` header.
:file:`pybind
11
/pybind
11
.h` header.
.. note::
...
...
@@ -376,7 +376,7 @@ See below for an example that uses the
};
PYBIND_PLUGIN(example) {
py::module m("example", "pybind example plugin");
py::module m("example", "pybind
11
example plugin");
py::class_<Example>(m, "Example")
.def(py::init<>())
...
...
@@ -620,7 +620,7 @@ dense array of doubles in C-style ordering.
When it is invoked with a different type (e.g. an integer), the binding code
will attempt to cast the input into a NumPy array of the requested type.
Note that this feature requires the ``pybind/numpy.h`` header to be included.
Note that this feature requires the ``pybind
11
/numpy.h`` header to be included.
Vectorizing functions
=====================
...
...
@@ -633,7 +633,7 @@ N-D arrays) in addition to its normal arguments:
double my_func(int x, float y, double z);
After including the ``pybind/numpy.h`` header, this is extremely simple:
After including the ``pybind
11
/numpy.h`` header, this is extremely simple:
.. code-block:: cpp
...
...
docs/basics.rst
View file @
8f4eb006
...
...
@@ -37,7 +37,7 @@ Windows
On Windows, use the `CMake GUI`_ to create a Visual Studio project. Note that
only the 2015 release and newer versions are supported since pybind11 relies on
various C++11 language features that break older versions of Visual Studio.
After running CMake, open the created :file:`pybind.sln` file and perform a
After running CMake, open the created :file:`pybind
11
.sln` file and perform a
release build, which will will produce a file named
:file:`Release\\example.pyd`. Copy this file to the :file:`example` directory
and run :file:`example\\run_test.py` using the targeted Python version.
...
...
@@ -79,16 +79,16 @@ a file named :file:`example.cpp` with the following contents:
.. code-block:: cpp
#include <pybind/pybind.h>
#include <pybind
11
/pybind
11
.h>
int add(int i, int j) {
return i + j;
}
namespace py = pybind
;
namespace py = pybind
11
PYBIND_PLUGIN(example) {
py::module m("example", "pybind example plugin");
py::module m("example", "pybind
11
example plugin");
m.def("add", &add, "A function which adds two numbers");
...
...
@@ -117,7 +117,7 @@ example can be compiled using the following command
.. code-block:: bash
$ c++ -O3 -shared -std=c++11 -I <path-to-pybind>/include `python-config --cflags --libs` example.cpp -o example.so
$ c++ -O3 -shared -std=c++11 -I <path-to-pybind
11
>/include `python-config --cflags --libs` example.cpp -o example.so
In general, it is advisable to include several additional build parameters
that can considerably reduce the size of the created binary. Refer to section
...
...
@@ -222,41 +222,41 @@ The following basic data types are supported out of the box (some may require
an additional extension header to be included). To pass other data structures
as arguments and return values, refer to the section on binding :ref:`classes`.
+------------------------+--------------------------+---------------------+
| Data type | Description | Header file |
+========================+==========================+=====================+
| int8_t, uint8_t | 8-bit integers | pybind/pybind.h
|
+------------------------+--------------------------+---------------------+
| int16_t, uint16_t | 16-bit integers | pybind/pybind.h
|
+------------------------+--------------------------+---------------------+
| int32_t, uint32_t | 32-bit integers | pybind/pybind.h
|
+------------------------+--------------------------+---------------------+
| int64_t, uint64_t | 64-bit integers | pybind/pybind.h
|
+------------------------+--------------------------+---------------------+
| ssize_t, size_t | Platform-dependent size | pybind/pybind.h
|
+------------------------+--------------------------+---------------------+
| float, double | Floating point types | pybind/pybind.h
|
+------------------------+--------------------------+---------------------+
| bool | Two-state Boolean type | pybind/pybind.h
|
+------------------------+--------------------------+---------------------+
| char | Character literal | pybind/pybind.h
|
+------------------------+--------------------------+---------------------+
| const char * | UTF-8 string literal | pybind/pybind.h
|
+------------------------+--------------------------+---------------------+
| std::string | STL dynamic UTF-8 string | pybind/pybind.h
|
+------------------------+--------------------------+---------------------+
| std::pair<T1, T2> | Pair of two custom types | pybind/pybind.h
|
+------------------------+--------------------------+---------------------+
| std::tuple<....> | Arbitrary tuple of types | pybind/pybind.h
|
+------------------------+--------------------------+---------------------+
| std::complex<T> | Complex numbers | pybind/complex.h |
+------------------------+--------------------------+---------------------+
| std::vector<T> | STL dynamic array | pybind/stl.h |
+------------------------+--------------------------+---------------------+
| std::map<T1, T2> | STL dynamic maps | pybind/stl.h |
+------------------------+--------------------------+---------------------+
| std::function<...> | STL polymorphic function | pybind/functional.h |
+------------------------+--------------------------+---------------------+
+------------------------+--------------------------+---------------------
--
+
| Data type | Description | Header file
|
+========================+==========================+=====================
==
+
| int8_t, uint8_t | 8-bit integers | pybind
11
/pybind
11
.h |
+------------------------+--------------------------+---------------------
--
+
| int16_t, uint16_t | 16-bit integers | pybind
11
/pybind
11
.h |
+------------------------+--------------------------+---------------------
--
+
| int32_t, uint32_t | 32-bit integers | pybind
11
/pybind
11
.h |
+------------------------+--------------------------+---------------------
--
+
| int64_t, uint64_t | 64-bit integers | pybind
11
/pybind
11
.h |
+------------------------+--------------------------+---------------------
--
+
| ssize_t, size_t | Platform-dependent size | pybind
11
/pybind
11
.h |
+------------------------+--------------------------+---------------------
--
+
| float, double | Floating point types | pybind
11
/pybind
11
.h |
+------------------------+--------------------------+---------------------
--
+
| bool | Two-state Boolean type | pybind
11
/pybind
11
.h |
+------------------------+--------------------------+---------------------
--
+
| char | Character literal | pybind
11
/pybind
11
.h |
+------------------------+--------------------------+---------------------
--
+
| const char * | UTF-8 string literal | pybind
11
/pybind
11
.h |
+------------------------+--------------------------+---------------------
--
+
| std::string | STL dynamic UTF-8 string | pybind
11
/pybind
11
.h |
+------------------------+--------------------------+---------------------
--
+
| std::pair<T1, T2> | Pair of two custom types | pybind
11
/pybind
11
.h |
+------------------------+--------------------------+---------------------
--
+
| std::tuple<....> | Arbitrary tuple of types | pybind
11
/pybind
11
.h |
+------------------------+--------------------------+---------------------
--
+
| std::complex<T> | Complex numbers | pybind
11
/complex.h |
+------------------------+--------------------------+---------------------
--
+
| std::vector<T> | STL dynamic array | pybind
11
/stl.h |
+------------------------+--------------------------+---------------------
--
+
| std::map<T1, T2> | STL dynamic maps | pybind
11
/stl.h |
+------------------------+--------------------------+---------------------
--
+
| std::function<...> | STL polymorphic function | pybind
11
/functional.h |
+------------------------+--------------------------+---------------------
--
+
.. [#f1] In practice, implementation and binding code will generally be located
...
...
docs/classes.rst
View file @
8f4eb006
...
...
@@ -23,12 +23,12 @@ The binding code for ``Pet`` looks as follows:
.. code-block:: cpp
#include <pybind/pybind.h>
#include <pybind
11
/pybind
11
.h>
namespace py = pybind
;
namespace py = pybind
11
PYBIND_PLUGIN(example) {
py::module m("example", "pybind example plugin");
py::module m("example", "pybind
11
example plugin");
py::class_<Pet>(m, "Pet")
.def(py::init<const std::string &>())
...
...
docs/reference.rst
View file @
8f4eb006
...
...
@@ -4,7 +4,7 @@
Please be advised that the reference documentation discussing pybind11
internals is currently incomplete. Please refer to the previous sections
and the pybind header files for the nitty gritty details.
and the pybind
11
header files for the nitty gritty details.
Reference
#########
...
...
@@ -22,7 +22,7 @@ Macros
.. code-block:: cpp
PYBIND_PLUGIN(example) {
pybind::module m("example", "pybind example plugin");
pybind
11
::module m("example", "pybind
11
example plugin");
/// Set up bindings here
return m.ptr();
}
...
...
@@ -188,9 +188,9 @@ Convenience classes for specific Python types
.. code-block:: cpp
pybind::module m("example", "pybind example plugin");
pybind::module m2 = m.def_submodule("sub", "A submodule of 'example'");
pybind::module m3 = m2.def_submodule("subsub", "A submodule of 'example.sub'");
pybind
11
::module m("example", "pybind
11
example plugin");
pybind
11
::module m2 = m.def_submodule("sub", "A submodule of 'example'");
pybind
11
::module m3 = m2.def_submodule("subsub", "A submodule of 'example.sub'");
.. cpp:function:: template <typename Func, typename ... Extra> module& module::def(const char *name, Func && f, Extra && ... extra)
...
...
example/example.h
View file @
8f4eb006
#include <pybind/pybind.h>
#include <pybind
11
/pybind
11
.h>
#include <iostream>
using
std
::
cout
;
using
std
::
endl
;
namespace
py
=
pybind
;
namespace
py
=
pybind
11
;
example/example10.cpp
View file @
8f4eb006
...
...
@@ -9,7 +9,7 @@
*/
#include "example.h"
#include <pybind/numpy.h>
#include <pybind
11
/numpy.h>
double
my_func
(
int
x
,
float
y
,
double
z
)
{
std
::
cout
<<
"my_func(x:int="
<<
x
<<
", y:float="
<<
y
<<
", z:float="
<<
z
<<
")"
<<
std
::
endl
;
...
...
example/example12.cpp
View file @
8f4eb006
...
...
@@ -8,7 +8,7 @@
*/
#include "example.h"
#include <pybind/functional.h>
#include <pybind
11
/functional.h>
/* This is an example class that we'll want to be able to extend from Python */
class
Example12
{
...
...
example/example2.cpp
View file @
8f4eb006
...
...
@@ -9,7 +9,7 @@
*/
#include "example.h"
#include <pybind/stl.h>
#include <pybind
11
/stl.h>
class
Example2
{
public:
...
...
example/example3.cpp
View file @
8f4eb006
...
...
@@ -8,7 +8,7 @@
*/
#include "example.h"
#include <pybind/operators.h>
#include <pybind
11
/operators.h>
class
Vector2
{
public:
...
...
example/example5.cpp
View file @
8f4eb006
...
...
@@ -9,7 +9,7 @@
*/
#include "example.h"
#include <pybind/functional.h>
#include <pybind
11
/functional.h>
class
Pet
{
...
...
example/example6.cpp
View file @
8f4eb006
...
...
@@ -9,8 +9,8 @@
*/
#include "example.h"
#include <pybind/operators.h>
#include <pybind/stl.h>
#include <pybind
11
/operators.h>
#include <pybind
11
/stl.h>
class
Sequence
{
public:
...
...
example/example8.cpp
View file @
8f4eb006
...
...
@@ -32,10 +32,7 @@ private:
};
/// Make pybind aware of the ref-counted wrapper type
namespace
pybind
{
namespace
detail
{
template
<
typename
T
>
class
type_caster
<
ref
<
T
>>
:
public
type_caster_holder
<
T
,
ref
<
T
>>
{
};
}}
PYBIND_DECLARE_HOLDER_TYPE
(
T
,
ref
<
T
>
);
Object
*
make_object_1
()
{
return
new
MyObject
(
1
);
}
ref
<
Object
>
make_object_2
()
{
return
new
MyObject
(
2
);
}
...
...
include/pybind/cast.h
→
include/pybind
11
/cast.h
View file @
8f4eb006
/*
pybind/cast.h: Partial template specializations to cast between
pybind
11
/cast.h: Partial template specializations to cast between
C++ and Python types
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
...
...
@@ -10,12 +10,12 @@
#pragma once
#include
<pybind/
pytypes.h
>
#include
<pybind/
typeid.h
>
#include
"
pytypes.h
"
#include
"
typeid.h
"
#include <array>
#include <limits>
NAMESPACE_BEGIN
(
pybind
)
NAMESPACE_BEGIN
(
pybind
11
)
NAMESPACE_BEGIN
(
detail
)
#if defined(_MSC_VER)
...
...
@@ -527,6 +527,12 @@ protected:
holder_type
holder
;
};
#define PYBIND_DECLARE_HOLDER_TYPE(type, holder_type) \
namespace pybind11 { namespace detail { \
template <typename type> class type_caster<holder_type> \
: public type_caster_holder<type, holder_type> { }; \
}}
template
<
>
class
type_caster
<
handle
>
{
public:
bool
load
(
PyObject
*
src
)
{
...
...
@@ -571,7 +577,7 @@ template <typename T> inline object cast(const T &value, return_value_policy pol
return
object
(
detail
::
type_caster
<
typename
detail
::
decay
<
T
>::
type
>::
cast
(
value
,
policy
,
parent
),
false
);
}
template
<
typename
T
>
inline
T
handle
::
cast
()
{
return
pybind
::
cast
<
T
>
(
m_ptr
);
}
template
<
typename
T
>
inline
T
handle
::
cast
()
{
return
pybind
11
::
cast
<
T
>
(
m_ptr
);
}
template
<
>
inline
void
handle
::
cast
()
{
return
;
}
template
<
typename
...
Args
>
inline
object
handle
::
call
(
Args
&&
...
args_
)
{
...
...
@@ -601,4 +607,4 @@ template <typename... Args> inline object handle::call(Args&&... args_) {
return
object
(
result
,
false
);
}
NAMESPACE_END
(
pybind
)
NAMESPACE_END
(
pybind
11
)
include/pybind/common.h
→
include/pybind
11
/common.h
View file @
8f4eb006
/*
pybind/common.h -- Basic macros
pybind
11
/common.h -- Basic macros
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
...
...
@@ -68,7 +68,7 @@
extern "C" PYBIND_EXPORT PyObject *init##name()
#endif
NAMESPACE_BEGIN
(
pybind
)
NAMESPACE_BEGIN
(
pybind
11
)
typedef
Py_ssize_t
ssize_t
;
...
...
@@ -192,7 +192,7 @@ NAMESPACE_END(detail)
struct
stop_iteration
:
public
std
::
runtime_error
{
public
:
stop_iteration
(
const
std
::
string
&
w
=
""
)
:
std
::
runtime_error
(
w
)
{}
};
struct
index_error
:
public
std
::
runtime_error
{
public
:
index_error
(
const
std
::
string
&
w
=
""
)
:
std
::
runtime_error
(
w
)
{}
};
struct
error_already_set
:
public
std
::
runtime_error
{
public
:
error_already_set
()
:
std
::
runtime_error
(
detail
::
error_string
())
{}
};
/// Thrown when pybind::cast or handle::call fail due to a type casting error
/// Thrown when pybind
11
::cast or handle::call fail due to a type casting error
struct
cast_error
:
public
std
::
runtime_error
{
public
:
cast_error
(
const
std
::
string
&
w
=
""
)
:
std
::
runtime_error
(
w
)
{}
};
NAMESPACE_END
(
pybind
)
NAMESPACE_END
(
pybind
11
)
include/pybind/complex.h
→
include/pybind
11
/complex.h
View file @
8f4eb006
/*
pybind/complex.h: Complex number support
pybind
11
/complex.h: Complex number support
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
...
...
@@ -9,10 +9,10 @@
#pragma once
#include
<
pybind
/pybind
.h
>
#include
"
pybind
11
.h
"
#include <complex>
NAMESPACE_BEGIN
(
pybind
)
NAMESPACE_BEGIN
(
pybind
11
)
PYBIND_DECL_FMT
(
std
::
complex
<
float
>
,
"Zf"
);
PYBIND_DECL_FMT
(
std
::
complex
<
double
>
,
"Zd"
);
...
...
@@ -37,4 +37,4 @@ public:
PYBIND_TYPE_CASTER
(
std
::
complex
<
T
>
,
"complex"
);
};
NAMESPACE_END
(
detail
)
NAMESPACE_END
(
pybind
)
NAMESPACE_END
(
pybind
11
)
include/pybind/functional.h
→
include/pybind
11
/functional.h
View file @
8f4eb006
/*
pybind/functional.h: std::function<> support
pybind
11
/functional.h: std::function<> support
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
...
...
@@ -9,10 +9,10 @@
#pragma once
#include
<
pybind
/pybind
.h
>
#include
"
pybind
11
.h
"
#include <functional>
NAMESPACE_BEGIN
(
pybind
)
NAMESPACE_BEGIN
(
pybind
11
)
NAMESPACE_BEGIN
(
detail
)
template
<
typename
Return
,
typename
...
Args
>
struct
type_caster
<
std
::
function
<
Return
(
Args
...)
>>
{
...
...
@@ -24,7 +24,7 @@ public:
return
false
;
object
src
(
src_
,
true
);
value
=
[
src
](
Args
...
args
)
->
Return
{
object
retval
(
pybind
::
handle
(
src
).
call
(
std
::
move
(
args
)...));
object
retval
(
pybind
11
::
handle
(
src
).
call
(
std
::
move
(
args
)...));
/* Visual studio 2015 parser issue: need parentheses around this expression */
return
(
retval
.
template
cast
<
Return
>());
};
...
...
@@ -46,4 +46,4 @@ public:
};
NAMESPACE_END
(
detail
)
NAMESPACE_END
(
pybind
)
NAMESPACE_END
(
pybind
11
)
include/pybind/numpy.h
→
include/pybind
11
/numpy.h
View file @
8f4eb006
/*
pybind/numpy.h: Basic NumPy support, auto-vectorization support
pybind
11
/numpy.h: Basic NumPy support, auto-vectorization support
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
...
...
@@ -9,15 +9,15 @@
#pragma once
#include
<
pybind
/pybind
.h
>
#include
<pybind/
complex.h
>
#include
"
pybind
11
.h
"
#include
"
complex.h
"
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
#endif
NAMESPACE_BEGIN
(
pybind
)
NAMESPACE_BEGIN
(
pybind
11
)
template
<
typename
type
>
struct
npy_format_descriptor
{
};
...
...
@@ -196,7 +196,7 @@ struct vectorize_helper {
/* Check if the parameters are actually compatible */
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
if
(
buffers
[
i
].
count
!=
1
&&
(
buffers
[
i
].
ndim
!=
ndim
||
buffers
[
i
].
shape
!=
shape
))
throw
std
::
runtime_error
(
"pybind::vectorize: incompatible size/dimension of inputs!"
);
throw
std
::
runtime_error
(
"pybind
11
::vectorize: incompatible size/dimension of inputs!"
);
}
/* Call the function */
...
...
@@ -234,7 +234,7 @@ template <typename func> auto vectorize(func &&f) -> decltype(
&
std
::
remove_reference
<
func
>::
type
::
operator
())
>::
type
*
)
nullptr
);
}
NAMESPACE_END
(
pybind
)
NAMESPACE_END
(
pybind
11
)
#if defined(_MSC_VER)
#pragma warning(pop)
...
...
include/pybind/operators.h
→
include/pybind
11
/operators.h
View file @
8f4eb006
/*
pybind/operator.h: Metatemplates for operator overloading
pybind
11
/operator.h: Metatemplates for operator overloading
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
...
...
@@ -9,10 +9,10 @@
#pragma once
#include
<
pybind
/pybind
.h
>
#include
"
pybind
11
.h
"
#include <type_traits>
NAMESPACE_BEGIN
(
pybind
)
NAMESPACE_BEGIN
(
pybind
11
)
NAMESPACE_BEGIN
(
detail
)
/// Enumeration with all supported operator types
...
...
@@ -45,13 +45,13 @@ template <op_id, op_type, typename B, typename L, typename R> struct op_impl { }
/// Operator implementation generator
template
<
op_id
id
,
op_type
ot
,
typename
L
,
typename
R
>
struct
op_
{
template
<
typename
Base
,
typename
Holder
,
typename
...
Extra
>
void
execute
(
pybind
::
class_
<
Base
,
Holder
>
&
class_
,
Extra
&&
...
extra
)
const
{
template
<
typename
Base
,
typename
Holder
,
typename
...
Extra
>
void
execute
(
pybind
11
::
class_
<
Base
,
Holder
>
&
class_
,
Extra
&&
...
extra
)
const
{
typedef
typename
std
::
conditional
<
std
::
is_same
<
L
,
self_t
>::
value
,
Base
,
L
>::
type
L_type
;
typedef
typename
std
::
conditional
<
std
::
is_same
<
R
,
self_t
>::
value
,
Base
,
R
>::
type
R_type
;
typedef
op_impl
<
id
,
ot
,
Base
,
L_type
,
R_type
>
op
;
class_
.
def
(
op
::
name
(),
&
op
::
execute
,
std
::
forward
<
Extra
>
(
extra
)...);
}
template
<
typename
Base
,
typename
Holder
,
typename
...
Extra
>
void
execute_cast
(
pybind
::
class_
<
Base
,
Holder
>
&
class_
,
Extra
&&
...
extra
)
const
{
template
<
typename
Base
,
typename
Holder
,
typename
...
Extra
>
void
execute_cast
(
pybind
11
::
class_
<
Base
,
Holder
>
&
class_
,
Extra
&&
...
extra
)
const
{
typedef
typename
std
::
conditional
<
std
::
is_same
<
L
,
self_t
>::
value
,
Base
,
L
>::
type
L_type
;
typedef
typename
std
::
conditional
<
std
::
is_same
<
R
,
self_t
>::
value
,
Base
,
R
>::
type
R_type
;
typedef
op_impl
<
id
,
ot
,
Base
,
L_type
,
R_type
>
op
;
...
...
@@ -146,4 +146,4 @@ NAMESPACE_END(detail)
using
detail
::
self
;
NAMESPACE_END
(
pybind
)
NAMESPACE_END
(
pybind
11
)
include/pybind/pybind.h
→
include/pybind
11
/pybind
11
.h
View file @
8f4eb006
/*
pybind/pybind.h: Main header file of the C++11 python binding generator library
pybind
11
/pybind
11
.h: Main header file of the C++11 python binding generator library
Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
...
...
@@ -23,9 +23,9 @@
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif
#include
<pybind/
cast.h
>
#include
"
cast.h
"
NAMESPACE_BEGIN
(
pybind
)
NAMESPACE_BEGIN
(
pybind
11
)
template
<
typename
T
>
struct
arg_t
;
...
...
@@ -113,31 +113,31 @@ private:
}
static
void
process_extra
(
const
char
*
doc
,
function_entry
*
entry
,
const
char
**
,
const
char
**
)
{
entry
->
doc
=
doc
;
}
static
void
process_extra
(
const
pybind
::
doc
&
d
,
function_entry
*
entry
,
const
char
**
,
const
char
**
)
{
entry
->
doc
=
d
.
value
;
}
static
void
process_extra
(
const
pybind
::
name
&
n
,
function_entry
*
entry
,
const
char
**
,
const
char
**
)
{
entry
->
name
=
n
.
value
;
}
static
void
process_extra
(
const
pybind
::
arg
&
a
,
function_entry
*
entry
,
const
char
**
kw
,
const
char
**
)
{
static
void
process_extra
(
const
pybind
11
::
doc
&
d
,
function_entry
*
entry
,
const
char
**
,
const
char
**
)
{
entry
->
doc
=
d
.
value
;
}
static
void
process_extra
(
const
pybind
11
::
name
&
n
,
function_entry
*
entry
,
const
char
**
,
const
char
**
)
{
entry
->
name
=
n
.
value
;
}
static
void
process_extra
(
const
pybind
11
::
arg
&
a
,
function_entry
*
entry
,
const
char
**
kw
,
const
char
**
)
{
if
(
entry
->
is_method
&&
entry
->
keywords
==
0
)
kw
[
entry
->
keywords
++
]
=
"self"
;
kw
[
entry
->
keywords
++
]
=
a
.
name
;
}
template
<
typename
T
>
static
void
process_extra
(
const
pybind
::
arg_t
<
T
>
&
a
,
function_entry
*
entry
,
const
char
**
kw
,
const
char
**
def
)
{