Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre post increment ops renamed #238

Merged
merged 9 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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