I know I can do this to distinguish between the name of the rvalue function and the pointer to the lvalue function:
template <typename RET_TYPE, typename...ARGs>
void takeFunction(RET_TYPE(& function)(ARGs...))
{
cout << "RValue function" << endl;
}
template <typename RET_TYPE, typename...ARGs>
void takeFunction(RET_TYPE(*& function)(ARGs...))
{
cout << "LValue function" << endl;
}
void function()
{
}
void testFn()
{
void(*f)() = function;
takeFunction(function);
takeFunction(f);
}
And I want to do the same for member functions. However, this does not seem to mean:
struct S;
void takeMemberFunction(void(S::&function)())
{
cout << "RValue member function" << endl;
}
void takeMemberFunction(void(S::*&function)())
{
cout << "LValue member function" << endl;
}
struct S
{
void memberFunction()
{
}
};
void testMemberFn()
{
void(S::*mf)() = &S::memberFunction;
takeMemberFunction(S::memberFunction);
takeMemberFunction(mf);
}
Why?
The alternative I know is to do for regular functions:
void takeFunction(void(*&& function)())
{
cout << "RValue function" << endl;
}
void takeFunction(void(*& function)())
{
cout << "LValue function" << endl;
}
void function()
{
}
void testFn()
{
void(*f)() = function;
takeFunction(&function);
takeFunction(f);
}
What translates member functions:
struct S;
void takeMemberFunction(void(S::*&&function)())
{
cout << "RValue member function" << endl;
}
void takeMemberFunction(void(S::*&function)())
{
cout << "LValue member function" << endl;
}
struct S
{
void memberFunction()
{
}
};
void testMemberFn()
{
void(S::*mf)() = &S::memberFunction;
takeMemberFunction(&S::memberFunction);
takeMemberFunction(mf);
}
But I would like to know that the discrepancy for my first example does not translate.
source
share