Skip to content

How should RHS operators be handled? #100

Description

@RyanJK5

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions