Boost logo

Boost :

From: Vyacheslav E. Andrejev (vandrejev_at_[hidden])
Date: 2004-10-14 05:09:56


Hi there,

I've found wrong usage of std::stringstream::narrow in date_parsing.hpp

    template<class date_type, class iterator_type>
    inline
    date_type from_stream_type(iterator_type& beg,
                               iterator_type& end,
                               wchar_t)
    {
      std::stringstream ss("");
      while(beg != end) {
        ss << ss.narrow(*beg++, 'X'); // 'X' will cause exception to be
thrown
      }
      return parse_date<date_type>(ss.str());
    }

In the code above ss.narrow does nothing, because the argument of narrow
function already has type char, not wchar_t at all. I think, that the right
code should be like this:

    template<class date_type, class iterator_type>
    inline
    date_type from_stream_type(iterator_type& beg,
                               iterator_type& end,
                               wchar_t)
    {
      std::stringstream ss("");
      while(beg != end) {
        ss << std::use_facet<std::ctype<wchar_t>
>(std::locale()).narrow(*beg++, 'X');
      }
      return parse_date<date_type>(ss.str());
    }

-- 
______________________________
Vyacheslav E. Andrejev
System Architect, Excelsior, LLC
E-mail: vandrejev_at_[hidden]
ICQ: 7152604

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk