I know full, real templates are hard to do for a lot of reasons (I've read the threads), but I had some sort of idea last night so I thought I'd present it and ask anyway.
Wouldn't it be plausible to emulate templates in such a way that you could register a templated function and then the C++ callback would receive the template types either as asIObjectType * or something that tells us what kind of primitive it is, and then we could do something with that?
Primitives aside for now, focusing on handles, it could look something like this in the AS:
ClassType @obj = getObjOf<ClassType>("by-this-name");
This function has been registered with the following AS signature:
T @getObjOf<T>(const string &inout)
In order to call this C++ function:
asIScriptObject *callbackGetObjOf(asIObjectType *templateArg, const std::string &functionArg)
{
return findObjByNameAndType(templateArg, functionArg);
}
Or perhaps if you're okay with doing some manual work if you have some C++ types registered (let's say ClassType is a registered C++ type):
void *callbackGetObjOf(asIObjectType *templateArg, const std::string &functionArg)
{
// return ...;
}
Or instead of void *, perhaps a CScriptHandle with a ref or whatever...
This function would be able to return a class derived from ClassType or whatever since the return value would automatically be casted to whatever T specified in the AS code.
This is obviously not necessarily safe since a bad cast could cause a crash, and so the responsibility of using this would lie with the programmer, but at least it would be possible to use templates to some extent unless my idea cannot possibly work in reality. Maybe by activating some compiler flag or AS engine rule in order to enable this unsafe feature.