Boost logo

Boost :

Subject: Re: [boost] [chrono/date] validated versus valid dates
From: Rob Stewart (robertstewart_at_[hidden])
Date: 2013-05-06 20:34:58


On May 6, 2013, at 5:40 AM, "Vicente J. Botet Escriba" <vicente.botet_at_[hidden]> wrote:

> Le 06/05/13 00:21, Rob Stewart a écrit :
>>>
>> The basic idea is reasonable, but I suggest a couple of alternatives. First, I see no value in making is_validated() public. Second, validate() should return void:
>>
>> void
>> date::validate()
>> {
>> if (!is_valid())
>> {
>> throw bad_date();
>> }
>> }
>>
>> bool
>> date::is_valid()
>> {
>> if (validated())
>> {
>> return true;
>> }
>> // do validation
>> if (valid)
>> {
>> validated_ = true;
>> }
>> return valid;
>> }
>>
>> Usage:
>>
>> date d1;
>> d1.validate(); // throws bad_date
>> date d2(year(2013), may, day(5));
>> d2.validate();
>> assert(d2.is_valid());
> I thought about this alternative. As is_valid must be const, this request validated_ to be mutable. I wanted to use one of the unused bits to store this information and I don't know if I can declare a bitfield mutable. Can I?

I don't think so, but the value can be mutable, which would allow you to manipulate the needed nit.

___
Rob

(Sent from my portable computation engine)


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