static_assert库把断言的诊断时刻由运行期提前到编译期,让编译器检查可能发生的错误,能更好的增加程序的健壮性

#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);
}