Boost logo

Boost Users :

Subject: Re: [Boost-users] [review][constrained_value] Review of Constrained Value Library begins today
From: Mika Heiskanen (mika.heiskanen_at_[hidden])
Date: 2008-12-03 05:23:21


Mathias Gaunard wrote:
> Jeff Garland wrote:
>
>> bounded_int<int, 0, 23>::type hour;
>> hour = 20; // OK
>> hour = 26; // exception!
>>
>> Behavior in case of assignment of an invalid value can be customized.
>
> I think this is wrong.
> Providing an invalid value should be a non-recoverable programming error.
> Non-recoverable means it should abort the program, and programming error
> means it should only be enabled in debug mode.
> i.e. an assert is the best choice to assert the preconditions are met.

How about this then:

   hour = boost::lexical_cast<int>(user_input_string);

Here user_input could come for example from a query string. It would be pointless to use
the bounded_int class if I'd have to validate the user input myself.

--> Mika Heiskanen


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net