This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Bug in the egcs STL implementation?
- To: egcs-bugs at cygnus dot com
- Subject: Bug in the egcs STL implementation?
- From: Bavo De Ridder <bavo at ace dot ulyssis dot student dot kuleuven dot ac dot be>
- Date: Thu, 18 Jun 1998 13:36:38 +0200 (CEST)
Hello,
I tried to write a program wich has to copy the standard input into a string.
This can be done in several ways. I took the following approach:
#include <iostream>
#include <iterator>
#include <string>
int main()
{
...
cin.unsetf( ios::skipws );
istream_iterator<char> in( cin );
istream_iterator<char> end;
string s( "" );
s.append( in, end );
...
}
This little piece of code should do the trick. Not very efficient, it reads one
character at a time, and relies heavily on the buffering by the iostreams.
But this piece of code gives the following error when compiling:
/usr/local/include/g++/std/bastring.h: In method
`class basic_string<char,string_char_traits<char>,
__default_alloc_template<true,0> > &
basic_string<char,string_char_traits<char>,
__default_alloc_template<true,0> >::replace(char *, char *,
class istream_iterator<char,int>, class istream_iterator<char,int>)':
/usr/local/include/g++/std/bastring.h:394:
no match for `istream_iterator<char,int> & - istream_iterator<char,int> &'
Not very clear but... looking at line 394 I get the following:
#ifdef __STL_MEMBER_TEMPLATES
template <class charT, class traits, class Allocator>
template <class InputIterator>
basic_string <charT, traits, Allocator>&
basic_string <charT, traits, Allocator>::
replace (iterator i1, iterator i2, InputIterator j1, InputIterator j2)
#else
template <class charT, class traits, class Allocator>
basic_string <charT, traits, Allocator>&
basic_string <charT, traits, Allocator>::
replace (iterator i1, iterator i2, const_iterator j1, const_iterator j2)
#endif
{
const size_type len = length ();
size_type pos = i1 - ibegin ();
size_type n1 = i2 - i1;
size_type n2 = j2 - j1;
My compiler (egcs 1.0.3) seems to define __STL_MEMBER_TEMPLATES so
InputIterators instead of const_iterators are used. Have a look at the
last line of code: "size_type n2 = j2 - j1;" how can you substract two
InputIterators? The only required operations for an InputIterator are:
1) copy constructors (Iter x(Iter y) and Iter(Iter y))
2) =
3) ==
4) !=
5) ++x
6) x++
and not '-'. This is exactly the error egcs gave: he can't find a 'operator -'
method. This seems to me like a bug in the code of replace of basic_string
in the egcs 1.0.3 g++ distribution. Or does egcs uses the HP distribution?
Is this a bug or am I wrong?
Bavo De Ridder