So I've been racking my brain trying to figure out a way to something. I thought I'd post it here to see if anyone has any ideas. Consider the following:
template <typename S, typename T, T S::* pMember>
bool SortByMember(const S& L, const S& R)
{
return L.*pMember < R.*pMember;
}
...
struct SomeStruct
{
int SomeMember;
};
void SomeFunction(void)
{
GetSortByMember<&SomeStruct::SomeMember>();
}
I would like the function, GetSortByMember, to return a function pointer to the corresponding instantiation of SortByMember. However, I can't think of a way to declare/define GetSortByMember in a way that doesn't require the user to also pass the class type and the member type. This:
GetSortByMember<SomeStruct, int, &SomeStruct::SomeMember>();
is overly verbose and requires me to state the member type. I'm sure there's probably a solution in the boost libraries, but I'd rather not introduce that dependency to the project I'm working on.
I doubt highly that there's a solution that'll yield the exact syntax I used in the psudocode, but perhaps something can be done with template classes or macros?
The signature of SortByMember is expected by the class that will be using the function pointer, so it can't be changed.