CHECK MEMBER TYPE
检查类里是否存在某种类型的几种方法,以检查xxx类型为例:
方法1:
template<class T>
class has_member_type_Type
{
struct big { char a[]; };
template<class C> static big probe(typename C::xxx*); // match here if type T::Type exists
template<class C> static char probe(...);
public:
static const bool value = sizeof(probe<T>(nullptr)) > ;
};
方法2:
template<typename T, typename = typename T::xxx>
static std::true_type has_xxx_impl(int); template<typename T>
static std::false_type has_xxx_impl(...); template<typename T>
struct has_xxx : decltype(has_xxx_impl<T>())
{
};
方法3:
template<typename... Ts> struct make_void { typedef void type; };
template<typename... Ts> using void_t = typename make_void<Ts...>::type;
template<typename T, typename = void>
struct has_yyy : std::false_type
{
};
template<typename T>
struct has_yyy < T, void_t<typename T::xxx>> : std::true_type
{
};
//用宏简化
#define HAS_TYPE_MEMBER(MEMBER)\
template<typename T, typename = void>\
struct has_type_##MEMBER : std::false_type\
{\
};\
template<typename T>\
struct has_type_##MEMBER < T, void_t<typename T::MEMBER>>:\
std::true_type\
{\
};
HAS_TYPE_MEMBER(xxx)
测试代码:
struct MyStruct
{
typedef char xxx;
}; int main()
{
static_assert(has_xxx<MyStruct>::value, "no xxx");
static_assert(has_type_xxx<MyStruct>::value, "no xxx");
}
CHECK MEMBER TYPE的更多相关文章
- how to check SVG type in js
how to check SVG type in js SVGSVGElement & SVGElement svg = document.querySelector(`svg`); // & ...
- check member function
template<typename T> struct has_member_foo11 { private: template<typename U> static auto ...
- How To Check Member In Window VS With CplusPlus?
实例说明 下面这个实例代码, 快速举例了在Win32应用程序下,对于内存的泄漏检查. 其中的原理,目前本人还是不太的理解. 只是记录了使用方法. 以后,看情况,会更新的. #ifdef _WIN32 ...
- 最新版自动检测卡片类型工具软件版本(auto check card type v3.2.0)
自动检测卡片类型工具软件. 卡片放到读卡器上面自动识别卡片类型,不需老是按下按钮,好用,方便.支持自动识别NTAG213卡片,NTAG215卡片, NTAG216卡片,Ultralight芯片, Ul ...
- list_entry(ptr, type, member)——知道结构体内某一成员变量地址,求结构体地址
#define list_entry(ptr, type, member) \ ((type *)(() -> member))) 解释: 1 在0这个地址看做有一个虚拟的type类型的变量,那 ...
- 对list_entry(ptr, type, member)的理解
如何根据一个结构体成员的地址.结构体类型以及该结构体成员名获得该结构体的首地址? #define list_entry(ptr, type, member) \ ((type *)((char *)( ...
- reifiable type与raw type
下面的逻辑需要明白如下两个概念: 4.7. Reifiable Types 4.8. Raw Types 举几个是Reifiable Types的例子,如下: class A{} class B< ...
- Welcome-to-Swift-18类型转换(Type Casting)
类型转换是一种检查类实例的方式,并且哦或者也是让实例作为它的父类或者子类的一种方式. Type casting is a way to check the type of an instance, a ...
- [TypeScript] Generic Functions, class, Type Inference and Generics
Generic Fucntion: For example we have a set of data and an function: interface HasName { name: strin ...
随机推荐
- C++混合编程之idlcpp教程Python篇(3)
上一篇 C++混合编程之idlcpp教程Python篇(2) 是一个 hello world 的例子,仅仅涉及了静态函数的调用.这一篇会有新的内容. 与PythonTutorial0相似,工程Pyth ...
- 作业,备份,存储过程,sqlserver print 语句,输出字符串
declare @filename nvarchar(100) set @filename='H:/backOrder/'+ convert(varchar(50),getdate(),112)+ l ...
- 简单sql操作
----------------------------- 数据库的有关SQL语句 -------------------------1.数据库 创建 create database data_nam ...
- CentOS7 安装 mongodb
https://docs.mongodb.com/manual/tutorial/install-mongodb-enterprise-on-red-hat/
- 用命令提示符压缩文件,解压缩文件(不需要客户端安装7zip)
压缩成一个CAB包的办法: type list.txt (生成一个文件列表) makecab /f list.txt /d compressiontype=mszip /d compressionme ...
- [ACM_模拟] ZOJ 3713 [In 7-bit 特殊输出规则 7bits 16进制]
Very often, especially in programming contests, we treat a sequence of non-whitespace characters as ...
- [stm32] GPIO及最小框架
1.GPIO硬件结构图: 2.GPIO程序结构: 3.框架介绍: 这里的ASM是固定启动文件夹,startup_stm32f10x_hd.s表示当前stm32类型为高容量设备,当然还有md.s等. C ...
- 浅谈Entity Framework中的数据加载方式
如果你还没有接触过或者根本不了解什么是Entity Framework,那么请看这里http://www.entityframeworktutorial.net/EntityFramework-Arc ...
- 【转】关于Mahalanobis距离的笔记
Mahalanobis距离是用来度量一个点P和一个分布D之间的距离,它是衡量点P与分布D的均值之间存在多少个标准差的一个多维泛化版本. 如果P就位于分布D的均值处,则该距离为0:该距离随着P的偏离均值 ...
- xdebug影响php运行速度
我在本地wamp的环境下面加了xdebug用来调试,但是我发现wordpress运行速度好慢,所有程序运行变得也很慢.开始以为是数据库有问题,找了半天,发现把xdebug的扩展去掉,就正常了. 目前配 ...