13 # ifdef __INTEL_COMPILER
14 # pragma warning(disable:2557)
16 # pragma warning(disable:4018)
27 template <
class D,
class T>
28 constexpr D
to(
const T &t) {
30 D ret =
static_cast<D
>(t);
32 T back =
static_cast<T
>(ret);
34 throw std::runtime_error(
"Numeric Conversion error.");
42 inline constexpr
float to(
const double& t) {
43 float f =
static_cast<float>(t);
47 throw std::runtime_error(
"Numeric Conversion error.");
52 constexpr D
to(
const double& d) {
55 throw std::runtime_error(
"Numeric Conversion error.");
57 throw std::runtime_error(
"Numeric Conversion error.");
60 D ret =
static_cast<D
>(d);
64 D constexpr
to(
const float &d) {
67 throw std::runtime_error(
"Numeric Conversion error.");
69 throw std::runtime_error(
"Numeric Conversion error.");
71 D ret =
static_cast<D
>(d);
75 inline constexpr
double to(
const float &d) {
76 double ret =
static_cast<double>(d);
80 # pragma warning(default:4018)
88 template <
class D,
class T>
92 D *d2 =
dynamic_cast<D *
>(t);
103 template <
class D,
class T>
105 const D *d = (
const D *)t;
106 assert(
dynamic_cast<const D *
>(t)==d);
117 constexpr
const T
safeDiv(
const T num,
const T denom) {
118 if (!denom)
return num;
debug checked shorthand for std::numeric_limits<T>::
Definition: limit.h:25
constexpr const T safeDiv(const T num, const T denom)
This function provids "safe" division operation, checks explicitly for zero.
Definition: to.h:117
constexpr D to(const T &t)
This template function serves as an alternative to static_cast<T>().
Definition: to.h:28
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:89
std::numeric_limits shorthand, with debug overflow checking