Boost logo

Boost :

From: pongba (weapon.liu_at_[hidden])
Date: 2007-08-22 00:59:58


Robert Kawulak <tigrisek <at> interia.pl> writes:

>
> bounded_int<int, 0, 23>::type hour;
> hour = 20; // OK
> hour = 26; // error -- throws an exception

I think the design of the interface is an example of taking generic programming
too far. Making the constraints/predicates template parameters would have the
limitations that only state-less functors and compile-time constraints could be
accepted. This can be unacceptable, if, for instance, my predicate is a
state-ful functor, or if it's a binded function (e.g. boost::bind(f, _1, x) ).
So why not generalize the interface using boost::function, like this:

template<typename T>
class constraint_data
{
public:
typedef boost::function<bool(T const&)> constraint_t;
...
void add_constraint(constraint_t constraint);

private:
...
std::vector<constraint_t> v;
};

We can have add_constraints and var-arg constructors when C++09 is out:

constraint_data(std::initializer_list<constraint_t> list){ ... }


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