My enable_if
statement was getting very long so I wanted to somehow typedef. I am not sure what the best way is though.
I tried this, but it doesn't work
template<typename T>
struct isValidImageFormat
{
typedef
typename std::is_same<T, float>::value ||
typename std::is_same<T, unsigned char>::value
value;
};
The error is:
expected unqualified-id before »||« token typename std::is_same::value ||
Questions:
You want std::disjunction
(the fancy word in philosophy for "or"):
typedef std::disjunction<
std::is_same<T, float>,
std::is_same<T, unsigned char>> condition;
Then you can use condition::value
to get a true or false value. Or if you only want a value, try this:
constexpr bool condition =
std::is_same<T, float>::value ||
std::is_same<T, unsigned char>::value;
The typename
keyword is used when you want to work with types, in your example you want to work with constexpr bool
value.
template<typename T>
struct isValidImageFormat
{
constexpr static bool value =
std::is_same<T, float>::value ||
std::is_same<T, unsigned char>::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