Skip to content
Snippets Groups Projects
Commit 3e1abd7c authored by Jan Travnicek's avatar Jan Travnicek
Browse files

fix primitive comparisons

parent 0f1434aa
No related branches found
No related tags found
1 merge request!95Many clang-tidy fixes
Pipeline #40787 passed with warnings
......@@ -138,7 +138,7 @@ struct compare < unsigned char > {
* \return negative value of left < right, positive value if left > right, zero if left == right
*/
int operator ( ) ( unsigned char first, unsigned char second ) const {
return first - second;
return static_cast < int > ( second < first ) - static_cast < int > ( first < second );
}
};
 
......@@ -159,7 +159,7 @@ struct compare < signed char > {
* \return negative value of left < right, positive value if left > right, zero if left == right
*/
int operator ( ) ( signed char first, signed char second ) const {
return first - second;
return static_cast < int > ( second < first ) - static_cast < int > ( first < second );
}
};
 
......@@ -180,7 +180,7 @@ struct compare < char > {
* \return negative value of left < right, positive value if left > right, zero if left == right
*/
int operator ( ) ( char first, char second ) const {
return first - second;
return static_cast < int > ( second < first ) - static_cast < int > ( first < second );
}
};
 
......@@ -201,7 +201,7 @@ struct compare < unsigned short > {
* \return negative value of left < right, positive value if left > right, zero if left == right
*/
int operator ( ) ( unsigned short first, unsigned short second ) const {
return first - second;
return static_cast < int > ( second < first ) - static_cast < int > ( first < second );
}
};
 
......@@ -222,7 +222,7 @@ struct compare < signed short > {
* \return negative value of left < right, positive value if left > right, zero if left == right
*/
int operator()(signed short first, signed short second) const {
return first - second;
return static_cast < int > ( second < first ) - static_cast < int > ( first < second );
}
};
 
......@@ -243,7 +243,7 @@ struct compare < unsigned int > {
* \return negative value of left < right, positive value if left > right, zero if left == right
*/
int operator()(unsigned int first, unsigned int second) const {
return first - second;
return static_cast < int > ( second < first ) - static_cast < int > ( first < second );
}
};
 
......@@ -264,7 +264,7 @@ struct compare < signed int > {
* \return negative value of left < right, positive value if left > right, zero if left == right
*/
int operator()(signed int first, signed int second) const {
return first - second;
return static_cast < int > ( second < first ) - static_cast < int > ( first < second );
}
};
 
......@@ -285,12 +285,7 @@ struct compare < unsigned long > {
* \return negative value of left < right, positive value if left > right, zero if left == right
*/
int operator ( ) ( unsigned long first, unsigned long second ) const {
if ( first < second )
return -1;
else if ( first > second )
return 1;
else
return 0;
return static_cast < int > ( second < first ) - static_cast < int > ( first < second );
}
};
 
......@@ -311,12 +306,7 @@ struct compare < signed long > {
* \return negative value of left < right, positive value if left > right, zero if left == right
*/
int operator ( ) ( signed long first, signed long second ) const {
if ( first < second )
return -1;
else if ( first > second )
return 1;
else
return 0;
return static_cast < int > ( second < first ) - static_cast < int > ( first < second );
}
};
 
......@@ -337,12 +327,7 @@ struct compare < unsigned long long > {
* \return negative value of left < right, positive value if left > right, zero if left == right
*/
int operator ( ) ( unsigned long long first, unsigned long long second ) const {
if ( first < second )
return -1;
else if ( first > second )
return 1;
else
return 0;
return static_cast < int > ( second < first ) - static_cast < int > ( first < second );
}
};
 
......@@ -363,12 +348,7 @@ struct compare < signed long long > {
* \return negative value of left < right, positive value if left > right, zero if left == right
*/
int operator ( ) ( signed long long first, signed long long second ) const {
if ( first < second )
return -1;
else if ( first > second )
return 1;
else
return 0;
return static_cast < int > ( second < first ) - static_cast < int > ( first < second );
}
};
 
......@@ -389,12 +369,7 @@ struct compare < float > {
* \return negative value of left < right, positive value if left > right, zero if left == right
*/
int operator ( ) ( float first, float second ) const {
if ( first < second )
return -1;
else if ( first > second )
return 1;
else
return 0;
return static_cast < int > ( second < first ) - static_cast < int > ( first < second );
}
};
 
......@@ -415,12 +390,7 @@ struct compare < double > {
* \return negative value of left < right, positive value if left > right, zero if left == right
*/
int operator ( ) ( double first, double second ) const {
if ( first < second )
return -1;
else if ( first > second )
return 1;
else
return 0;
return static_cast < int > ( second < first ) - static_cast < int > ( first < second );
}
};
 
......@@ -441,12 +411,7 @@ struct compare < long double > {
* \return negative value of left < right, positive value if left > right, zero if left == right
*/
int operator ( ) ( long double first, long double second ) const {
if ( first < second )
return -1;
else if ( first > second )
return 1;
else
return 0;
return static_cast < int > ( second < first ) - static_cast < int > ( first < second );
}
};
 
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment