13 # ifdef __INTEL_COMPILER 14 # pragma warning(disable:2557) 16 # pragma warning(disable:4018) 24 template <
class D,
class T> D
to(
const T &t) {
27 # ifndef __INTEL_COMPILER // NEED TO FIND SOMETHING THAT WORKS FOR INTEL! 29 throw std::runtime_error(
"Underflow error in numeric conversion.");
31 throw std::runtime_error(
"Overflow error in numeric conversion.");
35 return static_cast<D>(t);
38 # pragma warning(default:4018) 48 D *d2 = dynamic_cast<D *>(t);
58 template <
class D,
class T>
const D *
check_cast(
const T *t) {
59 const D *d = (
const D *)t;
60 assert(dynamic_cast<const D *>(t)==d);
69 template <
class T>
const T
safeDiv(
const T num,
const T denom) {
70 if (!denom)
return num;
const T safeDiv(const T num, const T denom)
This function provids "safe" division operation, checks explicitly for zero.
Definition: to.h:69
D to(const T &t)
This template function serves as an alternative to static_cast<T>().
Definition: to.h:24
debug checked shorthand for std::numeric_limits<T>::
Definition: limit.h:25
D * check_cast(T *t)
This template function serves as a fast alternative to dynamic_cast, when you know the base offset is...
Definition: to.h:45
std::numeric_limits shorthand, with debug overflow checking