#include <iostream>

struct Hello
{
int helloworld() { return 0; }
}; struct Generic {}; // SFINAE test
template <typename T>
class has_helloworld
{
typedef char yes[1];
typedef yes no[2]; template <typename C> static yes& test( typeof(&C::helloworld) );
template <typename C> static no& test(...); public:
enum { value = sizeof(test<T>(0)) == sizeof(yes) };
}; int main(int argc, char *argv[])
{
std::cout << has_helloworld<Hello>::value << std::endl;
std::cout << has_helloworld<Generic>::value << std::endl;
return 0;
}

参考资料

Is it possible to write a C++ template to check for a function's existence?

SFINAE to check for inherited member functions

Substitution failure is not an error(SFINAE)

An introduction to C++'s SFINAE concept: compile-time introspection of a class member

深入浅出SFINAE

2016-08-16: 检测函数是否存在的C++模板的更多相关文章

  1. Murano Weekly Meeting 2016.08.16

    Meeting time: 2016.August.16 1:00~2:00 Chairperson:  Kirill Zaitsev, from Mirantis Meeting summary: ...

  2. mysql查询练习题-2016.12.16

    >>>>>>>>>> 练习时间:2016.12.16 编辑时间:2016-12-20-->22:12:08 题: 涉及:多表查询.ex ...

  3. 不可或缺 Windows Native (16) - C++: 函数重载, 缺省参数, 内联函数, 函数模板

    [源码下载] 不可或缺 Windows Native (16) - C++: 函数重载, 缺省参数, 内联函数, 函数模板 作者:webabcd 介绍不可或缺 Windows Native 之 C++ ...

  4. http://tedhacker.top/2016/08/05/Spring%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95/

    http://tedhacker.top/2016/08/05/Spring%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%9 ...

  5. 【转载】webstorm11(注册,激活,破解,码,一起支持正版,最新可用)(2016.11.16更新)

    很多人都发现 http://idea.lanyus.com/ 不能激活了 很多帖子说的 http://15.idea.lanyus.com/ 之类都用不了了 最近封的厉害仅作测试 选择 License ...

  6. http://www.cnblogs.com/alipayhutu/archive/2012/08/16/2643098.html

    http://www.cnblogs.com/alipayhutu/archive/2012/08/16/2643098.html

  7. 人脸检测的harr检测函数

    眼球追踪需要对人脸进行识别,然后再对人眼进行识别,判断人眼张合度,进而判断疲劳... 解析:人脸检测的harr检测函数使用方法 代码理解: 利用训练集,检测出脸部,画出框 void CAviTestD ...

  8. php检测函数是否存在函数 function_exists

    php检测函数是否存在函数 function_exists 语法 bool function_exists ( string $function_name )检查的定义的函数的列表,同时内置(内部)和 ...

  9. 2016.8.16上午纪中初中部NOIP普及组比赛

    2016.8.16上午纪中初中部NOIP普及组比赛 链接:https://jzoj.net/junior/#contest/home/1334 这次也翻车了,感觉比之前难多了. 辛辛苦苦改完了,太难改 ...

随机推荐

  1. MySql分组函数-Group by与having理解

    注意:select 后的字段,必须要么包含在group by中,要么包含在having 后的聚合函数里. 1. GROUP BY 是分组查询, 一般 GROUP BY 是和聚合函数配合使用 group ...

  2. USACO 2015 December Contest, Gold Problem 2. Fruit Feast

    Problem 2. Fruit Feast 很简单的智商题(因为碰巧脑出来了所以简单一,一 原题: Bessie has broken into Farmer John's house again! ...

  3. JPanel

    class NewPanel extends JPanel{ public NewPanel() {} public void paintComponent(Graphics g) { int x=0 ...

  4. el表达式无法获取springmvc的model封装好的数据之解决方法

    近日碰到奇怪的问题,应该挺好解决的,可是就是卡住我两天 下面我来描述一下问题 用的是springmvc,自然需要controller,假设我现在所有的配置都是对的. controller代码 @Req ...

  5. UIWebView的使用

    iOS中UIWebView的使用详解 一.初始化与三种加载方式 UIWebView继承与UIView,因此,其初始化方法和一般的view一样,通过alloc和init进行初始化,其加载数据的方式有三种 ...

  6. Nim Game,Reverse String,Sum of Two Integers

    下面是今天写的几道题: 292. Nim Game You are playing the following Nim Game with your friend: There is a heap o ...

  7. [zz]利用碎片时间健身

    利用碎片时间健身(上) http://v.163.com/zixun/V96957QH6/VBSQ4D861.html#from=zixunplay_recommended 利用碎片时间健身(下) h ...

  8. HackerRank "Equal Stacks"

    Greedy - though simple, but fun! #include <vector> #include <iostream> using namespace s ...

  9. chmod、chown、chgrp的意思

    文件权限管理chown->change owner 改变文件所有者chown test install.log -将install.log这个文件的所有者改为test用户 chgrp->c ...

  10. <<软技能,代码之外的生存技能>>读书笔记

    管理 1. 制定大目标,再分解成小目标,定时反思自己的长期和短期的成果 2. 人都希望自己很重要, 要让下属有存在感,让他们做事有成就感 3. 奖励积极比惩罚消极更有用 4. 学会换位思考,不要用&q ...