Skip to content

Commit

Permalink
adding mod support
Browse files Browse the repository at this point in the history
  • Loading branch information
zwimer authored Oct 10, 2022
1 parent 2a61164 commit d460756
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions source/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ static std::map<string, string > const cpp_python_operator_map{
{"operator-", "__sub__"}, //
{"operator*", "__mul__"}, //
{"operator/", "__truediv__"}, //
{"operator%", "__mod__"}, //

{"operator+=", "__iadd__"}, //
{"operator-=", "__isub__"}, //
{"operator*=", "__imul__"}, //
{"operator/=", "__itruediv__"}, //
{"operator%=", "__imod__"}, //

{"operator()", "__call__"}, //
{"operator==", "__eq__"}, //
Expand Down
2 changes: 2 additions & 0 deletions test/T12.operator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ struct T
T &operator-(int) { return *this; }
T &operator*(int) { return *this; }
T &operator/(int) { return *this; }
T &operator%(int) { return *this; }

void operator+=(int) {}
void operator-=(int) {}
void operator*=(int) {}
void operator/=(int) {}
void operator%=(int) {}

void operator()(int) {}

Expand Down
4 changes: 3 additions & 1 deletion test/T12.operator.ref
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ void bind_T12_operator(std::function< pybind11::module &(std::string const &name
cl.def("__sub__", (struct T & (T::*)(int)) &T::operator-, "C++: T::operator-(int) --> struct T &", pybind11::return_value_policy::automatic, pybind11::arg(""));
cl.def("__mul__", (struct T & (T::*)(int)) &T::operator*, "C++: T::operator*(int) --> struct T &", pybind11::return_value_policy::automatic, pybind11::arg(""));
cl.def("__div__", (struct T & (T::*)(int)) &T::operator/, "C++: T::operator/(int) --> struct T &", pybind11::return_value_policy::automatic, pybind11::arg(""));
cl.def("__mod__", (struct T & (T::*)(int)) &T::operator%, "C++: T::operator%(int) --> struct T &", pybind11::return_value_policy::automatic, pybind11::arg(""));
cl.def("__iadd__", (void (T::*)(int)) &T::operator+=, "C++: T::operator+=(int) --> void", pybind11::arg(""));
cl.def("__isub__", (void (T::*)(int)) &T::operator-=, "C++: T::operator-=(int) --> void", pybind11::arg(""));
cl.def("__imul__", (void (T::*)(int)) &T::operator*=, "C++: T::operator*=(int) --> void", pybind11::arg(""));
cl.def("__idiv__", (void (T::*)(int)) &T::operator/=, "C++: T::operator/=(int) --> void", pybind11::arg(""));
cl.def("__imod__", (void (T::*)(int)) &T::operator%=, "C++: T::operator%=(int) --> void", pybind11::arg(""));
cl.def("__call__", (void (T::*)(int)) &T::operator(), "C++: T::operator()(int) --> void", pybind11::arg(""));
cl.def("__eq__", (bool (T::*)(const struct T &)) &T::operator==, "C++: T::operator==(const struct T &) --> bool", pybind11::arg(""));
cl.def("__ne__", (bool (T::*)(const struct T &)) &T::operator!=, "C++: T::operator!=(const struct T &) --> bool", pybind11::arg(""));
Expand Down Expand Up @@ -87,4 +89,4 @@ PYBIND11_MODULE(T12_operator, root_module) {
// T12_operator.cpp

// Modules list file: TEST/T12_operator.modules
//
//

0 comments on commit d460756

Please sign in to comment.