The below code snippet does not compile. I tried different initializers but could not make it compile.
#include <array>
#include <semaphore>
int main()
{
std::array<std::binary_semaphore, 4> semaphores { {0}, {0}, {0}, {0} };
auto& [ lock1, lock2, lock3, lock4 ] { semaphores };
}
Here's the error message:
SO.cpp:8:74: error: too many initializers for ‘std::array<std::counting_semaphore<1>, 4>’
8 | std::array<std::binary_semaphore, 4> semaphores { {0}, {0}, {0}, {0} };
| ^
Isn't it possible to declare an array of binary_semaphore
s? What is the correct syntax for this?