| 6126 | // Modulus |
| 6127 | template < typename T, typename U, typename E > |
| 6128 | SafeInt< T, E > operator %( U lhs, SafeInt< T, E > rhs ) |
| 6129 | { |
| 6130 | // Value of return depends on sign of lhs |
| 6131 | // This one may not be safe - bounds check in constructor |
| 6132 | // if lhs is negative and rhs is unsigned, this will throw an exception. |
| 6133 | |
| 6134 | // Fast-track the simple case |
| 6135 | // same size and same sign |
| 6136 | if( sizeof(T) == sizeof(U) && |
| 6137 | (bool)IntTraits< T >::isSigned == (bool)IntTraits< U >::isSigned ) |
| 6138 | { |
| 6139 | if( rhs != 0 ) |
| 6140 | { |
| 6141 | if( IntTraits< T >::isSigned && (T)rhs == -1 ) |
| 6142 | return 0; |
| 6143 | |
| 6144 | return SafeInt< T, E >( (T)( lhs % (T)rhs ) ); |
| 6145 | } |
| 6146 | |
| 6147 | E::SafeIntOnDivZero(); |
| 6148 | } |
| 6149 | |
| 6150 | return SafeInt< T, E >( ( SafeInt< U, E >( lhs ) % (T)rhs ) ); |
| 6151 | } |
| 6152 | |
| 6153 | // Multiplication |
| 6154 | template < typename T, typename U, typename E > |
nothing calls this directly
no test coverage detected