Basically, I’m looking to do something like this:
HANDLE hThread1 = CreateThread(...);
HANDLE hThread2 = CreateThread(...);
HANDLE hThread3 = CreateThread(...);
...
WaitForMultipleObjects( 3, {hThread1,hThread2,hThread3}, FALSE, INFINITE );
instead of this:
HANDLE hThread[3];
hThread[0] = CreateThread(...);
hThread[1] = CreateThread(...);
hThread[2] = CreateThread(...);
...
WaitForMultipleObjects( 3, hThread, FALSE, INFINITE );
The only solution I’ve found is using std::initializer_list, but obviously WaitForMultipleObjects() doesn’t doesn’t accept an std::initializer_list
Write a wrapper, then.
Now you can do:
This obviously requires C++11 compiler that supports
initializer_list.std::vector<HANDLE>might be a better type for the argument if you expect to pass an already-existing one. Or a more generic iterator/range interface, but that’s left as an exercise for the reader.