Ticket #7187: rational-wide-streams.patch
File rational-wide-streams.patch, 2.1 KB (added by , 10 years ago) |
---|
-
boost/rational.hpp
525 525 526 526 // A utility class to reset the format flags for an istream at end 527 527 // of scope, even in case of exceptions 528 template <typename CharType> 528 529 struct resetter { 529 resetter(std:: istream& is) : is_(is), f_(is.flags()) {}530 resetter(std::basic_istream<CharType>& is) : is_(is), f_(is.flags()) {} 530 531 ~resetter() { is_.flags(f_); } 531 std:: istream& is_;532 std::istream::fmtflags f_;// old GNU c++ lib has no ios_base532 std::basic_istream<CharType>& is_; 533 typename std::basic_istream<CharType>::fmtflags f_; // old GNU c++ lib has no ios_base 533 534 }; 534 535 535 536 } 536 537 537 538 // Input and output 538 template <typename IntType> 539 std::istream& operator>> (std::istream& is, rational<IntType>& r) 539 template <typename CharType, typename IntType> 540 std::basic_istream<CharType>& operator>> (std::basic_istream<CharType>& is, 541 rational<IntType>& r) 540 542 { 541 543 IntType n = IntType(0), d = IntType(1); 542 charc = 0;543 detail::resetter sentry(is);544 CharType c = 0; 545 detail::resetter<CharType> sentry(is); 544 546 545 547 is >> n; 546 548 c = is.get(); 547 549 548 if (c != '/')549 is.clear(std:: istream::badbit); // old GNU c++ lib has no ios_base550 if (c != static_cast<CharType>('/')) 551 is.clear(std::basic_istream<CharType>::badbit); // old GNU c++ lib has no ios_base 550 552 551 553 #if !defined(__GNUC__) || (defined(__GNUC__) && (__GNUC__ >= 3)) || defined __SGI_STL_PORT 552 554 is >> std::noskipws; … … 562 564 } 563 565 564 566 // Add manipulators for output format? 565 template <typename IntType> 566 std::ostream& operator<< (std::ostream& os, const rational<IntType>& r) 567 template <typename CharType, typename IntType> 568 std::basic_ostream<CharType>& operator<< (std::basic_ostream<CharType>& os, 569 const rational<IntType>& r) 567 570 { 568 os << r.numerator() << '/'<< r.denominator();571 os << r.numerator() << static_cast<CharType>('/') << r.denominator(); 569 572 return os; 570 573 } 571 574