This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/26512] g++ doesn't recognize user-defined operator<<(ostream, const pair<int, double> &)
- From: "bangerth at dealii dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Mar 2006 04:49:38 -0000
- Subject: [Bug c++/26512] g++ doesn't recognize user-defined operator<<(ostream, const pair<int, double> &)
- References: <bug-26512-12289@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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