
Hi,
From: Joe Gottman
Robert Kawulak wrote:
Hi,
From: utku
can we create a saturating int with only lower bound set and upper bound is infinite, like
saturating_int<int, 1>::type ImageBoundary;
Yes, you can simply write:
saturating_int<int, 1, boost::integer_traits<int>::const_max>::type ImageBoundary;
Since no int is greater than const_max, the upper bound will never be used for saturation (and I bet compilers will easily optimise the code eliminating the comparison with the upper bound).
Would it be possible for you to make that a default parameter for the class? That would really improve usability for this use-case.
I don't know if it's a good idea to make the default for this special use case - if I'd see something like saturating_int<int, 1>::type, probably it wouldn't be easy for me to guess if it saturates below or over 1. Maybe another set of aliases with more descriptive names would be better? Like: lower_saturating_int<int, 0>::type - clips values less than 0 upper_saturating_int<int, 0>::type - clips values greater than 0 I'm not sure if those names are good enough either... BTW, is this a common use case in some areas? Best regards, Robert