
Hi all, I've updated the Boost Constrained Value library (which is likely to be reviewed soon) -- the list of changes is below: - added unconstrained -- a new constrained alias to replace it in release mode if constraint-checking is not needed and efficiency is a concern, - added Examples section to the documentation, - other minor corrections and improvements in the documentation, - using BOOST_THROW_EXCEPTION instead of boost::throw_exception() (requires Boost version 1.37.0), - fixed one place to make a better use of EBO. As usually, the code and documentation can be downloaded here: http://rk.go.pl/f/constrained_value.zip The documentation is also available online here: http://rk.go.pl/r/constrained_value Best regards, Robert Kawulak -=##############=- "I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein

Robert Kawulak wrote:
Hi all,
I've updated the Boost Constrained Value library (which is likely to be reviewed soon) -- the list of changes is below: - added unconstrained -- a new constrained alias to replace it in release mode if constraint-checking is not needed and efficiency is a concern, - added Examples section to the documentation, - other minor corrections and improvements in the documentation, - using BOOST_THROW_EXCEPTION instead of boost::throw_exception() (requires Boost version 1.37.0), - fixed one place to make a better use of EBO.
As usually, the code and documentation can be downloaded here: http://rk.go.pl/f/constrained_value.zip The documentation is also available online here: http://rk.go.pl/r/constrained_value
Thanks. I thought to use 'unconstrained', but this isn't really what I need. I have a fixed_pt integer class, //! signed fixed pt template<int int_bits, int frac_bits, typename base_type=int, typename error_policy=cv::throw_exception<>, typename round_policy=rnd<base_type> > struct fixed_pt : ... typedef typename cv::bounded_int<base_type, min, max,error_policy>::type val_t; When I want to turn off checking, it seems the thing to do is use an error_policy which ignores the error. I've been using this, which I got from you some time ago: struct no_error_policy { template <typename V, class C> void operator () (V & old_val, const V & new_val, C &) { old_val = new_val; } }; So I can write: fixed_pt<16,5,int,cv::no_error_policy> f; Maybe this is a useful addition to the lib, or at least as an example?

Hi Neal,
From: Neal Becker I thought to use 'unconstrained', but this isn't really what I need. I have a fixed_pt integer class,
//! signed fixed pt template<int int_bits, int frac_bits, typename base_type=int, typename error_policy=cv::throw_exception<>, typename round_policy=rnd<base_type> > struct fixed_pt : ... typedef typename cv::bounded_int<base_type, min, max,error_policy>::type val_t;
When I want to turn off checking, it seems the thing to do is use an error_policy which ignores the error. I've been using this, which I got from you some time ago:
struct no_error_policy { template <typename V, class C> void operator () (V & old_val, const V & new_val, C &) { old_val = new_val; } };
So I can write: fixed_pt<16,5,int,cv::no_error_policy> f;
Maybe this is a useful addition to the lib, or at least as an example?
OK, now I think I see what you want to do. I don't think using this policy is a good idea for two reasons: - as I've written before, it is not a correct error policy in a general case. It will break the bounded object's invariant (and fire an assertion) if you assign an invalid value; - it will make it harder for the compiler to optimize the unnecessary checks away. What I would suggest is using bounded_int when there is actually a need for error checking, and using unconstrained when there should be no error-checking: struct no_error_checking {}; // a tag to indicate no checks at all template<... typename base_type = int, typename error_policy = cv::throw_exception<> ...> struct fixed_pt { typedef typename if_< is_same<error_policy, no_error_checking >::type, cv::unconstrained<base_type>::type, cv::bounded_int<base_type, min, max, error_policy>::type >::type val_t; Or, if there are no issues with the interface compatibility, you may use the underlying value type directly: typedef typename if_< is_same<error_policy, no_error_checking >::type, base_type, cv::bounded_int<base_type, min, max, error_policy>::type >::type val_t; Hope this helps, Robert
participants (2)
-
Neal Becker
-
Robert Kawulak