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

有个参数,需要判断其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
", x);
    func(x);
    return 0;
}

  

原文地址:https://www.cnblogs.com/westfly/p/6183381.html