I know it's impossible to have a single template template parameter that would accept any template.
But I thought it was possible with enough overloads:
template <template <typename...> typename> void foo() {}template <template <auto ...> typename> void foo() {}// 2template <template <auto , typename...> typename> void foo() {}template <template <typename, auto ...> typename> void foo() {}// 3template <template <typename, auto , typename...> typename> void foo() {}template <template <typename, typename, auto ...> typename> void foo() {}template <template <auto , auto , typename...> typename> void foo() {}template <template <auto , typename, auto ...> typename> void foo() {}// ...// 5 (just a single function for the example)template <template <typename, typename, typename, typename, auto...> typename> void foo() {}// A test:#include <vector>#include <map>int main(){ foo<std::vector>(); foo<std::map>();}
But alas, this doesn't work. E.g. std::vector
causes ambiguity between <typename...>
and <typename, typename, auto...>
.
Getting rid of ...
parameter packs doesn't help, now std::vector
is an ambiguity between <typename>
and <typename, typename>
(because its second parameter has a default argument).
Replacing every pack X...
with X, X...
(except on first two overloads) also doesn't help. It works with std::vector
and std::map
, but if I try passing template <int, typename...> struct A {}
, it gets matched against the <auto, typename, typename...>
overload, because that overload is then unable to pass just one template argument to A
.
Is there a solution?