0

I am trying to use a vector of mutexes, but want to resize them after they are defined. However, I am getting a compilation error

error: static_assert failed due to requirement 'is_constructible<std::mutex, std::mutex &&>::value' "result type must be constructible from value type of input range" static_assert(is_constructible<_ValueType2, decltype(__first)>::value,*

Here is the code in godbolt

#include <iostream>
#include <vector>
#include <mutex>

std::vector<std::mutex> g_v(4);

int main() { 
    g_v.resize(2);
    std::cout<<"v.size() =  " << g_v.size()<<'\n';
}

https://godbolt.org/z/K85MEPM8E

Could someone explain the meaning of such an error message and how to solve the issue?

dochoex
  • 191
  • 1
  • 3
  • 11

0 Answers0