How should RHS operators be handled?
- Dominant language
- C++
- Stars
- 11
- Forks
- 4
- Avg merge
- 16h 39m
- Merged PRs (30d)
- 131
Description
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.:
```c++
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:
```c++
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?
Contributor guide
Research direction
No implementation files, tests, or entry points are named. First clarify whether right-hand-side operators should be supported, then compare friend declarations with the proposed annotations and determine how reflection would discover them. Done means the project has a decided syntax and behavior for these operators.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100