Skip to content

Instantly share code, notes, and snippets.

@Bueddl
Created January 8, 2017 00:15
Show Gist options
  • Save Bueddl/dc0e0b8a32db36b9c7fffb141c488b41 to your computer and use it in GitHub Desktop.
Save Bueddl/dc0e0b8a32db36b9c7fffb141c488b41 to your computer and use it in GitHub Desktop.
cast class member functions to unsigned long (to obtain their addresses in code)
template<class T, class R, class... As>
constexpr unsigned long memfn_cast(R(T::*mfnp)(As...))
{
union {
unsigned long u_ul;
R(T::*u_mfnp)(As...);
} addr;
addr.u_mfnp = mfnp;
return addr.u_ul;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment