Boost logo

Boost :

From: Martin (adrianm_at_[hidden])
Date: 2005-06-23 08:06:30


1. The date_time library in the currenct CVS doesn't follow the standard
formatted input/output requirements in the C++ standard.

e.g.

stringstream s("205-Jan-01");
date d;
s >> d;

will throw "Year out of valid range" exception instead of just setting the
badbit.

The resolution is to use the sentry object and catch exceptions:

template <class charT, class traits>
inline std::basic_istream<charT, traits>&
operator>>(std::basic_istream<charT, traits>& is, date& d) {
  std::basic_istream<charT, traits>::sentry cerberos(is, false);
  if (cerberos) {
    std::ios_base::iostate status = std::ios_base::iostate
(std::ios_base::goodbit);
    try {
      ... //use facet and set status if failed
    }
    catch (...) {
      is.setstate(std::ios_base::badbit);
    }
    if (status)
      is.setstate(status);
  }
  return is
}

---------------
2. The default date format is "%Y-%b-%d" which is very confusing since it is
using a date order that is not common in english speaking countries while it
uses english month names.
The default format should be "%x".
(I know this will create problems with input parsing on some STL libraries but
I think it is a better than the current solution where almost nobody can use
the default).

---------------
3. The streaming functions all add a new facet to the locale if no current
facet has been imbued. Wouldn't it be better to either have a
singleton "default" facet for all streams or imbue the facet to the global
locale instead?


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