Say I have:
struct S{
void f(int);
float g(int,int);
void h(int);
}
#define UID(w) /* how to do it? */
cout << UID(S::f);
cout << UID(S::g);
cout << UID(S::h);
I need some way of creating a unique number, string or address for each member.
This is because I'm going to be using:
#define BIND(foo) Generate<decltype(&foo), &foo>::call
u = & BIND(S::f)
v = & BIND(S::g)
w = & BIND(S::h)
i.e. BIND
generates an associated C-style function
Here is a sketch of the generator:
template< typename F f >
struct Generate {}
template < typename R, typename ...Arg, R(S::*target)(Arg...) >
struct Generate< R(S::*)(Arg...),target >
{
static R call( PyObject* self, Arg... carg)
{
cout << ??? // the name, e.g. 'S::b'
I need this function to cout
the name of the S::foo
that generated it.
So the second half of the question is: how can I recover the same UID from inside call
?
The reason I'm trying to create UIDs is so that I can make a:
static std::map<void*, std::string> names_map;
Then I can modify my:
#define BIND(foo) Generate<decltype(&foo), &foo>::call; \
names_map[ UID(foo) ] = std::string(#foo);
static R call( PyObject* self, Arg... carg)
{
cout << names_map[ UID( R(S::*target)(Arg...) ) ];
But how to actually do this?
I've put together a testcase on coliru -- can anyone make it work?