[gecode-users] global operator<<
Max
chaosangel at gmx.de
Wed Oct 29 16:12:20 CET 2008
So, i'm not that experienced with dependent name lookup, so i asked a
more experienced developer i know and he told me that your operator
implementation is wrong.
I tried to print some results using
IntVarArray x;
std::cout << x;
In my test application it works, in my real application i do get an
error that he can not find the operator for that type, or even worse,
can not convert Gecode::IntVarArray to some of my types.
The problem is, that your operators are defined in global namespace. He
send me a little example:
namespace XY {
struct Bar {};
std::ostream& operator<<(std::ostream& os, Bar&);
void f() {
Bar b;
Clasp::Literal l;
Gcode::Foo f;
std::cout << b << std::endl; // 1. OK
std::cout << l << std::endl; // 2. OK, ADL!
std::cout << f << std::endl; // 3. Error!
}
}
The first call is ok, trivial.
The second call is ok, because the operator<< for Clasp::Literal is
defined in namespace Clasp, so argument dependent lookup finds the operator.
The third version throws an error, cannot convert from Gecode::Foo to
XY::Bar because the namespace XY already has an operator, the global
namespace is not searched for. ADL does not find the operator in
namespace Gecode.
So, i hope everything is right i just said. Maybe you could move your
operators to the gecode namespace, otherwise i would have to write
::operator<<(std::cout, myIntVar);
Thanks
Max
More information about the gecode-users
mailing list