[gecode-users] global operator<<

Christian Schulte cschulte at kth.se
Thu Oct 30 12:06:05 CET 2008


Thanks for the info, we'll check and fix it if needed for 3.0.

Thanks
Christian

--
Christian Schulte, www.ict.kth.se/~cschulte/


-----Original Message-----
From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
Of Max
Sent: Wednesday, October 29, 2008 4:12 PM
To: users at gecode.org
Subject: [gecode-users] global operator<<

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

_______________________________________________
Gecode users mailing list
users at gecode.org
https://www.gecode.org/mailman/listinfo/gecode-users





More information about the gecode-users mailing list