I’m a trying to write a wrapper around calls of the form typeid()==typeid() to prevent passing pointers / pointer types as arguments (an error easily made and difficult to detect).
So where now the call would be typeid(ClassA)==typeid(arg), I would like to replace it with safesametype(ClassA, arg) or something similar. Then, it should be checked at compile time whether none of the two arguments in fact refer to pointers.
Using functionality of the Loki library, I got almost there, but not quite. I am currently able to do the call safesametype<ClassA, SuperClassOfA>(arg) where SuperClassOfA is the type of arg.
Does anyone have ideas on how I can drop the SuperClassOfA specification? This is the current source:
#include "loki/NullType.h"
#include "loki/TypeTraits.h"
#include "loki/static_check.h"
#include <typeinfo>
class CannotCompareTypeIDofPointers{};
template<class T, class T2>
bool safesametype(const T& object){
LOKI_STATIC_CHECK(not Loki::TypeTraits<T>::isPointer, InvalidTypeIDCheck);
LOKI_STATIC_CHECK(not Loki::TypeTraits<T2>::isPointer, InvalidTypeIDCheck);
return typeid(object)==typeid(T2);
}
thanks in advance!
Broes
(PS please no solutions telling me not to use typeid)
Just swap the template parameters.
Call as: