This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: rel_ops issues
- To: Joe Buck <jbuck at racerx dot synopsys dot com>
- Subject: Re: rel_ops issues
- From: Gabriel Dos Reis <Gabriel dot Dos-Reis at cmla dot ens-cachan dot fr>
- Date: 03 Apr 2001 08:31:01 +0200
- Cc: Gabriel dot Dos-Reis at cmla dot ens-cachan dot fr (Gabriel Dos Reis), bkoz at redhat dot com (Benjamin Kosnik), Theodore dot Papadopoulo at sophia dot inria dot fr (Theodore Papadopoulo), libstdc++ at gcc dot gnu dot org
- Organization: CMLA, ENS Cachan -- CNRS UMR 8536 (France)
- References: <200104030125.SAA10107@racerx.synopsys.com>
Joe Buck <jbuck@racerx.synopsys.com> writes:
[...]
| > Consider what should happen with:
| >
| > #include <stdio.h>
| >
| > namespace Mine
| > {
| > template<typename T>
| > bool operator==(const X<T>& a, const X<T>& b)
| > {
| > printf("%p == %p\n", &a, &b);
| > return true;
| > }
| >
| > template<typename T>
| > bool operator!=(const X<T>& a, const X<T>& b)
| > {
| > printf("%p != %p\n", &a, &b);
| > return false;
| > }
| >
| > struct Y : X<int> { };
| > }
|
| So?
|
| This is not a complete example.
Fair enough
| ... Please show me where you put the using
| directive,
Inside the function as you were suggesting.
| ... and which code malfunctions, remembering that because of the
| way partial specialization works, bool operator!=(const X<T>& a, const
| X<T>& b) will be chosen over the one in rel_ops (there is no ambiguity).
No. First, there is nothing called function partial specialization. We
only have function overloading. Second, the example I provided will
involve a conversion so the exact match provided by the general
template will be chosen -- contrary to what you're saying.
#include <stdio.h>
namespace standard
{
namespace rel_ops
{
template<typename T>
bool operator!=(const T& u, const T& v)
{ return !(u == v); }
}
template<typename I>
void f(I p, I q)
{
using rel_ops::operator!=;
*p == *q;
*p != *q;
}
}
namespace Mine
{
template<typename T> struct X { };
template<typename T>
bool operator==(const X<T>& a, const X<T>& b)
{
printf("%p == %p\n", &a, &b);
}
template<typename T>
bool operator!=(const X<T>& a, const X<T>& b)
{
printf("%p != %p\n", &a, &b);
}
struct Y : X<int> { };
}
Now the following is intended to show which operator!= is chosen
int main()
{
Mine::Y a, b;
standard::f(&a, &b);
}
it will output
0xbffff3cb == 0xbffff3ca
0xbffff3cb == 0xbffff3ca
instead of
0xbffff3cb == 0xbffff3ca
0xbffff3cb != 0xbffff3ca
-- Gaby