CxxWrap.jl
CxxWrap.jl copied to clipboard
How to wrap operators?
How do I wrap operators like:
LinkedReadMapper operator=(const LinkedReadMapper &other);
or
bool operator==(const SequenceGraph &o) const ;
My guess is something like: .method("=", operator=(const LinkedReadMapper &other))
and .method("==", operator==(const SequenceGraph &other))
or maybe "Base.=="?
But I wasn't sure if that was the correct way of doing it.
Thanks!
For ==
, something like that should work, using the function pointer, e.g. .method("==", &SequenceGraph::operator==)
.
The implementation for this is currently quite ugly, there is a predefined list of names that are automatically added to base: https://github.com/JuliaInterop/CxxWrap.jl/blob/master/src/CxxWrap.jl#L334-L342
I intend to change this in the future, by allowing to specify the module to which the method should be added using an optional argument. For now, for function not in the list you will have to define a function local to your module, and then overload the Base function as usual on the Julia side.
For =
there is no way to do it: it cannot be overloaded in Julia, since assignment is just setting what value is pointed to by a given variable name. The best equivalent would be to overload copy!
.
@barche close?
Yes, this is done now, using the set_override_module
function (on the C++ side).