#include<boost/static_assert.hpp>
#include<iostream>
using namespace std;
template<typename T>
T my_min(T a,T b)
{
//invalid application of ‘sizeof’ to incomplete type ‘boost::STATIC_ASSERTION_FAILURE<false>’
BOOST_STATIC_ASSERT(sizeof(T)<sizeof(int));
return a<b?a:b;
}
int main()
{
cout << my_min(1,2);
}
boost StaticAssert
原创xiangjie256 博主文章分类:boost模板元编程 ©著作权
©著作权归作者所有:来自51CTO博客作者xiangjie256的原创作品,请联系作者获取转载授权,否则将追究法律责任
static_assert库把断言的诊断时刻由运行期提前到编译期,让编译器检查可能发生的错误,能更好的增加程序的健壮性
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
boost python调用 python boost库
1.环境介绍 64位 win7 操作系统 VS2015 64位 python2.7.9 boost1.6.0 2.软件安装 VS2015与python的安装,在此不再讲述
boost python调用 c++ python boost 动态库 -
redis 列出key的value
第一章 Redis 快速入门 Redis是一个Key-Value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)和zset(有序集合)。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操
redis 列出key的value redis 存储系统 cassandra memcached