Is there an elegant way to perform a conditional static_assert in c++11
For example:
template <class T> class MyClass { COMPILE_TIME_IF( IsTypeBuiltin<T>::value) static_assert(std::is_floating_point<T>::value, "must be floating pt"); }; Simple boolean logic within static_assert() should do it:
static_assert( (!std::is_fundamental<T>::value) || std::is_floating_point<T>::value, "must be floating pt" ); I.e. T is either not fundamental or it's floating point. In other words: If T is fundamental it must also be floating point.
std::is_integral<T>andstd::is_floating_point<T>are exclusive. What is it that you want to achieve?Tis integral, it can't be floating point.