Friend operators are not callable
See this example code:
import cppyy
cppyy.cppdef("""
#include <iostream>
class Foo {
public:
Foo &operator+=(const Foo &o) { std::cout << "operator +=" << std::endl; return *this; }
friend Foo operator+(const Foo &a, const Foo &b) { std::cout << "operator +" << std::endl; return a; }
};
void test() {
Foo f1, f2, f3;
f1 += f2;
f3 = f1 + f2;
}
""")
cppyy.gbl.test()
print("----")
f1, f2, f3 = cppyy.gbl.Foo(), cppyy.gbl.Foo(), cppyy.gbl.Foo()
f1 += f2
f3 = f1 + f2
I would expect to see this:
operator +=
operator +
----
operator +=
operator +
Instead, I'm getting this:
operator +=
operator +
----
operator +=
Traceback (most recent call last):
File "...", line 24, in <module>
f3 = f1 + f2
NotImplementedError
Yes, this is known: Cling does not currently expose friend declarations, so these are not available for lookup.
Hmm, I see... :/ Are you aware of any plans or effort adding this to Cling?
No, I'm not aware of that. Probably have to do that myself at some point ...
@torokati44 https://github.com/flatsurf/cppyythonizations/blob/master/src/cppyythonizations/operators/arithmetic.py might work as a workaround in your example.
Thank you! This is similar to what I had in mind, so it's good to see it actually done somewhere.