I have a class with a bool as a template parameter to control the behavior of the class (in my particular case it controls whether or not a cache is used for certain calculations). All methods not affected by this option are defined in the .h
file and implemented in a .tpp
file. Though, one methods implementation depends on the passed template parameter and I am unable to figure out how I can move its implementation to the seperate file as well. Currently I have something similar to this example.
MyClass.h
template<bool enableCache = false>
class MyClass
{
public:
MyClass() {}
void someMethod();
template<bool fwd = enableCache, typename std::enable_if<fwd>::type* = nullptr>
unsigned int calcSomething() {
// ask cache if calculation is necessary
return 0;
}
template<bool fwd = enableCache, typename std::enable_if<!fwd>::type* = nullptr>
unsigned int calcSomething() {
// always recalculate
return 1;
}
};
#include "MyClass.tpp"
MyClass.tpp
template<enableCache>
void MyClass<enableCache>::someMethod() {
// do something
return;
}
This setup works (unless I introduced some minor errors while simplifying my original code), but I want to move the implementation of calcSomething
to the .tpp
as well. Can somebody help me with that?
Aucun commentaire:
Enregistrer un commentaire