Skip to content

Instantly share code, notes, and snippets.

@pordyna
Last active March 19, 2025 10:42
Show Gist options
  • Select an option

  • Save pordyna/710b59377b07317696ce3b39003c5f26 to your computer and use it in GitHub Desktop.

Select an option

Save pordyna/710b59377b07317696ce3b39003c5f26 to your computer and use it in GitHub Desktop.
Code snippet showing how to define a transform operation on a std tuple
template <typename T_Func, typename... T_values, std::size_t... I>
inline auto applyToTupleImpl(
T_Func func,
const std::tuple<T_values...> &tuple,
std::index_sequence<I...>)
{
return std::make_tuple(func(std::get<I>(tuple))...);
}
template <typename T_Func, typename... T_values>
inline auto applyToTuple(
T_Func func,
const std::tuple<T_values...> &tuple)
{
return applyToTupleImpl(func, tuple, std::make_index_sequence<sizeof...(T_values)>{});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment