How do I use the canonical definition of != out of == in std::rel_ops?

#include <utility>

namespace n {
class c { };

bool operator ==( c const&, c const& )
{
return true;
}

using namespace std::rel_ops;

}

int main()
{
n::c a, b;
a != b; // does not compile
}

Re: using std::rel_ops by Carl

Carl
Wed Apr 12 17:26:04 CDT 2006


"Angel Tsankov" <fn42551@fmi.uni-sofia.bg> wrote in message
news:O95p7snXGHA.3704@TK2MSFTNGP03.phx.gbl...
> How do I use the canonical definition of != out of == in std::rel_ops?
>
> #include <utility>
>
> namespace n {
> class c { };
>
> bool operator ==( c const&, c const& )
> {
> return true;
> }
>
> using namespace std::rel_ops;

move the above line...

>
> }

to here. The operators in std::relops need to be in-scope at the point of
use.

>
> int main()
> {
> n::c a, b;
> a != b; // does not compile
> }
>

-cd



Re: using std::rel_ops by Igor

Igor
Wed Apr 12 17:27:43 CDT 2006

Angel Tsankov <fn42551@fmi.uni-sofia.bg> wrote:
> How do I use the canonical definition of != out of == in std::rel_ops?
>
> #include <utility>
>
> namespace n {
> class c { };
>
> bool operator ==( c const&, c const& )
> {
> return true;
> }
>
> using namespace std::rel_ops;

Make it

using std::rel_ops::operator!=;

A using declaration (that's what I show) introduces a new name as a
synonym for the entity named in the declaration. This name can then be
referred to from other scopes.

A using directive (that's what you have in your code) does not introduce
any new names, but simply aids name lookup within the scope in which it
appears. It has no effect outside of said scope.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: using std::rel_ops by Angel

Angel
Thu Apr 13 01:23:50 CDT 2006

>> #include <utility>
>>
>> namespace n {
>> class c { };
>>
>> bool operator ==( c const&, c const& )
>> {
>> return true;
>> }
>>
>> using namespace std::rel_ops;
>
> Make it
>
> using std::rel_ops::operator!=;
>
> A using declaration (that's what I show) introduces a new name as a
> synonym for the entity named in the declaration. This name can then be
> referred to from other scopes.
>
> A using directive (that's what you have in your code) does not introduce
> any new names, but simply aids name lookup within the scope in which it
> appears. It has no effect outside of said scope.

Thanks, Igor! That's exactly what I need.