I'm trying to write a function that will return a generic lambda with variadic arguments, where the lambda checks that one of the arguments is equal to a specific value. Here's (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'm not sure what to put in the std::tuple</* ??? */>
template argument. I've tried decltype(args)
, decltype(args...)
, auto
, auto...
, and a few other things, but I keep getting compiler errors. Is this even possible?
The non-generic equivalent would be something like:
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 isn't generic - it doesn't work with any arbitrary parameter pack.
Try with
The full function