#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. js中substr,substring,indexOf,lastIndexOf,split 的用法

    1.substr substr(start,length)表示从start位置开始,截取length长度的字符串. var src="images/off_1.png";alert ...

  2. [leetcode] 根据String数组构造TreeNode,用于LeetCode树结构相关的测试用例

    LeetCode 跟树结构相关的题目的测试用例中大多是通过String数组来构造树.例如{2,#,3,#,4,#,5,#,6},可以构造出如下的树(将树结构逆时针选择90度显示): 6         ...

  3. Monkey工具使用详解

    上节中介绍了Monkey工具使用环境的搭建,传送门..本节我将详细介绍Monkey工具的使用. 一.Monkey测试简介 Monkey测试是Android平台自动化的一种手段,通过Monkey程序模拟 ...

  4. 第一个Struts2程序之HelloWorld

    1.Struts2 简介 Struts 2是Struts的下一代产品,是在 struts 1和WebWork的技术基础上进行了合并的全新的Struts 2框架.其全新的Struts 2的体系结构与St ...

  5. SQL 行转列和列转行2

    DECLARE @T TABLE (columnName varchar(100) NOT NULL PRIMARY KEY); INSERT INTO @T SELECT columnName fr ...

  6. JavaScript数据类型之隐式类型转换

    JavaScript的数据类型分为七种,分别为null,undefined,boolean,string,number,object,symbol ( ECMAScript 2015新增).objec ...

  7. IE弹出窗口显示URL地址栏

    工具-->Internet 选项-->安全-->自定义级别-->允许网站打开没有地址栏或状态栏的窗口-->禁止

  8. sqldeveloper

    阅读文档:e12152-08 preferences 首选项,参数 panes 窗格 tabs 标签,选项卡 pin 别针,钉住 detach,move,dock 分离,移动,停靠 find data ...

  9. requests高级用法

    会话对象 当你向同一主机发送多个请求时,session会重用底层的tcp连接,从而提升性能,同时session也会为所有请求保持 cookie. # _*_ coding: utf-8 _*_ imp ...

  10. Storm进阶

    并行度 在Storm集群中真正运行Topology的主要有三个实体:worker.executor.task,下图是可以表示他们之间的关系. 数据流模型 对于一个Spout或Bolt,都会有多个tas ...