For the following code:
#include <iostream>
#include <vector>
template <class T>
inline auto foo(const T* A)
{
return A[0];
}
template <class T>
struct impl
{
template <typename F>
static auto bar(const T& A, F func)
{
return func(&A[0]);
}
};
int main()
{
std::vector<size_t> A = {2, 3, 4};
std::cout << impl<decltype(A)>::bar(A, &foo) << std::endl;
return 0;
}
I get (with C++14 using clang on macOS) that
main.cpp:23:18: error: no matching function for call to 'bar'
std::cout << impl<decltype(A)>::bar(A, &foo) << std::endl;
^~~~~~~~~~~~~~~~~~~~~~
main.cpp:14:17: note: candidate template ignored: couldn't infer template argument 'F'
static auto bar(const T& A, F func)
^
1 error generated.
My question is: Why? How can I fix it?