Boost logo

Boost :

From: christopher diggins (cdiggins_at_[hidden])
Date: 2005-09-23 09:06:34


----- Original Message -----
From: "Robert Kawulak" <kawulak_at_[hidden]>
Newsgroups: gmane.comp.lib.boost.devel
Sent: Friday, September 23, 2005 7:47 AM
Subject: Re: Bounded types

>> I have written something like this for signal processing
>> application. The
>> bounded types are integer-like. Basically, all it does it
>> perform a check
>> action when a value is assigned to it. The check function is
>> specified as
>> a template policy parameter. The version I wrote has three
>> policies. If
>> the assigned value is out of range, the action could
>> 1) limit to the desired range
>> 2) wrap the value (as if an integer of some small width)
>> 3) throw
>
> Yeah, there are all the abovementioned behaviours implemented in my
> version,
> plus ignore (for efficiency in release versions). Furthermore, in case 3
> you
> may choose among throwing an exception, setting the ERRNO or simply
> ignoring
> the invalid operation. Of course the policies are extensible and let you
> specify other action than listed above. And the policies let you also pick
> your own ordering function used to compare values against bounds (this is
> especially useful when using them with non-integral types).

On this topic:

Jeff Garland already has implemented something similar within the Boost
date_time library called the constrained_value type. I made a variation of
constrained_value, with some contribution from the Boost mailing list last
year (search the archives for constrained_value). My version is here:
http://www.cdiggins.com/constrained_value.hpp and some basic tests are at
http://www.cdiggins.com/cv_test.cpp . My approach was to keep the policy as
simple as possible and that is one which provides only the entire assignment
operation (this entails the contraints checking, and exceptional behaviour),
rather than breaking it down into several steps.

Time constraints do not permit me to follow through on the constrained_value
type submission, but I encourage you to look at and modify the code as much
as you want. There is also an article about it at the C++ users journal (
http://www.cuj.com/documents/cuj0412d/ )

best of luck,
Christopher Diggins
http://www.cdiggins.com


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