Ticket #1574: fix-ptime-operator-2nd-bug1574.patch

File fix-ptime-operator-2nd-bug1574.patch, 1.9 KB (added by christian.stimming@…, 12 years ago)

Better patch for this error which (after reading my Stroustrup again) is using the ostream's sentry constructor to check for potential failbits.

  • boost/date_time/posix_time/posix_time_io.hpp

    old new  
    4545  std::basic_ostream<CharT, TraitsT>&
    4646  operator<<(std::basic_ostream<CharT, TraitsT>& os,
    4747             const ptime& p) {
     48    typedef std::basic_ostream<CharT, TraitsT>       __ostream_type;
     49    typename __ostream_type::sentry cerb(os);
     50    if (cerb) {
    4851    boost::io::ios_flags_saver iflags(os);
    4952    typedef boost::date_time::time_facet<ptime, CharT> custom_ptime_facet;
    5053    typedef std::time_put<CharT>                  std_ptime_facet;
     
    6265      os.imbue(l);
    6366      f->put(oitr, os, os.fill(), p);
    6467    }
     68    }
    6569    return os;
    6670  }
    6771
     
    112116  std::basic_ostream<CharT, TraitsT>&
    113117  operator<<(std::basic_ostream<CharT, TraitsT>& os,
    114118             const boost::posix_time::time_period& p) {
     119    typedef std::basic_ostream<CharT, TraitsT>       __ostream_type;
     120    typename __ostream_type::sentry cerb(os);
     121    if (cerb) {
    115122    boost::io::ios_flags_saver iflags(os);
    116123    typedef boost::date_time::time_facet<ptime, CharT> custom_ptime_facet;
    117124    typedef std::time_put<CharT>                  std_time_facet;
     
    130137      os.imbue(l);
    131138      f->put(oitr, os, os.fill(), p);
    132139    }
     140    }
    133141    return os;
    134142  }
    135143
     
    178186  std::basic_ostream<CharT, Traits>&
    179187  operator<<(std::basic_ostream<CharT, Traits>& os, const time_duration& td)
    180188  {
     189    typedef std::basic_ostream<CharT, Traits>       __ostream_type;
     190    typename __ostream_type::sentry cerb(os);
     191    if (cerb) {
    181192    boost::io::ios_flags_saver iflags(os);
    182193    typedef boost::date_time::time_facet<ptime, CharT> custom_ptime_facet;
    183194    typedef std::time_put<CharT>                  std_ptime_facet;
     
    195206      os.imbue(l);
    196207      f->put(oitr, os, os.fill(), td);
    197208    }
     209    }
    198210    return os;
    199211  }
    200212