mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-17 12:44:42 +03:00
C.168: switch example to op+ to avoid side tracking about defaults (closes #1955)
This commit is contained in:
@@ -8513,23 +8513,21 @@ Avoiding inconsistent definition in different namespaces
|
|||||||
##### Example
|
##### Example
|
||||||
|
|
||||||
struct S { };
|
struct S { };
|
||||||
bool operator==(S, S); // OK: in the same namespace as S, and even next to S
|
S operator+(S, S); // OK: in the same namespace as S, and even next to S
|
||||||
S s;
|
S s;
|
||||||
|
|
||||||
bool x = (s == s);
|
S r = s + s;
|
||||||
|
|
||||||
This is what a default `==` would do, if we had such defaults.
|
|
||||||
|
|
||||||
##### Example
|
##### Example
|
||||||
|
|
||||||
namespace N {
|
namespace N {
|
||||||
struct S { };
|
struct S { };
|
||||||
bool operator==(S, S); // OK: in the same namespace as S, and even next to S
|
S operator+(S, S); // OK: in the same namespace as S, and even next to S
|
||||||
}
|
}
|
||||||
|
|
||||||
N::S s;
|
N::S s;
|
||||||
|
|
||||||
bool x = (s == s); // finds N::operator==() by ADL
|
S r = s + s; // finds N::operator+() by ADL
|
||||||
|
|
||||||
##### Example, bad
|
##### Example, bad
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user