Say I have a template class that makes multiple static_asserts:
template <class T>
class Foo
{
static_assert(!std::is_const<T>::value,"");
static_assert(!std::is_reference<T>::value,"");
static_assert(!std::is_pointer<T>::value,"");
//...<snip>...
}
Now say I have more template classes that need to make the same asserts.
Is there a way to make a static_assert
block reusable? A "static_assert function" if you will.
You can just combine required traits into one with descriptive name:
template<typename T> using
is_fancy = ::std::integral_constant
<
bool
, (not std::is_const<T>::value)
and
(not std::is_reference<T>::value)
and
(not std::is_pointer<T>::value)
>;
and use it later:
static_assert(std::is_fancy<T>::value,"");
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