libstdc++/8529: wontcompile copy() of map to ostream_iterator

j.tevessen@gmx.net j.tevessen@gmx.net
Mon Nov 11 09:36:00 GMT 2002


>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 
   td::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 OutputIter 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 OutputIter
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 OutputIter
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 OutputIter
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 OutputIter 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:



More information about the Gcc-prs mailing list