Hello,
I want to be able to pass a pointer to a templated function as a paramter of another function, without specifying the concret template type. From what I've read, this is not possible per-se, however since my case is very specific, I belive that there is at least a work-around. This is how it should syntactically work and look like:
// template function to be passed & called
template<typename Type>
void appendAttribute(ICustomComponentAttributes::AttributeVector& vAttributes, const xml::Node& value)
{
vAttributes.emplace_back(value.GetName(), conv::FromString<Type>(value.GetValue()));
}
// this is the receiving function/method
template<typename Function, typename Return, typename... Args> // ???
Return AttributeDeclaration::CallByType(Args&&... args) const
{
switch(type)
{
case AttributeType::BOOL:
return Function<bool>(args...);
case AttributeType::FLOAT:
return Function<float>(args...);
case AttributeType::INT:
return Function<int>(args...);
case AttributeType::STRING:
return Function<std::wstring>(args...);
default:
ACL_ASSERT(false);
}
}
// in code
attribute.CallByType<appendAttribute>(vAttributes, node);
So as you can see, what I already try is to pass the function as part of a template, which of course didn't work that easily. I searched around a bit and found template template arguments, which unfortunately didn't seem to work for my example.
Is there a way to get this to work with a similar way to what I try to achieve with template arguments here? I belive that there is, since technically the template instantiations are known inside the CallByType-method. If there isn't, is there any workaround? Code complexity is of no concern, but it should be as easy to use in the actual code as possible, since this will be used in many instances. Thanks!