I am aware, that I can pass a class template as template argument like this:
template <template <class> class ClassTemplate>
void foo()
{
ClassTemplate<int> x;
}
int main()
{
foo<std::optional>();
}
But suppose I have a variable template:
template <class T>
constexpr bool IsBig = sizeof(T) >= sizeof(void*);
How can I pass it as a template argument? Is there a simple solution? I guess the language simply does not support it. This does not work:
template <template <class> bool VariableTemplate> // fictional C++ syntax
void foo()
{
bool b = VariableTemplate<int>;
}
int main()
{
foo<IsBig>();
}
Is there an ongoing effort in the Standardization Committee to include the above syntax (or similar) into C++ as a new feature?
I found no simple solution. I guess that's why all type traits are currently represented by a class (with ...::type
and ...::value
members) in STL. I wanted to avoid to use classes as traits. For example the straightforward way to implement IsBig
is a variable template.