I have a class template:
template<int a, int b>
class foo {
};
I only want to instantiate it when a + b == 10.
Could I make this possible using std::enable_if?
Furthermore, if I have a data member in class foo:
template<int a, int b>
class foo {
int c;
};
I only want to have c when a == 5.
How do I do that using std::enable_if?
Is this one the correct case to use std::enable_if?
I guess you can use static_assert better to enforce that constraint instead of enable_if
enable_if is primarily used to conditionally remove functions and classes from overload resolution based on type traits and to provide separate function overloads and specializations for different type traits.