I want to do something like this in a well-defined manner:
struct S
{
static some_integral_type f() noexcept
{
return some_cast<...>(&f);
}
};
The integer can be signed or unsigned. The result should be the same as the casts of object pointers to uintptr_t
or intptr_t
produce. AFAIK casts to those are not guaranteed to be possible for function pointers. Even casts to uintmax_t
and intmax_t
might not work for all I know.
I need this so I can produce a unique "handle" from a function pointer, that I can then use in a switch
statement.