This is overkill for such a simple operation. Doing it this way should optimize to a single add and it doesn't have any of the problems associated with breaking aliasing rules.

This commit is contained in:
Steve Checkoway
2006-11-01 11:30:41 +00:00
parent cf3a76b600
commit d571048d2b
+2 -3
View File
@@ -165,14 +165,13 @@ ConvertValueHelper<TO, FROM> ConvertValue( FROM *pValue )
template<typename T> template<typename T>
static inline void enum_add( T &val, int iAmt ) static inline void enum_add( T &val, int iAmt )
{ {
*ConvertValue<int>(&val) += iAmt; val = static_cast<T>( val + iAmt );
} }
template<typename T> template<typename T>
static inline T enum_add2( T val, int iAmt ) static inline T enum_add2( T val, int iAmt )
{ {
enum_add( val, iAmt ); return static_cast<T>( val + iAmt );
return val;
} }