为什么 std::mutex 是标准布局 class?
Why is std::mutex a standard-layout class?
[...] It is a standard-layout class ([class.prop]).
这个要求的原因是什么?
与关联的 C 接口的互操作性。来自 N2320(标准 C++ 的多线程库):
The C level interface has been removed from this proposal with the
following rationale:
- As long as we specify that the key types in this proposal are standard-layout types (which we have done), WG14 is still free to
standardize a C interface which interoperates with this C++ interface.
- WG14 is in a better position to solve the cancellation interoperability problem than WG21 is. [...]
- WG14 asked WG21 to take the lead on this issue. We feel we can best take lead by specifying only a C++ interface which has the minimum
hooks in it to support a future C interoperating interface (i.e.
types are standard-layout types). We feel we should stop short of
actually specifying that C interface in the C++ standard. WG14 can do
a better job with the C interface and a future C++ standard can then
import it by reference.
[...] It is a standard-layout class ([class.prop]).
这个要求的原因是什么?
与关联的 C 接口的互操作性。来自 N2320(标准 C++ 的多线程库):
The C level interface has been removed from this proposal with the following rationale:
- As long as we specify that the key types in this proposal are standard-layout types (which we have done), WG14 is still free to standardize a C interface which interoperates with this C++ interface.
- WG14 is in a better position to solve the cancellation interoperability problem than WG21 is. [...]
- WG14 asked WG21 to take the lead on this issue. We feel we can best take lead by specifying only a C++ interface which has the minimum hooks in it to support a future C interoperating interface (i.e. types are standard-layout types). We feel we should stop short of actually specifying that C interface in the C++ standard. WG14 can do a better job with the C interface and a future C++ standard can then import it by reference.