I am trying to write a function that returns a common lambda with variable arguments, where the lambda checks that one of the arguments is equal to a specific value. Here (roughly) what I'm trying to do:
template <int Index, typename TValue>
inline auto arg_eq(const TValue& value)
{
return [value] (auto... args) -> bool {
return (std::get<Index>(std::tuple<>(args...)) == value);
};
}
I am not sure what to add to the template argument std::tuple</* ??? */>. I tried to decltype(args), decltype(args...), auto, auto...and a few other things, but I keep getting compiler errors. Is it possible?
The nonequivalent equivalent would look something like this:
template <int Index, typename TValue, typename... TArgs>
inline auto arg_eq(const TValue& value)
{
return [value] (TArgs... args) -> bool {
return (std::get<Index>(std::tuple<TArgs...>(args...)) == value);
};
}
This works fine, but the returned lambda is not common - it does not work with any parameter package.