cppyabm
1.0.17
An agent-based library to integrate C++ and Python
|
|
Go to the documentation of this file.
14 #if defined(__clang__) && !defined(__INTEL_COMPILER)
15 # pragma clang diagnostic ignored "-Wunsequenced" // multiple unsequenced modifications to 'self' (when using def(py::self OP Type()))
16 #elif defined(_MSC_VER)
17 # pragma warning(push)
18 # pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
50 template <op_
id, op_type,
typename B,
typename L,
typename R>
struct op_impl { };
53 template <op_
id id, op_type ot,
typename L,
typename R>
struct op_ {
54 template <
typename Class,
typename... Extra>
void execute(Class &cl,
const Extra&... extra)
const {
55 using Base =
typename Class::type;
59 cl.def(op::name(), &op::execute,
is_operator(), extra...);
60 #if PY_MAJOR_VERSION < 3
62 cl.def(
id ==
op_itruediv ?
"__idiv__" : ot ==
op_l ?
"__div__" :
"__rdiv__",
66 template <
typename Class,
typename... Extra>
void execute_cast(Class &cl,
const Extra&... extra)
const {
67 using Base =
typename Class::type;
71 cl.def(op::name(), &op::execute_cast,
is_operator(), extra...);
72 #if PY_MAJOR_VERSION < 3
74 cl.def(
id ==
op_itruediv ?
"__idiv__" : ot ==
op_l ?
"__div__" :
"__rdiv__",
80 #define PYBIND11_BINARY_OPERATOR(id, rid, op, expr) \
81 template <typename B, typename L, typename R> struct op_impl<op_##id, op_l, B, L, R> { \
82 static char const* name() { return "__" #id "__"; } \
83 static auto execute(const L &l, const R &r) -> decltype(expr) { return (expr); } \
84 static B execute_cast(const L &l, const R &r) { return B(expr); } \
86 template <typename B, typename L, typename R> struct op_impl<op_##id, op_r, B, L, R> { \
87 static char const* name() { return "__" #rid "__"; } \
88 static auto execute(const R &r, const L &l) -> decltype(expr) { return (expr); } \
89 static B execute_cast(const R &r, const L &l) { return B(expr); } \
91 inline op_<op_##id, op_l, self_t, self_t> op(const self_t &, const self_t &) { \
92 return op_<op_##id, op_l, self_t, self_t>(); \
94 template <typename T> op_<op_##id, op_l, self_t, T> op(const self_t &, const T &) { \
95 return op_<op_##id, op_l, self_t, T>(); \
97 template <typename T> op_<op_##id, op_r, T, self_t> op(const T &, const self_t &) { \
98 return op_<op_##id, op_r, T, self_t>(); \
101 #define PYBIND11_INPLACE_OPERATOR(id, op, expr) \
102 template <typename B, typename L, typename R> struct op_impl<op_##id, op_l, B, L, R> { \
103 static char const* name() { return "__" #id "__"; } \
104 static auto execute(L &l, const R &r) -> decltype(expr) { return expr; } \
105 static B execute_cast(L &l, const R &r) { return B(expr); } \
107 template <typename T> op_<op_##id, op_l, self_t, T> op(const self_t &, const T &) { \
108 return op_<op_##id, op_l, self_t, T>(); \
111 #define PYBIND11_UNARY_OPERATOR(id, op, expr) \
112 template <typename B, typename L> struct op_impl<op_##id, op_u, B, L, undefined_t> { \
113 static char const* name() { return "__" #id "__"; } \
114 static auto execute(const L &l) -> decltype(expr) { return expr; } \
115 static B execute_cast(const L &l) { return B(expr); } \
117 inline op_<op_##id, op_u, self_t, undefined_t> op(const self_t &) { \
118 return op_<op_##id, op_u, self_t, undefined_t>(); \
160 #undef PYBIND11_BINARY_OPERATOR
161 #undef PYBIND11_INPLACE_OPERATOR
162 #undef PYBIND11_UNARY_OPERATOR
171 #if defined(_MSC_VER)
172 # pragma warning(pop)
#define PYBIND11_NAMESPACE_BEGIN(name)
#define PYBIND11_INPLACE_OPERATOR(id, op, expr)
#define PYBIND11_NAMESPACE_END(name)
void execute_cast(Class &cl, const Extra &... extra) const
#define PYBIND11_NAMESPACE
Annotation for operators.
#define PYBIND11_BINARY_OPERATOR(id, rid, op, expr)
void execute(Class &cl, const Extra &... extra) const
Operator implementation generator.
op_id
Enumeration with all supported operator types.
typename std::conditional< B, T, F >::type conditional_t
self_t __self()
Don't warn about an unused variable.
Type for an unused type slot.
std::string abs(const Vector2 &)
#define PYBIND11_UNARY_OPERATOR(id, op, expr)
base template of operator implementations