Skip to content

Bind operator overloads #64

Description

@kwabenantim

Summary

Automatically generate bindings for overloaded operators. For example:

class Foo
{
public:
  Foo();
  ~Foo();
  double& operator[](unsigned index);
};

An example of generated bindings for the overloaded operator[]:

void register_Foo_class(py::module &m)
{
  py::class_<Foo>(m, "Foo")
    // ...
    .def("__setitem__", &Foo::operator[], "")
    .def("__getitem__", &Foo::operator[], "")
  ;
}

This can currently be added in using custom templates:

class Foo(cppwg.templates.custom.Custom):

    def get_class_cpp_def_code(self, class_name):
        code = """\
        .def("__getitem__", &{class_name}::operator[])
        .def("__setitem__", &{class_name}::operator[])
        """.format(class_name=class_name)

        return code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions