Use correct type get the maximum value.

Previously we hardcoded float. Now we use the result_type of
the binary_function without any qualifiers. With any cv or reference
qualifiers std::numeric_limits uses a default implementation which
produces nonesense (e.g. numeric_limits<const int>::max() returns 0).
This commit is contained in:
Markus Blatt 2015-05-22 20:29:48 +02:00
parent 3aa869cfa0
commit fa279d6b16

View File

@ -404,6 +404,12 @@ private:
template<typename BinaryOperator> template<typename BinaryOperator>
struct MaskToMinOperator struct MaskToMinOperator
{ {
// This is a real nice one: numeric limits has to a type without const
// or reference. Otherwise we get complete nonesense.
typedef typename std::remove_reference<
typename std::remove_const<typename BinaryOperator::result_type>::type
>::type Result;
MaskToMinOperator(BinaryOperator b) MaskToMinOperator(BinaryOperator b)
: b_(b) : b_(b)
{} {}
@ -432,11 +438,11 @@ private:
// for integral types. // for integral types.
if( std::is_integral<T>::value ) if( std::is_integral<T>::value )
{ {
return -std::numeric_limits<float>::min(); return -std::numeric_limits<Result>::min();
} }
else else
{ {
return -std::numeric_limits<float>::max(); return -std::numeric_limits<Result>::max();
} }
} }
} }
@ -458,6 +464,12 @@ private:
template<typename BinaryOperator> template<typename BinaryOperator>
struct MaskToMaxOperator struct MaskToMaxOperator
{ {
// This is a real nice one: numeric limits has to a type without const
// or reference. Otherwise we get complete nonesense.
typedef typename std::remove_cv<
typename std::remove_reference<typename BinaryOperator::result_type>::type
>::type Result;
MaskToMaxOperator(BinaryOperator b) MaskToMaxOperator(BinaryOperator b)
: b_(b) : b_(b)
{} {}