Boost logo

Boost Users :

Subject: [Boost-users] How to detect the presence of a particular type of constructor?
From: Siegfried Kettlitz (siegfried.kettlitz_at_[hidden])
Date: 2009-04-25 03:48:51


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++?

Regards,
Siegfried Kettlitz


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net