2009/4/25 Siegfried Kettlitz
Hello,
what i like to do, is to detect the presence of a particular type of constructor for a class in a template. It is possible to use template overloading to detect the presence of members or member functions (like with::some_func(int) ), but since it is not possible(?) to take a pointer to a constructor ( like with::with(int) ), this method does not work to detect the present types of the templated class T.
Consider this pseudocode: struct with { with( int ); }
struct without { without( void ); }
template<typename T> T* do_construct() { a) return new T(int) if T::T(int) present; b) return new T() if T::T(int) not present; }
int main( void ) { do_construct<with>(); do_construct<without>(); }
So far i did not find anything useful in type_traits to make the do_construct-function work without modifying the classes (adding inheritance or some static member). Does anyone know another possibility to do this, or is it not possible using the current standard of c++?
It's possible, because constructor of 'with' is not explicit.
#include