[Bug c++/26512] g++ doesn't recognize user-defined operator<<(ostream, const pair<int, double> &)
bangerth at dealii dot org
gcc-bugzilla@gcc.gnu.org
Wed Mar 8 04:49:00 GMT 2006
------- Comment #11 from bangerth at dealii dot org 2006-03-08 04:49 -------
This is indeed invalid under the present rules:
---------------
typedef std::map<int, double> M;
namespace std {
extern std::ostream &operator <<(std::ostream &f, const M::value_type &p);
};
void f()
{
M m;
std::copy(m.begin(), m.end(),
std::ostream_iterator<M::value_type>(std::cout));
}
---------------
When inside std::copy, the compiler needs to lookup an operator<< for
its arguments. It does so in the present namespace (i.e. std::) as well
as the namespaces of all arguments. The arguments are std::ofstream and
std::pair (and possibly the template arguments of two classes, though
I'm not sure about that). All these arguments are from namespace std::
or are builtin types that have no associated namespace. Lookup therefore
has to fail.
The solution is to put your own definition of operator<< into namespace
std:: -- not pretty, but a solution that we have discussed several times
here in this database...
W.
--
bangerth at dealii dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bangerth at dealii dot org
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26512
More information about the Gcc-bugs
mailing list