[PATCH] LWG 2989 hide path iostream operators from normal lookup
Jonathan Wakely
jwakely@redhat.com
Thu Jun 21 09:31:00 GMT 2018
On 21/06/18 07:12 +0200, François Dumont wrote:
>That's a great way to define global operators.
>
>I started working on making iterator operators global as we said once
>on this mailing list. I already noticed during that task that when I
>was making a mistake and gcc was complaining about not finding the ==
>operator it was proposing about 80 candidates, so a very big compiler
>error message.
Yes, and it makes compilation slower because every one of those
candidates gets considered by overload resolution every time there's
an == expression.
>Can I generalize this approach ?
No. Unfortunately when the standard explicitly declares an operator at
namespace scope, we're required to define it there.
It's allowed for the comparisons in <random> because the standard
doesn't declare them explicitly, it just says that equality and
inequality expressions must work (in the "Random number engine
requirements" table). That means we can use a hidden friend, because
it meets the requirement, but doesn't add anything to the enclosing
namespace.
IMHO we should specify everything that way, not by declaring explicit
operators at namespace scope, but that's not what the current standard
does.
More information about the Libstdc++
mailing list