Quantcast
Channel: SafeInt Discussions Rss Feed
Viewing all articles
Browse latest Browse all 25

New Post: SafeInt strategy for implicit cast to larger type

$
0
0
SafeInt has an operator + overload. The following overload is called in the case above. As you can see the return type of the operation is SafeInt<T, E> where T is same type as the input SafeInt. So in your case it is SafeInt<unsiged int> which cannot fit the result.
template < typename T, typename U, typename E >                                 
SafeInt< T, E > operator +( U lhs, SafeInt< T, E > rhs ) SAFEINT_CPP_THROW      
{                                                                               
    T ret( 0 );                                                                 
    AdditionHelper< T, U, AdditionMethod< T, U >::method >::template AdditionThrow< E >( (T)rhs, lhs, ret );
    return SafeInt< T, E >( ret );                                              
}  

Viewing all articles
Browse latest Browse all 25

Latest Images

Trending Articles



Latest Images