// static_assert works at compile time // It's the only way to check if template parameters make sense! #include #include #include #include #include template void func(std::vector & vec) { static_assert(std::is_integral::value||std::is_floating_point::value,"func: Vector type must be int or float"); std::cout<<"ok, got number data; func call ok\n"; // Operation that follow make sense only for numerical values } int main() { std::vector v1(10); std::vector v2(10); std::vector v3(10); func(v1); // ok func(v2); // ok func(v3); // won't compile, static assertion in func fails // type traits: std::cout<<"std::is_floating_point::value = "<::value<<"\n"; std::cout<<"std::is_integral::value = "<::value<<"\n"; std::cout<<"std::is_floating_point::value = "<::value<<"\n"; }