|
Boost : |
Subject: Re: [boost] [review][constrained_value] Review of Constrained Value Library begins today
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2008-12-06 04:13:09
----- Original Message -----
From: "Jeff Garland" <jeff_at_[hidden]>
To: <boost_at_[hidden]>; <boost-users_at_[hidden]>
Sent: Monday, December 01, 2008 1:30 PM
Subject: [boost] [review][constrained_value] Review of Constrained Value Library begins today
Hi,
what do you think about replacing the typedef by a specific class so instead of writing
bounded<int>::type v;
we write
bounded<int> v;
The advantage to have a specific class (see below) is that it allows to add specific members that have a sens, e. g. change_lower_bound can be added to bounded<int, int, int> but not to bounded_int<int, 0, 100>. The liability is that we need to repeat a lot of constructors. Of course this can be done by the user itself as constrained is a public class but at the end what is more important is the user interface.
This technique has already been used at least on Boost.MultiIndex and Boost.Flyweight.
Best regards,
Vicente
================================================
/// The class of constrained for bounded object types (using within_bounds constraint policy).
template <
typename ValueType,
typename LowerType = ValueType,
typename UpperType = LowerType,
typename ErrorPolicy = throw_exception<>,
typename LowerExclType = boost::mpl::false_,
typename UpperExclType = LowerExclType,
typename CompareType = std::less<ValueType>
>
struct bounded
: constrained<
ValueType,
within_bounds<
LowerType,
UpperType,
LowerExclType,
UpperExclType,
CompareType
>,
ErrorPolicy
>
{
/// The basetype-typedef alias.
typedef
constrained<
ValueType,
within_bounds<
LowerType,
UpperType,
LowerExclType,
UpperExclType,
CompareType
>,
ErrorPolicy
> basetype;
// add all the constructors and specific functions
// ...
};
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk