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:
@@ -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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user