Since interfaces are defined as structs, there is not an obvious way for how binary operators should be defined where the interface is the right-hand side operand, e.g.:
struct S {
friend std::ostream& operator<<(std::ostream& out, const S& self);
};
struct Printable {
// how should this be specified?
};
Is this something we want to support? If so, how should it be written?
One possibility is to write the friend declaration in Printable, but I do not know if there's a way to discover that via reflection. Another is to use the approach from duck, which uses annotations:
struct Printable {
[[=rjk::right_side]]
std::ostream& operator<<(std::ostream& out) const;
};
struct AddableWithInt {
[[=rjk::both_sides]]
int operator+(int) const;
};
However this could be considered too complex / not matching STL style. Any thoughts?
Since interfaces are defined as structs, there is not an obvious way for how binary operators should be defined where the interface is the right-hand side operand, e.g.:
Is this something we want to support? If so, how should it be written?
One possibility is to write the friend declaration in
Printable, but I do not know if there's a way to discover that via reflection. Another is to use the approach fromduck, which uses annotations:However this could be considered too complex / not matching STL style. Any thoughts?