13# ifdef __INTEL_COMPILER
14# pragma warning(disable:2557)
16# pragma warning(disable:4018)
27template <
class D,
class T>
28constexpr 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.");
42inline constexpr float to(
const double& t) {
43 float f =
static_cast<float>(t);
47 throw std::runtime_error(
"Numeric Conversion error.");
52constexpr 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);
64D
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);
75inline constexpr double to(
const float &d) {
76 double ret =
static_cast<double>(d);
80# pragma warning(default:4018)
88template <
class D,
class T>
92 D *d2 =
dynamic_cast<D *
>(t);
103template <
class D,
class T>
105 const D *d = (
const D *)t;
106 assert(
dynamic_cast<const D *
>(t)==d);
117constexpr 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
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
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
std::numeric_limits shorthand, with debug overflow checking