我一直在阅读 STL 文件以学习更好的方法来格式化我的代码,并学习提高效率的技巧。我一直在阅读线程文件,但我无法弄清楚某些代码的作用。
template<class _Fn,
class... _Args,
class = enable_if_t<!is_same<decay_t<_Fn>, thread>::value>>
explicit thread(_Fn&& _Fx, _Args&&... _Ax)
{ // construct with _Fx(_Ax...)
...
}
Run Code Online (Sandbox Code Playgroud)
std::enable_if_t 是
template<bool _Test,
class _Ty = void>
using enable_if_t = typename enable_if<_Test, _Ty>::type;
template<class _Ty>
struct enable_if<true, _Ty>
{ // type is _Ty for _Test
using type = _Ty;
};
Run Code Online (Sandbox Code Playgroud)
该代码在线程和 str1common STL 中均受版权保护。
我唯一的问题是class = enable_if_t<...>做什么?