So I had this function...
virtual void CallRemoteFunction( const char* pServerGameObjectId, const char* pFunctionName, OVariant arg1 = OVariant(), OVariant arg2 = OVariant(), OVariant arg3 = OVariant(), OVariant arg4 = OVariant(), OVariant arg5 = OVariant(), OVariant arg6 = OVariant(), OVariant arg7 = OVariant(), OVariant arg8 = OVariant(), OVariant arg9 = OVariant() );
I decided to rewrite the function because, frankly, i was embarrassed by it. The function is straightforward... take a variable number of arguments of unknown type and do stuff.
I am fairly new to modern c++, so I did some searching and assumed I would find some simple/elegant new way of doing this. I imagined something like...
//hypothetical code
virtual void CallRemoteFunction( const char* pServerGameObjectId, const char* pFunctionName, ... args )
{
std::vector<OVariant> argsArray;
for (auto& arg : args )
{
argsArray.push_back(arg)
}
//do other stuff
}
//end hypothetical code
But in my searches, I could not find anything close. It seams that the c++ gods used their infinite cleverness, and made possibilities that increase the complexity of a simple issue. They force the use of templates, tuples, initializer lists. They even managed to add recursion into the mix.
Ok, my rant is over. So could anybody kindly give me some ideas on how to refactor my original function into something cleaner or simpler? Note...The solution must be c++ 11 or older.
Aucun commentaire:
Enregistrer un commentaire