小编Cod*_*y W的帖子

template<class = enable_if_t<...>> 有什么作用?

我一直在阅读 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<...>做什么?

c++ stl sfinae variadic-templates c++14

8
推荐指数
1
解决办法
2494
查看次数

标签 统计

c++ ×1

c++14 ×1

sfinae ×1

stl ×1

variadic-templates ×1