Skip to content

Commit

Permalink
renaming binding names for pre/post increment/decrement operators for…
Browse files Browse the repository at this point in the history
… clarity
  • Loading branch information
zwimer authored Dec 15, 2022
1 parent 844858e commit c51ec70
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 1 addition & 3 deletions documentation/limitations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,4 @@ The following operators will be ignored by binder:
Miscellaneous
-------------

1. The pre/post increment operators both map to ``plus_plus``, with the pre-increment operator being invoked via ``a.plus_plus()`` and post-increment via ``.plus_plus(0)``; just as the operators are technically defined in C++. The same is true for the pre/post decrement operators, both called ``minus_minus``.

2. User defined literals ``operator"" _foo`` end up being named as ``operator_foo``.
1. User defined literals ``operator"" _foo`` end up being named as ``operator_foo``.
4 changes: 2 additions & 2 deletions source/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ string cpp_python_operator(const FunctionDecl & F) {
{"operator!=", {"__ne__"}}, //
{"operator[]", {"__getitem__"}}, //
{"operator=", {"assign"}}, //
{"operator++", {"plus_plus"}}, //
{"operator--", {"minus_minus"}}, //
{"operator++", {"pre_increment", "post_increment"}}, //
{"operator--", {"pre_decrement", "post_decrement"}}, //

{"operator->", {"arrow"}} //
};
Expand Down
2 changes: 2 additions & 0 deletions test/T12.operator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@ struct T
T &operator=(const T &) { return *this; }
T &operator++() { return *this; }
T &operator--() { return *this; }
T &operator++(int) { return *this; }
T &operator--(int) { return *this; }
};
6 changes: 4 additions & 2 deletions test/T12.operator.ref
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ void bind_T12_operator(std::function< pybind11::module &(std::string const &name
cl.def("__ne__", (bool (T::*)(const struct T &)) &T::operator!=, "C++: T::operator!=(const struct T &) --> bool", pybind11::arg(""));
cl.def("__getitem__", (bool (T::*)(int)) &T::operator[], "C++: T::operator[](int) --> bool", pybind11::arg(""));
cl.def("assign", (struct T & (T::*)(const struct T &)) &T::operator=, "C++: T::operator=(const struct T &) --> struct T &", pybind11::return_value_policy::automatic, pybind11::arg(""));
cl.def("plus_plus", (struct T & (T::*)()) &T::operator++, "C++: T::operator++() --> struct T &", pybind11::return_value_policy::automatic);
cl.def("minus_minus", (struct T & (T::*)()) &T::operator--, "C++: T::operator--() --> struct T &", pybind11::return_value_policy::automatic);
cl.def("pre_increment", (struct T & (T::*)()) &T::operator++, "C++: T::operator++() --> struct T &", pybind11::return_value_policy::automatic);
cl.def("pre_decrement", (struct T & (T::*)()) &T::operator--, "C++: T::operator--() --> struct T &", pybind11::return_value_policy::automatic);
cl.def("post_increment", (struct T & (T::*)(int)) &T::operator++, "C++: T::operator++(int) --> struct T &", pybind11::return_value_policy::automatic, pybind11::arg(""));
cl.def("post_decrement", (struct T & (T::*)(int)) &T::operator--, "C++: T::operator--(int) --> struct T &", pybind11::return_value_policy::automatic, pybind11::arg(""));
}
}

Expand Down

0 comments on commit c51ec70

Please sign in to comment.