So I was reading this thread: C++ How to store a parameter pack as a variable
The answer didn't really help me (I wasn't sure on how to implement it)
What I'm trying to create is a Thread class that has arguments, the current way I do it the arguments need to be able to be stored as members, for them to be passed onto the member function.
Here is my current Thread class: (I want All the FuncArgs to be able to be stored as members, so they can be passed to the member function in Run)
template<class _Ty, typename...FuncArgs>
class YThread
{
private:
typedef YVoid(_Ty::* YMethod)();
HANDLE _myThread_handle;
DWORD _myThread_id;
_Ty* _myObject;
YMethod _myMethod;
private:
static YVoid Run(YPointer thread_obj)
{
YThread<_Ty>* thread = (YThread<_Ty>*)thread_obj;
thread->_myObject->*thread->_myMethod();
}
YThread(const YThread<_Ty>& Other) = delete;
YThread<_Ty>& operator=(const YThread<_Ty>& other) = delete;
public: // Starters
YThread()
{}
YThread(_Ty* object, YVoid(_Ty::* method)())
{
_myObject = object;
_myMethod = method;
Start();
}
~YThread()
{
if (_myThread_handle)
CloseHandle(_myThread_handle);
}
YBool Start()
{
_myThread_handle = CreateThread(
0, 0,
(LPTHREAD_START_ROUTINE)YThread<_Ty>::Run,
this,
0, &_myThread_id);
}
YBool Start(_Ty* object, YVoid(_Ty::* method)())
{
_myObject = object;
_myMethod = method;
Start();
}
public: // Other
YVoid Kill()
{
TerminateThread(_myThread_handle, 0);
}
YVoid Join()
{
WaitForSingleObject(_myThread_handle, INFINITE);
}
YBool is_alive()
{
DWORD exitCode = 0;
if (_myThread_handle)
GetExitCodeThread(_myThread_handle, &exitCode);
if (exitCode == STILL_ACTIVE)
return true;
return false;
}
};