Boost logo

Boost :

From: Robert Kawulak (kawulak_at_[hidden])
Date: 2008-06-20 03:57:11

Dear Boosters,

I'm glad to say the Boost Constrained Value library is finally ready for a
formal review. To remind what this library is about, an excerpt from the
section of the documentation is attached at the bottom of this message.

Jeff, you volunteered to be the review manager - is your proposition still up to
date? If so, I'd be thankful if you could do the work. ;-)

The code and documentation can be downloaded here:
The documentation is also available online here:

The only thing that's missing is test programs - I will try to add them
during/after the review.

The changes made since previous version:
- rewritten the documentation at some points and added tutorial,
- no more value generators - direct types or MPL integral constants are used
- bounded types use bounds exclusion instead of inclusion (so bounds are
included by default in all cases),
- changed order and default values of some of template parameters,
- removed throw_verbose_exception error policy,
- made other minor fixes and improvements.

As always, feedback is welcome.

Best regards,
Robert Kawulak


The Boost Constrained Value library contains class templates useful for creating
constrained objects. A simple example is an object representing an hour of a
day, for which only integers from the range [0, 23] are valid values:

    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. For
instance, instead of throwing an exception as in the example above, the value
may be adjusted to meet the constraint:

    wrapping_int<int, 0, 255>::type buffer_index;
    buffer_index = 257; // OK: adjusts the value to fit in the range by wrapping
    assert( buffer_index == 1 );

The library doesn't focus only on bounded objects as in the examples above --
virtually any constraint can be imposed by using a predicate:

    // constraint (a predicate)
    struct is_odd {
        bool operator () (int i) const
        { return (i % 2) != 0; }

    // and the usage is as simple as:
    constrained<int, is_odd> odd_int = 1;
    odd_int += 2; // OK
    ++odd_int; // exception!

The library has a policy-based design to allow for flexibility in defining
constraints and behavior in case of assignment of invalid values. Policies may
be configured at compile-time for maximum efficiency or may be changeable at
runtime if such dynamic functionality is needed.

Boost list run by bdawes at, gregod at, cpdaniel at, john at