Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2004-04-19 12:59:14


From: "Janusz Piwowarski" <jpiw_at_[hidden]>
> Rob Stewart writes:
>
> > That makes the result of the expression quite explicit. I can't
> > see any problems with that approach. I'd expect an exception if
> > the resulting month doesn't have the requested day. OTOH, if
> > date's ctor were to take an extra argument, or if there was a
> > date factory function supplying the different behavior, you could
> > specify that you want clipping to the last day of the designated
> > month:
> >
> > date(d.month() + 2 * months, d.day(), clip_to_eom)
> > make_date_clipped_to_end_of_month(d.month() + 2 * months,
> > d.day())
> >
>
> IMHO, simple date wrappers can give more readability:
>
> d.allow_clipping_to_eom() + 2*months;
> d.disallow_clipping_to_eom() + 2*months;

That would require modifying the date class to add new mfs for
each style, right? Or did you mean that "d" was of a wrapper
type?

> or
>
> allow_clipping_to_eom(d) + 2*months;
> disallow_clipping_to_eom(d) + 2*months;
>
> where adding months to date directly isn't allowed.

That sounds like an excellent approach. Not only might the
library provide one or more such date wrappers and factory
functions, but this provides a clear usage pattern that custom
wrappers can follow.

-- 
Rob Stewart                           stewart_at_[hidden]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

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