Boost logo

Boost :

From: Jeff Garland (jeff_at_[hidden])
Date: 2005-09-15 08:51:34


Won't respond to all the details in this thread, but a few thoughts. There is
already something in the date-time implementation that does much of this
called constrained_value.

http://cvs.sourceforge.net/viewcvs.py/boost/boost/boost/date_time/constrained_value.hpp?rev=1.4&view=auto

The constraints are specified at build time to reduce the footprint of the
runtime object. Boost date-time uses this to range check things like the
month (1..12). The date-time version is policy based so you can specify how
to handle the out of range condition: exception, log, etc. For example,
here's how the month is setup to throw a bad_month exception:

  struct bad_month : public std::out_of_range {...}

  //! Build a policy class for the greg_month_rep
  typedef CV::simple_exception_policy<unsigned short, 1, 12, bad_month>
greg_month_policies;
  //! A constrained range that implements the gregorian_month rules
  typedef CV::constrained_value<greg_month_policies> greg_month_rep;

  greg_month_rep m(13); //bad_month exception

Christopher Diggins has actually extended this idea and published it in CUJ.
For more you can see his weblog.

http://www.artima.com/weblogs/viewpost.jsp?thread=79470

We also discussed this on the developer list, so you'll want to search the
archives.

Long story short is I'd like to see this as a standalone library -- so I'll
help however I can.

Jeff


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