a string problem

Gabriel Dos Reis dosreis@cmla.ens-cachan.fr
Wed Oct 13 06:00:00 GMT 1999


scleary@jerviswebb.com writes:

| > > #include <string>
| > >
| > > void foo() { std::string s(10,0); }
| >
| > whoops. This is not a compiler or library implementation bug--the
| > arugments get deduced as iterators, as you pointed out earlier. You'll
| > have to cast to
| >
| > string s(10, char(0)) to call the constructor that you're intending.
| >
| 
| I beg to differ.  It is an implementation bug, according to ANSI 21.3.1 para
| 15, which states for constructor "template <class InputIterator>
| basic_string(InputIterator begin, InputIterator end, const Allocator & a =
| Allocator());": "If InputIterator is an integral type, [this constructor
| call is] equivalent to 'basic_string(static_cast<size_type>(begin),
| static_cast<value_type>(end))'"  Also see ANSI 23.1.1 para 9-11.

Actually you're right.  It just happens that the reported bug appears
to be known... Let me quote from libstdc++/docs/17_intro/TODO:

===
- fix template members of basic_string<> to overload iterators and
  non-iterators properly.  (This is the infamous hack as in vector<> etc
  23.1.1 para 10.)
===

-- Gaby


More information about the Libstdc++ mailing list