
Zach Laine wrote:
The docs include some example code on "using constrained objects in debug mode only", and make reference to using unconstrained<> to allow use of the .value() member function. Why not replace the .value() member function with a free function boost::constrained_value::value(), and then write something like this?
#ifndef NDEBUG typedef bounded_int<int, 0, 100>::type my_int; #else typedef int my_int; # if IM_FINE_WITH_MACROS # define value(x) x # else inline int value(int x) { return x; } # endif #endif
Then, as long as the user always writes "value(x)", letting ADL pick up the boost::constrained_value::value() free function, the macro/inline function above will silently kick in instead if defined. This gets rid of any requirements on the quality of the optimizer in order to get performance just like an int. Did you already try this and find it problematic?
Intuitively, I'd say this is problematic - the value(int) version wouldn't get picked up by ADL. Sebastian