Re: [Boost-users] [review][constrained_value] Review of Constrained Value Library begins today

Hi Jesse, From: "Jesse Perla"
4. If it is true in general, then this statement: http://student.agh.edu.pl/~kawulak/constrained_value/constrained_value/ rationale.html#constrained_value.rationale.no_floats makes this library practically useless.
This is the problem of limited usefulness of built-in floating point arithmetic rather than of this library. If you need constrained floats, use a library for reliable, repeatable floating-point computations.
typedef bounded<double> interest_rate; interest_rate r1, r2; change_bounds(r1, .8, .99);
Now the interest rate bounds on r2 don't exist, right? This is a big problem for me... It would mean that the bounds information is not kept on the type, but on the instantiation...
Sorry, but this makes no sense to me in the context of constrained values. If the current bounds are [0, 1] and you have r1 == .5 and r2 == .9, then what changing the bounds for the whole type to [.8, .99] would mean for r1? How the type is supposed to know that there is an instance that is not valid according to the new bounds? The type should keep handles to all its instances? Or the bounds should change anyway, leaving the instance in invalid state? So what would be the point of bounds checking, if you can't guarantee that once you assign a valid value then the object will remain valid?
6) Is there any way to get the library to compile: std::max(2, i) instead of using i.value() as mentioned in the tutorial for a constrained i?
No. These are just the rules for template functions. Implicit conversions are not taken into consideration in such case, so both the arguments have to be of identical type.
This really is essential to make the library equivalent to normal operations, but with extra type information. Again, I am willing to forgo ease of use on the bounds checking for this... What I really want is the instantiation to behave EXACTLY the same as an underlying type. So overloading the ++, +, etc. are useful, but I would go further to say that perhaps everything could be done by just going back to the underlying type...
What you ask for is not possible in C++. You cannot have one type and use it exactly the same way as other type. I'll give you some examples (having constrained<string> cs): const char * s = cs.c_str(); // not possible Type constrained<string> can't have members that string has. char c = cs[0]; // not possible Type constrained<string> can't have operators that string has. How would you define such operator for constrained class template? How would you know what should be its return type in general case (without decltype available, of course)? Best regards, Robert
participants (1)
-
Robert Kawulak