I try to make a template to only work with double and a user-defined type. The user can choose the user defined type by a typedef in a included header file.
typedef float Usertype;
I solved this by writing the following in the end of my template source files:
template class SpaceDiscretizer<Datatype::Usertype>;
template class SpaceDiscretizer<double>;
However I run into a problem when the user defines Usertype as double! I tried to follow some directions, namely this topic 1 __2
struct dummy{};
template class SpaceDiscretizer< std::conditional<std::is_same<double,Datatype::Usertype>::value, dummy, double>::type>;
//typedef typename std::enable_if<false,double>::type mytype;
//template class SpaceDiscretizer<mytype>;
template class SpaceDiscretizer<Datatype::Usertype>;
The first one doesn't work,because if SpaceDiscretizer gets initialized with anything non-complicated,except for double, it does not work. But I want to give the user a easy way to add a working alternative to double in the feature. The second (commented out) try fails, because this is not an overload and if type is non existent, mytype won't be ignored, but an error is put out instead.
Aucun commentaire:
Enregistrer un commentaire