Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It seems to an editorial issue for the comment in an operator over example #4226

Closed
xmh0511 opened this issue Sep 23, 2020 · 1 comment
Closed

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Sep 23, 2020

Consider the example in over.match.oper#7, that is:

struct A {
  operator int();
};
A operator+(const A&, const A&);
void m() {
  A a, b;
  a + b;                        // operator+(a, b) chosen over int(a) + int(b)
}

Note the comment in this code, it sounds like the best overload is built-in operator. However, For this example, the candidate functions are a non-member user-defined function for operator + and a built-in operator, according to [over.match.best], convert these operands of type A to what the type build-in + expects, there are user-defined conversion sequences applied to these original operands, conversely, for user-declared operator +, only identity conversion applied to these operands, which is standard conversion sequences. Obviously, the later is more better. why the comment said chosen over int(a) + int(b)? GCC and Clang all agree that A operator+(const A&, const A&) is the best overload, Is it a typo?

@jensmaurer
Copy link
Member

I disagree that the comment claims that the best operator is the built-in operator.
It clearly says you choose the (user-defined) operator+ in preference over the built-in operator.
"choose X over Y" means "take X because it's better / you like it more than Y".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants