Thursday, 5 September 2013

Declaring a function with same signature of the given template parameter's function

Declaring a function with same signature of the given template parameter's
function

I'm writing a wrapper class to be derived which hides the implementation.
How can I get the signature of the given template parameter's function?
template <class T>
struct wrapper
{
static typename std::result_of<&T::impl>::type
call(...) { // this function has the same signature of T::impl();
return T::impl(...);
}
};
struct sum : public wrapper<sum>
{
private:
friend class wrapper<func>
static int impl(int a, int b, int c) {
return a + b + c;
}
};
int main()
{
std::cout << sum::call(1,2,3) << std::endl;
}

No comments:

Post a Comment