When using qBound in combination with qreal, it is important to properly cast the upper and lower bounds, e.g.:
qreal x = qBound(qreal(0.2), v, qreal(1.5));
If you forget this, i.e by using the following code:
qreal x = qBound(0.2, v, 1.5);
Your code will happily work on x86, and some other platforms, but not on Arm. This is because qreal is a double on all other platforms than Arm. On Arm, it is a float. This leads to GCC complaining about not being able to instantiate the template.
Would
qreal x = qBound(0.2, v, 1.5);
do the same?
sigh… Please mentally add a template parameter [qreal] after the qBound that was stripped off by the comment function.
Personally, I think
qreal x = qBound<qreal>(0.2, v, 1.5);
is less typing, more readable, and more explicit.thanks for the tip. explicitly specifying the template type looks nicer (and saves a bit of typing).
Or, of course, ARM could simply add the proper overloads, but why make life easier for others, right ?
And, you know, I think I remember having already seen a blogpost about this on planetkde. Twice at least, if memory serves me well.
@Lubos, it would not really be ARM doing the overloading, rather the Qt folks adding a specialized implementation of the function. However, the template only takes one type, and the automagical instantiation reads two (double and qreal, a.k.a. float).
C-Style casts, yuck :)
@Frank, those are C++ style casts. C coders write (qreal)x.
I of course didn’t expect a processor to add a Qt overload. And it’s not necessarily Qt that has to add it, it can be added pretty much anywhere where it fits. As for your ‘however’:
#ifdef ARM
inline double qBound( double low, double value, qreal high )
{
return qBound( low ,value, high );
}
etc. for all 8 combinations … Tadaaa.
And yes, the return type should be double, given it’s the larger type.
@Lubos I completely understand that one needs to add specializations, I just wanted to clarify that it is not a problem with ARM, per-se, but something that the Qt engineers would have to do.