Index: boost/date_time/posix_time/posix_time_io.hpp =================================================================== --- boost/date_time/posix_time/posix_time_io.hpp (revision 68583) +++ boost/date_time/posix_time/posix_time_io.hpp (working copy) @@ -45,22 +45,25 @@ std::basic_ostream& operator<<(std::basic_ostream& os, const ptime& p) { - boost::io::ios_flags_saver iflags(os); - typedef boost::date_time::time_facet custom_ptime_facet; - typedef std::time_put std_ptime_facet; - std::ostreambuf_iterator oitr(os); - if (std::has_facet(os.getloc())) - std::use_facet(os.getloc()).put(oitr, os, os.fill(), p); - else { - //instantiate a custom facet for dealing with times since the user - //has not put one in the stream so far. This is for efficiency - //since we would always need to reconstruct for every time period - //if the locale did not already exist. Of course this will be overridden - //if the user imbues as some later point. - custom_ptime_facet* f = new custom_ptime_facet(); - std::locale l = std::locale(os.getloc(), f); - os.imbue(l); - f->put(oitr, os, os.fill(), p); + typename std::basic_ostream::sentry no_error_sentry(os); + if (no_error_sentry) { + boost::io::ios_flags_saver iflags(os); + typedef boost::date_time::time_facet custom_ptime_facet; + typedef std::time_put std_ptime_facet; + std::ostreambuf_iterator oitr(os); + if (std::has_facet(os.getloc())) + std::use_facet(os.getloc()).put(oitr, os, os.fill(), p); + else { + //instantiate a custom facet for dealing with times since the user + //has not put one in the stream so far. This is for efficiency + //since we would always need to reconstruct for every time period + //if the locale did not already exist. Of course this will be overridden + //if the user imbues as some later point. + custom_ptime_facet* f = new custom_ptime_facet(); + std::locale l = std::locale(os.getloc(), f); + os.imbue(l); + f->put(oitr, os, os.fill(), p); + } } return os; } @@ -112,24 +115,27 @@ std::basic_ostream& operator<<(std::basic_ostream& os, const boost::posix_time::time_period& p) { - boost::io::ios_flags_saver iflags(os); - typedef boost::date_time::time_facet custom_ptime_facet; - typedef std::time_put std_time_facet; - std::ostreambuf_iterator oitr(os); - if (std::has_facet(os.getloc())) { - std::use_facet(os.getloc()).put(oitr, os, os.fill(), p); + typename std::basic_ostream::sentry no_error_sentry(os); + if (no_error_sentry) { + boost::io::ios_flags_saver iflags(os); + typedef boost::date_time::time_facet custom_ptime_facet; + typedef std::time_put std_time_facet; + std::ostreambuf_iterator oitr(os); + if (std::has_facet(os.getloc())) { + std::use_facet(os.getloc()).put(oitr, os, os.fill(), p); + } + else { + //instantiate a custom facet for dealing with periods since the user + //has not put one in the stream so far. This is for efficiency + //since we would always need to reconstruct for every time period + //if the local did not already exist. Of course this will be overridden + //if the user imbues as some later point. + custom_ptime_facet* f = new custom_ptime_facet(); + std::locale l = std::locale(os.getloc(), f); + os.imbue(l); + f->put(oitr, os, os.fill(), p); + } } - else { - //instantiate a custom facet for dealing with periods since the user - //has not put one in the stream so far. This is for efficiency - //since we would always need to reconstruct for every time period - //if the local did not already exist. Of course this will be overridden - //if the user imbues as some later point. - custom_ptime_facet* f = new custom_ptime_facet(); - std::locale l = std::locale(os.getloc(), f); - os.imbue(l); - f->put(oitr, os, os.fill(), p); - } return os; } @@ -178,22 +184,25 @@ std::basic_ostream& operator<<(std::basic_ostream& os, const time_duration& td) { - boost::io::ios_flags_saver iflags(os); - typedef boost::date_time::time_facet custom_ptime_facet; - typedef std::time_put std_ptime_facet; - std::ostreambuf_iterator oitr(os); - if (std::has_facet(os.getloc())) - std::use_facet(os.getloc()).put(oitr, os, os.fill(), td); - else { - //instantiate a custom facet for dealing with times since the user - //has not put one in the stream so far. This is for efficiency - //since we would always need to reconstruct for every time period - //if the locale did not already exist. Of course this will be overridden - //if the user imbues as some later point. - custom_ptime_facet* f = new custom_ptime_facet(); - std::locale l = std::locale(os.getloc(), f); - os.imbue(l); - f->put(oitr, os, os.fill(), td); + typename std::basic_ostream::sentry no_error_sentry(os); + if (no_error_sentry) { + boost::io::ios_flags_saver iflags(os); + typedef boost::date_time::time_facet custom_ptime_facet; + typedef std::time_put std_ptime_facet; + std::ostreambuf_iterator oitr(os); + if (std::has_facet(os.getloc())) + std::use_facet(os.getloc()).put(oitr, os, os.fill(), td); + else { + //instantiate a custom facet for dealing with times since the user + //has not put one in the stream so far. This is for efficiency + //since we would always need to reconstruct for every time period + //if the locale did not already exist. Of course this will be overridden + //if the user imbues as some later point. + custom_ptime_facet* f = new custom_ptime_facet(); + std::locale l = std::locale(os.getloc(), f); + os.imbue(l); + f->put(oitr, os, os.fill(), td); + } } return os; }