Can I use an alias for static member function templates?

c++11

Solution

Sure, you can alias the templated function if you want to do a little work with the `using` keyword first:

template<typename T>
using testfn = bool (*)(T);

and then create a pointer to the function with:

testfn<int> fnPointer = Test::Function;

and finally call it:

std::cout << boolalpha << fnPointer(x) << std::endl;

Live Demo

If you only ever want to bind to the case where `T` is `int`, you can do this:

using testfn = bool (*)(int);
//...
testfn fnPointer = Test::Function;
std::cout << boolalpha << fnPointer(x) << std::endl;

Live Demo 2

Edit: If you want a `constexpr` function pointer like in the accepted answer of the question you linked, that's a pretty simple extension:

constexpr auto yourFunction = &Test::Function<int>;
//...
std::cout << boolalpha << yourFunction(x) << std::endl;

Live Demo 3

Problem

Using C++11, I'd like to call a static member function template without qualifying it with the scope of its enclosing class: ``` struct Test { template<typename T> static bool Function(T x) { /* ... */ } }; int x; Test::Function(x); // I don't want to write this Function(x); // I want to be able to write this instead ``` I can define another function with the same signature at global scope and forward the arguments, but I'd prefer a solution that doesn't force me to write another function. I'd also like to avoid using a macro. This question is related: (using alias for static member functions?) but doesn't seem to cover the case of function templates.

Original source

Related problems