1 #ifndef SYMENGINE_CASTS_H
2 #define SYMENGINE_CASTS_H
6 #include <symengine/symengine_config.h>
7 #include <symengine/symengine_assert.h>
36 template <
typename To,
typename From>
37 inline To implicit_cast(
const From &f)
60 template <
typename To,
typename From>
61 inline To down_cast(From *f)
68 implicit_cast<From *, To>(0);
71 SYMENGINE_ASSERT(f == NULL ||
dynamic_cast<To
>(f) != NULL);
73 return static_cast<To
>(f);
76 template <
typename To,
typename From>
77 inline To down_cast(From &f)
79 typedef typename remove_reference<To>::type *ToAsPointer;
85 implicit_cast<From *, ToAsPointer>(0);
88 SYMENGINE_ASSERT(
dynamic_cast<ToAsPointer
>(&f) != NULL);
90 return *
static_cast<ToAsPointer
>(&f);
93 template <
typename To,
typename From>
94 inline To numeric_cast(
103 return static_cast<To
>(f);
106 template <
typename To,
typename From>
107 inline To numeric_cast(
112 #ifdef WITH_SYMENGINE_ASSERT
115 SYMENGINE_ASSERT(f >= 0);
116 SYMENGINE_ASSERT(
static_cast<unsigned_from_type
>(f)
119 return static_cast<To
>(f);
122 template <
typename To,
typename From>
123 inline To numeric_cast(
128 #ifdef WITH_SYMENGINE_ASSERT
134 return static_cast<To
>(f);
Main namespace for SymEngine package.