let's say I have an enumeration:
typedef enum {
Val1,
Val2,
Val3,
Val4
} vals;
And a function check(vals x)
which returns a boolean indicating whether the val is in a specific subset of values in vals
.
bool check(vals x) {
switch(x) {
case Val1:
case Val3:
return true;
}
return false;
}
I want to use this function as a condition for the enable_if
(the function, as you can see, it's not a function depending on the runtime), to let the users use only those values with the class template.
class MyClass<vals v> {
}
PS: I need the template to make specializations for a method of the class, depending on the template value.
In C++14, just declare the function constexpr
and keep the implementation as is.
In C+11 you need to change it to a single return statement:
constexpr bool check(vals x) {
return x == Val1 || x == Val3;
}
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