diff options
Diffstat (limited to 'Gem/develop/include/Gem/Utils/any.h')
-rw-r--r-- | Gem/develop/include/Gem/Utils/any.h | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Gem/develop/include/Gem/Utils/any.h b/Gem/develop/include/Gem/Utils/any.h index 0861e19..435f3a3 100644 --- a/Gem/develop/include/Gem/Utils/any.h +++ b/Gem/develop/include/Gem/Utils/any.h @@ -27,7 +27,9 @@ #include <algorithm> #include <string> -//#define GEM_ANY_TYPEID_HACK +#include "is_pointer.h" + +//#define GEM_ANY_TYPEID_HACK 1 namespace gem { @@ -293,6 +295,11 @@ struct GEM_EXTERN any { { return (get_type() == typeid(T)); } + template<typename T> + bool compatible(T&x) const + { + return compatible<T>(); + } // implicit casting is disabled by default @@ -329,11 +336,10 @@ struct GEM_EXTERN any { }; // boost::any-like casting - template<typename T> -T* any_cast(any* this_) +T* any_cast(any* this_, bool force) { - if (this_->get_type() != typeid(T)) { + if (!force && !this_->compatible<T>()) { throw bad_any_cast(this_->get_type(), typeid(T)); } if (sizeof(T) <= sizeof(void*)) { @@ -346,13 +352,13 @@ T* any_cast(any* this_) template<typename T> T const* any_cast(any const* this_) { - return any_cast<T>(const_cast<any*>(this_)); + return any_cast<T>(const_cast<any*>(this_), false); } template<typename T> -T const& any_cast(any const& this_) +T const& any_cast(any const& this_, bool force_pointers=false) { - return *any_cast<T>(const_cast<any*>(&this_)); + return *any_cast<T>(const_cast<any*>(&this_), force_pointers && is_pointer<T>()); } #ifdef GEM_INTERNAL // Note: The "unsafe" versions of any_cast are not part of the |