If you are looking for a more general and human-readable construct, you can create something like this:
template <typename T, int TSize>
struct AnyOfThis {
template <typename TFirst, typename... TOthers>
explicit AnyOfThis(TFirst&& first, TOthers&&... others)
: values({ std::forward<TFirst>(first), std::forward<TOthers>(others)... }) {}
std::array<T, TSize> values;
};
template <typename TFirst, typename... TOthers>
auto anyOf(TFirst&& first, TOthers&&... others) {
constexpr std::size_t size = 1 + sizeof...(others);
return AnyOfThis<typename std::decay<TFirst>::type, size>(std::forward<TFirst>(first),
std::forward<TOthers>(others)...);
}
template <typename T, int TSize>
bool operator==(const T value, const AnyOfThis<typename std::decay<T>::type, TSize>& anyOfThis) {
return std::find(anyOfThis.values.begin(), anyOfThis.values.end(), value) != anyOfThis.values.end();
}
Basically, it creates a static array from a variadic function. Then there is another function which serves as a comparator, which takes the value you want to compare and looks for this value in the array.
The use-case reads fairly well, too:
if (1 == anyOf(1, 2, 3)) {
// do stuff
}
LIVE DEMO AT COLIRU