您当前的位置: 首页 >  c++

mutourend

暂无认证

  • 4浏览

    0关注

    661博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C++ std::enable_if 代码示例

mutourend 发布时间:2019-03-04 17:23:01 ,浏览量:4

std::enable_if 在C++ 14中的定义为:

template< bool B, class T = void >
using enable_if_t = typename enable_if::type;

对应的执行内容为以下二者之一:

template
struct enable_if {}; //此时B为false
 
template
struct enable_if { typedef T type; }; //此时B为true

代码示例:

#include 
#include 
 
// foo1 overloads are enabled via the return type
template
typename std::enable_if::type 
    foo1(T t) 
{
    std::cout             
关注
打赏
1664532908
查看更多评论
0.0416s