I need a template class, which has different members, depending on which ctor is called. I managed to get a class, which has different members using sfinae with a base class (I did it almost like this SFINAE on member variable). Now my question is, can I achieve a single template class, which has different members, depending on which ctor of the class is called? Maybe someone can has an idea how to achieve this.
EDIT: I currently use boost::variant
, but the problem is, that the largest object in the variant is huge, and the the smallest is ust a pointer. this is a real performance problem, because most of the time the pointer will be in the variant.
EDIT II: If this would work with a ctor it would be awesome, but if not, a factory-fuction would work as well.
EDIT III (or what I am trying to achieve): I am currently making a DSL, which translates to C++. Since I am trying to make polymorphism possible, I am only passing pointers to functions. Beacause some pointers are reference counted and some pointers are raw, depending on what the user wants, there can be shared_pointers and raw pointers of the same class. Thats why I can't make two different classes, because if a function is called on a pointer, it should be the same function, otherwise I have to overload all the fnctions, which would give me 2**n functions when the function has n arguments. Thats why I am trying to create a class, which could eigther represents a raw pointer or a shared_ptr, based on what is passed to the ctor.