C++ template for calling functions

Viewed 61

I have to call different functions in same manner:

VixHandle jobHandle = VIX_INVALID_HANDLE;
jobHandle = VixHost_Connect(VIX_API_VERSION, provider, host.c_str(), 0, user.c_str(), password.c_str(), 0, VIX_INVALID_HANDLE,NULL, NULL);
VixHandle result = Vix_waitJobResult(jobHandle);

I want to simplify source code, and use something like this:

template <typename FUNC, typename ... ARGS>
VixHandle VIX_CALL(FUNC fun, ARGS ... arg){
    VixHandle result = VIX_INVALID_HANDLE;
    VixHandle jobHandle = VIX_INVALID_HANDLE;
    jobHandle = fun(arg...);
    result = Vix_waitJobResult(jobHandle);
    Vix_ReleaseHandle(jobHandle);
    return result;
}

And make call look like:

VixHandle hostHandle = VIX_CALL(VixHost_Connect, VIX_API_VERSION, provider, host.c_str(), 0, user.c_str(), password.c_str(), 0, VIX_INVALID_HANDLE,NULL, NULL);

Obviously, my template does not work, and I am not sure how to fix it:

C:\Users\crashtua\Documents\CppVix\vix_api_helper.h:12: error: C2664: 'VixHandle (int,VixServiceProvider,const char *,int,const char *,const char *,VixHostOptions,VixHandle,VixEventProc (__cdecl *),void *)': cannot convert argument 10 from 'int' to 'void *'

And finnaly, how I can fix(or rewrite) my template to make it work as I expecting?

1 Answers
Related