I have searched a lot and could find many similar questions, but none of them solves this particular question AFAIK.
I want to replace a type in a tuple, by type (not by index). I tried something like this:
template <class Tuple, class ToRemove, class ToReplace>
struct ReplaceType {
using type = Tuple;
};
template <class ToRemove, class ToReplace, class...Args, class...Args2>
struct ReplaceType<std::tuple<Args..., ToRemove, Args2...>, ToRemove, ToReplace> {
using type = std::tuple<Args..., ToReplace, Args2...>;
};
This won't work but I cannot understand why it should not. It says that parameters are not deducible for Args... and Args2... but to me it should be natural to guess it from the call site:
typename ReplaceType<std::tuple<int, float, char>, float, double>>::type;
From there int should be Args1... in the template specialization and char Args2...
- Why this won't work?
- Is there any workaround?