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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With