Это работает: < /p>
Код: Выделить всё
std::mutex m;
std::optional lg(m);
< /code>
Но это не: (*) < /p>
std::mutex m;
std::optional lg;
lg = std::lock_guard(m);
< /code>
А не: (**) < /p>
std::mutex m;
std::optional lg;
lg = std::optional(m);
< /code>
Но это так: < /p>
std::string s;
std::optional os;
os = std::string(s);
< /code>
И это так: < /p>
std::string s;
std::optional os;
os = std::optional(s);
< /code>
(*) Сообщение об ошибке: < /p>
1>c:\dev\repos\tp_iu2\iu2\pretests\j00010_adaptercal.cpp(51): error C2679: binary '=': no operator found which takes a right-hand operand of type 'std::lock_guard' (or there is no acceptable conversion)
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.13.26128\include\optional(547): note: could be 'std::optional &std::optional::operator =(const std::optional &)'
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.13.26128\include\optional(320): note: or 'std::optional &std::optional::operator =(std::nullopt_t) noexcept'
1>c:\dev\repos\tp_iu2\iu2\pretests\j00010_adaptercal.cpp(51): note: while trying to match the argument list '(std::optional, std::lock_guard)'
< /code>
(**) Сообщение об ошибке: < /p>
1>c:\dev\repos\tp_iu2\iu2\pretests\j00010_adaptercal.cpp(51): error C2280: 'std::optional &std::optional::operator =(const std::optional &)': attempting to reference a deleted function
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.13.26128\include\optional(547): note: compiler has generated 'std::optional::operator =' here
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.13.26128\include\optional(547): note: 'std::optional &std::optional::operator =(const std::optional &)': function was implicitly deleted because a base class invokes a deleted or inaccessible function 'std::_Deleted_move_assign &std::_Deleted_move_assign::operator =(const std::_Deleted_move_assign &)'
Подробнее здесь: https://stackoverflow.com/questions/794 ... lock-guard