X
Ich danke dir vielmals hustbaer!!!
Ich überlege, ob ich es nun etwa so machen soll:
template<typename TFunction>
class MyTemplate{
public:
template<typename T>
void doSomething(const T& t){
typedef typename TFunction::function_type function_type;
TFunction::function(t.getParameter());
}
};
template <typename TReturnType, typename TParamType, TReturnType (*TFunc)(TParamType)>
struct FuncWrapper{
typedef TReturnType (*function_type)(TParamType);
static function_type function;
};
template <typename TReturnType, typename TParamType, TReturnType (*TFunc)(TParamType)>
TReturnType (*FuncWrapper<TReturnType, TParamType, TFunc>::function)(TParamType) = TFunc;
int main(int argc, char**)
{
typedef FuncWrapper<double, const MyParamA&, &fA> my_func;
MyTemplate<my_func> mt;
MyObjectA moa;
mt.doSomething(moa);
}
Gibt es sowas evtl. schon in boost o. ä. integriert?
Kann man die Infos evtl. auch aus boost::function wieder ermitteln?
Ich hab im leider bisher nichts gefunden.
EDIT: Okay... Es ist spät... Aus der Template-Definition von boost::function wird man es
natürlich nicht erhalten, da die Funktion ja Bestandteil eines spezifischen Objektes ist
EDIT2:
Alternativ ginge auch Folgendes:
template<typename T>
void doSomething(const T& t){
TFunction::func(t.getParameter());
}
};
template <typename TReturnType, typename TParamType, TReturnType (*TFunc)(TParamType)>
struct FuncWrapper{
static TReturnType func(TParamType param);
};
template <typename TReturnType, typename TParamType, TReturnType (*TFunc)(TParamType)>
TReturnType FuncWrapper<TReturnType, TParamType, TFunc>::func(TParamType param){
TFunc(param);
}
Welche der beiden Möglichkeiten würdet ihr weswegen bevorzugen?
Kann man eigentlich auch etwas statisches wie
static TReturnType operator()(TParamType param);
(so klappts leider nicht) oder ähnlich implementieren, damit man
TFunction(t.getParameter());
aufrufen kann
Gruß,
XSpille