From e9b5729311fcd5572d806f5df2e645e1845603e5 Mon Sep 17 00:00:00 2001 From: Alexei Sheplyakov Date: Wed, 15 Oct 2008 15:32:11 +0400 Subject: [PATCH] is_exactly_a: use typeid() to check the type of expression. Custom RTTI considered harmful, part 1. Custom run time type information (RTTI) system implemented in GiNaC have several serious drawbacks, such as 1. It makes writing GiNaC classes unnecessary cumbersome. 2. It wastes sizeof(void *) bytes per object, for small objects like symbol, numeric, etc. this overhead is considerable. It turns out that GiNaC's RTTI is not any faster than the standard one (at least on GNU/Linux and Solaris with GNU C++ library and compiler). So, GiNaC RTTI have no reasons to exit any more. --- ginac/basic.h | 3 ++- ginac/symbol.h | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ginac/basic.h b/ginac/basic.h index ffc508db..304adcfa 100644 --- a/ginac/basic.h +++ b/ginac/basic.h @@ -27,6 +27,7 @@ #include #include #include +#include // for typeid // CINT needs to work properly with #include @@ -306,7 +307,7 @@ inline bool is_a(const basic &obj) template inline bool is_exactly_a(const basic & obj) { - return obj.tinfo() == &T::tinfo_static; + return typeid(T) == typeid(obj); } } // namespace GiNaC diff --git a/ginac/symbol.h b/ginac/symbol.h index c174ad5f..3caa24e4 100644 --- a/ginac/symbol.h +++ b/ginac/symbol.h @@ -24,6 +24,7 @@ #define __GINAC_SYMBOL_H__ #include +#include #include "basic.h" #include "ex.h" #include "ptr.h" @@ -129,7 +130,7 @@ public: /** Specialization of is_exactly_a(obj) for realsymbol objects. */ template<> inline bool is_exactly_a(const basic & obj) { - if (obj.tinfo() != &symbol::tinfo_static) + if (!is_a(obj)) return false; unsigned domain = static_cast(obj).get_domain(); return domain==domain::real || domain==domain::positive; @@ -138,7 +139,7 @@ template<> inline bool is_exactly_a(const basic & obj) /** Specialization of is_exactly_a(obj) for possymbol objects. */ template<> inline bool is_exactly_a(const basic & obj) { - if (obj.tinfo() != &symbol::tinfo_static) + if (!is_a(obj)) return false; unsigned domain = static_cast(obj).get_domain(); return domain == domain::positive; -- 2.47.0