'c++ passing a pointer to a template function as template

I have this iter function that takes a pointer to value_type, a size_type, and a function pointer fun_type that is supposed to take a value_type& as parameter:

template <
    class value_type,
    class size_type,
    class fun_type
> void  iter(value_type *arr, size_type size, fun_type function)
{ while (size--) function(arr[size]); }

It works fine until we have a function that has a template, let's say for example we want to use this function:

template <
   class T
> void print(const T &value) { std::cout << value << std::endl; }

Then we get this compilation error:

main.cpp:35:1: error: no matching function for call to 'iter'
iter( tab, 5, print );
^~~~
./iter.hpp:17:8: note: candidate template ignored: couldn't infer template argument 'fun_type'
> void  iter(value_type *arr, size_type size, fun_type function)
        ^
main.cpp:36:1: error: no matching function for call to 'iter'
iter( tab2, 5, print );
^~~~
./iter.hpp:17:8: note: candidate template ignored: couldn't infer template argument 'fun_type'
> void  iter(value_type *arr, size_type size, fun_type function)

How could I make fun_type work with every function no matter the template and the return type of the function?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source