您的位置:首页 > 产品设计 > UI/UE

通过模板判断Value是否为指针

2016-12-15 15:16 239 查看
有个参数,需要判断其Value是否为指针,如果是做相应的处理。

代码示例如下,后来发现is_pointer在std空间中。

#include <stdio.h>
#include<iostream>
#include<vector>
template<typename T>
struct is_pointer { static const bool value = false; };

template<typename T>
struct is_pointer<T*> { static const bool value = true; };

template<typename T>
void func(T& v) {
std::cout << "is it a pointer? " << is_pointer<T>::value << std::endl;
}
int main(int argc, char *argv[])
{
__uint128_t x = 1111UL;
printf("%llu\n", x);
func(x);
return 0;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐