public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* libstdc++/8529: wontcompile copy() of map to ostream_iterator
@ 2002-11-11 9:36 j.tevessen
0 siblings, 0 replies; 2+ messages in thread
From: j.tevessen @ 2002-11-11 9:36 UTC (permalink / raw)
To: gcc-gnats; +Cc: j.tevessen
>Number: 8529
>Category: libstdc++
>Synopsis: wontcompile copy() of map to ostream_iterator
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Mon Nov 11 09:36:02 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Johannes Tevessen
>Release: 3.2
>Organization:
>Environment:
System: Linux aris.dummy.de 2.4.19-pre8 #1 Sam Mai 4 18:10:42 CEST 2002 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../configure --prefix=/usr --enable-languages=c,c++
>Description:
g++ doesn't seem to find the matching operator<< when
std::copy()ing a std::map to an output_iterator
Error is like this:
/usr/include/c++/3.2/bits/stream_iterator.h: In member function
\x13td::ostream_iterator<_Tp, _CharT, _Traits>& std::ostream_iterator<_Tp,
_CharT, _Traits>::operator=(const _Tp&) [with _Tp =
std::pair<std::string,
int>, _CharT = char, _Traits = std::char_traits<char>]':
mapproblem.cc:228: instantiated from \x1fOutputIter std::__copy(_InputIter,
_InputIter, _OutputIter, std::input_iterator_tag) [with _InputIter =
std::_Rb_tree_iterator<std::pair<const std::string, int>, std::pair<const
std::string, int>&, std::pair<const std::string, int>*>, _OutputIter =
std::ostream_iterator<std::pair<std::string, int>, char,
std::char_traits<char> >]'
mapproblem.cc:260: instantiated from \x1fOutputIter
std::__copy_aux2(_InputIter, _InputIter, _OutputIter, __false_type) [with
_InputIter = std::_Rb_tree_iterator<std::pair<const std::string, int>,
std::pair<const std::string, int>&, std::pair<const std::string, int>*>,
_OutputIter = std::ostream_iterator<std::pair<std::string, int>, char,
std::char_traits<char> >]'
mapproblem.cc:298: instantiated from \x1fOutputIter
std::__copy_ni2(_InputIter, _InputIter, _OutputIter, __false_type) [with
_InputIter = std::_Rb_tree_iterator<std::pair<const std::string, int>,
std::pair<const std::string, int>&, std::pair<const std::string, int>*>,
_OutputIter = std::ostream_iterator<std::pair<std::string, int>, char,
std::char_traits<char> >]'
mapproblem.cc:321: instantiated from \x1fOutputIter
std::__copy_ni1(_InputIter, _InputIter, _OutputIter, __false_type) [with
_InputIter = std::_Rb_tree_iterator<std::pair<const std::string, int>,
std::pair<const std::string, int>&, std::pair<const std::string, int>*>,
_OutputIter = std::ostream_iterator<std::pair<std::string, int>, char,
std::char_traits<char> >]'
mapproblem.cc:342: instantiated from \x1fOutputIter std::copy(_InputIter,
_InputIter, _OutputIter) [with _InputIter =
std::_Rb_tree_iterator<std::pair<const std::string, int>, std::pair<const
std::string, int>&, std::pair<const std::string, int>*>, _OutputIter =
std::ostream_iterator<std::pair<std::string, int>, char,
std::char_traits<char> >]'
mapproblem.cc:21: instantiated from here
/usr/include/c++/3.2/bits/stream_iterator.h:141: no match for
std::basic_ostream<char, std::char_traits<char> >& << const
std::pair<std::string, int>&' operator
/usr/include/c++/3.2/bits/ostream.tcc:55: candidates are:
std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT,
_Traits>::operator<<(std::basic_ostream<_CharT,
_Traits>&(*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char,
_Traits = std::char_traits<char>]
(...)
>How-To-Repeat:
Try to compile this:
#include <cstdlib>
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <iterator>
std::ostream&
operator<< (std::ostream& ostr, const std::pair<std::string,int>& mypair) {
return ostr << mypair.first;
}
int
main (void) {
std::map<std::string,int> mymap;
mymap[std::string("myid1")] = 1;
mymap[std::string("myid2")] = 2;
std::copy (mymap.begin (), mymap.end (),
std::ostream_iterator<std::pair<std::string,int> >
(std::cout, " "));
return EXIT_SUCCESS;
}
>Fix:
Really don't know. However, I had no problem compiling this
with Intel's C++ 5.0 compiler on Linux
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: libstdc++/8529: wontcompile copy() of map to ostream_iterator
@ 2002-11-11 9:50 bangerth
0 siblings, 0 replies; 2+ messages in thread
From: bangerth @ 2002-11-11 9:50 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, j.tevessen, nobody
Synopsis: wontcompile copy() of map to ostream_iterator
State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Mon Nov 11 09:50:53 2002
State-Changed-Why:
Your op<< is in the global namespace, but at the place where
it is used (inside std::copy and the ostream_iterator), only
operators in namespace std are looked up because both operands
are in namespace std. There are several other instances
of this bug/feature in the database.
You can work around the problem by putting the op<< into
namespace std.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8529
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-11-11 17:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-11 9:36 libstdc++/8529: wontcompile copy() of map to ostream_iterator j.tevessen
2002-11-11 9:50 bangerth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).