Simplify assign in Object.h

This commit is contained in:
Giles Bathgate 2021-06-08 18:21:46 +01:00
parent 2891c22fc7
commit b575892a16
1 changed files with 5 additions and 26 deletions

View File

@ -76,26 +76,11 @@ class Object
template <class T>
bool assign(T &t) const
{
if(obj) {
#ifdef CGAL_USE_ANY_BAD_CAST
try {
t = boost::any_cast<T>(*obj);
return true;
} catch(...) {
return false;
}
#else
const T* res = boost::any_cast<T>(&(*obj));
if (res){
const T* res = boost::any_cast<T>(obj.get());
if (!res) return false;
t = *res;
return true;
}
return false;
#endif
} else {
return false;
}
}
bool
empty() const
@ -174,19 +159,13 @@ template <class T>
inline
const T * object_cast(const Object * o)
{
if(o->obj)
return boost::any_cast<T>((o->obj).get());
else
return nullptr;
}
template <class T>
inline
T object_cast(const Object & o)
{
if(!o.obj)
throw Bad_object_cast();
const T * result = boost::any_cast<T>((o.obj).get());
if (!result)
throw Bad_object_cast();