How do I static_assert
like this? Maybe Boost supports it if not C++ or new features in C++11?
template
struct foo {};
template
Some small improvements over the other answers:
const
, volatile
, and reference types properly via std::decayconstexpr
variableI have intentionally not put the std::decay_t on the is_template_for_v because a type trait should work identically regardless of whether it is called with the _v suffix or not.
This does require C++17 for std::conjunction
, but you can either remove the variadic feature or implement your own conjunction
using c++11/14.
template class tmpl, typename T>
struct _is_template_for : public std::false_type {};
template class tmpl, class... Args>
struct _is_template_for> : public std::true_type {};
template class tmpl, typename... Ts>
using is_template_for = std::conjunction<_is_template_for>...>;
template class tmpl, typename... Ts>
constexpr bool is_template_for_v = is_template_for::value;
Usage:
static_assert(is_template_for_v>); // doesn't fire