你能专攻std::unique_lock

Can you specialize std::unique_lock

我们使用的互斥锁有一个奇怪的接口(例如奇怪的外壳)。对 std::unique_lock 进行专门化将有助于减少使用此互斥锁的认知开销。

我在标准中找不到任何专门允许专业化的内容 std::unique_lock。考虑一下,我没有想到允许 std::unique_lock 的专业化有任何缺点。有人可以确认它确实未被标准指定(因此此处引用后的未定义行为 )?

如果允许的话,有人可以指点我在标准中这样说的部分吗?

您可以针对自己的互斥类型专门化 std::unique_lock

[namespace.std]/1

A program may add a template specialization for any standard library template to namespace std only if the declaration depends on a user-defined type and the specialization meets the standard library requirements for the original template and is not explicitly prohibited.

std::unique_lock 部分没有明确禁止专业化的内容。因此一般规则适用。