I'm trying to compile the following:
#include <vector> #include <array> template <typename T> void sort(T &container) {} template <typename F, typename T, typename ...Tail> void sort_containers(F sort_func, T &container, Tail &...tail) { sort_func(container); sort_containers(sort_func, tail...); } template <typename F, typename T> void sort_containers(F sort_func, T &container) { sort_func(container); } int main() { std::vector<int> x = {1,2,3}; std::vector<double> y = {1.0, 2.0, 3.0}; std::array<char, 3> z = {{'d' , 'b', 'c'}}; sort_containers(sort, x, y, z); } Which leads to the following compiler error with g++4.8:
error: no matching function for call to ‘sort_containers(<unresolved overloaded function type>, std::vector<int>&, std::vector<double>&, std::array<char, 3u>&)’ I understand that I need to specify the template parameter for sort when passing it to sort_containers, but I'm not sure how this works in the presence of a variadic template function.
sort_three_containers. That is, not too well. You need to pass not a function (template) but an object with a member function template that does the sorting, so that its instantiation happens at every recursive call tosort_containers.sort_three_containers