Ticket #7187: rational-wide-streams.patch

File rational-wide-streams.patch, 2.1 KB (added by Mathias Hasselmann <mathias@…>, 10 years ago)

One possible patch

  • boost/rational.hpp

     
    525525
    526526    // A utility class to reset the format flags for an istream at end
    527527    // of scope, even in case of exceptions
     528    template <typename CharType>
    528529    struct resetter {
    529         resetter(std::istream& is) : is_(is), f_(is.flags()) {}
     530        resetter(std::basic_istream<CharType>& is) : is_(is), f_(is.flags()) {}
    530531        ~resetter() { is_.flags(f_); }
    531         std::istream& is_;
    532         std::istream::fmtflags f_;      // old GNU c++ lib has no ios_base
     532        std::basic_istream<CharType>& is_;
     533        typename std::basic_istream<CharType>::fmtflags f_; // old GNU c++ lib has no ios_base
    533534    };
    534535
    535536}
    536537
    537538// Input and output
    538 template <typename IntType>
    539 std::istream& operator>> (std::istream& is, rational<IntType>& r)
     539template <typename CharType, typename IntType>
     540std::basic_istream<CharType>& operator>> (std::basic_istream<CharType>& is,
     541                                          rational<IntType>& r)
    540542{
    541543    IntType n = IntType(0), d = IntType(1);
    542     char c = 0;
    543     detail::resetter sentry(is);
     544    CharType c = 0;
     545    detail::resetter<CharType> sentry(is);
    544546
    545547    is >> n;
    546548    c = is.get();
    547549
    548     if (c != '/')
    549         is.clear(std::istream::badbit);  // old GNU c++ lib has no ios_base
     550    if (c != static_cast<CharType>('/'))
     551        is.clear(std::basic_istream<CharType>::badbit);  // old GNU c++ lib has no ios_base
    550552
    551553#if !defined(__GNUC__) || (defined(__GNUC__) && (__GNUC__ >= 3)) || defined __SGI_STL_PORT
    552554    is >> std::noskipws;
     
    562564}
    563565
    564566// Add manipulators for output format?
    565 template <typename IntType>
    566 std::ostream& operator<< (std::ostream& os, const rational<IntType>& r)
     567template <typename CharType, typename IntType>
     568std::basic_ostream<CharType>& operator<< (std::basic_ostream<CharType>& os,
     569                                          const rational<IntType>& r)
    567570{
    568     os << r.numerator() << '/' << r.denominator();
     571    os << r.numerator() << static_cast<CharType>('/') << r.denominator();
    569572    return os;
    570573}
    571574