我刚刚发现如何检查操作符<<被提供用于类型.
template<class T> T& lvalue_of_type();
template<class T> T rvalue_of_type();
template<class T>
struct is_printable
{
template<class U> static char test(char(*)[sizeof(
lvalue_of_type<std::ostream>() << rvalue_of_type<U>()
)]);
template<class U> static long test(...);
enum { value = 1 == sizeof test<T>(0) };
typedef boost::integral_constant<bool,value> type;
};
这个技巧是否知名,还是刚刚获得了编程的诺贝尔奖?
总结
以上是DEVMAX为你收集整理的c – SFINAE sizeof =检测表达式是否编译全部内容。
如果觉得DEVMAX网站内容还不错,欢迎将DEVMAX网站推荐给好友。