I am looking for a way to identify primitives types in a template class definition.
I mean, having this class :
template<class T> class A{ void doWork(){ if(T isPrimitiveType()) doSomething(); else doSomethingElse(); } private: T *t; };
Is there is any way to ‘implement’ isPrimitiveType().
UPDATE: Since C++11, use the
is_fundamentaltemplate from the standard library:In order to save the function call overhead, use structs:
As others have pointed out, you can save your time implementing that by yourself and use is_fundamental from the Boost Type Traits Library, which seems to do exactly the same.