Boost logo

Boost :

Subject: Re: [boost] [gsoc 2013] draft proposal for chrono::date
From: Howard Hinnant (howard.hinnant_at_[hidden])
Date: 2013-05-03 13:53:59


On May 3, 2013, at 1:46 PM, "Vicente J. Botet Escriba" <vicente.botet_at_[hidden]> wrote:

> Howard, I believe I start to understand why you don't want day/month/year to validate its input.
> I suspect that the rationale is quite simple, you are relaying on undefined behavior when the value of these parameters is out of range, isn't it?

class day
{
    int d_;
public:
    constexpr
    explicit
    day(int d) noexcept
        : d_(d)
        {}

    constexpr operator int() const noexcept {return d_;}
};

day d(623); // no undefined behavior

The rationale for not checking if day is within a valid range (like I did for http://home.roadrunner.com/~hinnant/bloomington/date.html), is simply performance.

One can not completely validate a day without the knowledge of the year and month. There are two design spaces to explore:

1. Validate as much as you can as early as you can. This was the approach taken by my 2011 paper and which was criticized for low performance.

2. Validate only once when you have the complete information.

1. didn't work. So now I'm proposing 2. I'm flexible. :-) There is no undefined behavior involved.

Howard


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