You can only create class or function templates. There is no such thing as a variable templates, yet (there was talk about doing something like that, though). One work-around is to use a class template providing access to the array instead:
template <typename T>
struct func_ptr {
static void (*array[100])(std::vector<T>&, int, int, bool (*)(T, T);
};
template <typename T>
void (*func_ptr<T>::array[100])(std::vector<T>&, int, int, bool (*)(T, T);
This should work but isn't too scalable. Wrapping the array into a function template and returning a reference to the array will work better: This way it is easy to get just one instance of the array as static variable in function templates need to be merged between different instantiations with the same parameters. Writing out the return type of the function template is just a bit awkward:
template <typename T>
void (*(&funcPtrArray())[100])(std::vector<T>&, int, int, bool (*)(T, T))
{
static void (*array[100])(std::vector<T>&, int, int, bool (*)(T, T));
return array;
}
I was wondering if C++11 helps but it doesn't:
auto funcPtrArray() -> void (*(&)[100])(std::vector<T>&, int, int, bool (*)(T, T))
{
...
}
You would then use the function to get you the array, e.g.:
std::vector<int> vec;
funcPtrArray<int>()[12](vec, 1, 1, [](int a, int b){ return a < b; });