Tuesday, 20 August 2013

How to generate a memeber function with a deduced signature

How to generate a memeber function with a deduced signature

is it possible to produce method definition (with an exact number of
parameters and return value of known type), having:
method argument types "frozen" in a variadic arguments pack
deduced method return type
method name (passed to a macro?)
Details:
I have a simple reflection structure (partial specialisation stuff omited
for readability), which deduces member functions return type and argument
types:
template<typename RetType, typename ...ArgTypes>
struct reflect_method<RetType(HostClassType::*)(ArgTypes...)> {
using method_type = RetType;
using method_args = type_placeholder<ArgTypes...>;
using call_type = RetType(HostClassType::*)(ArgTypes...);
};
where method_type is a method return type, method_args are a method
argument types "frozen" in a helper template struct type_placeholder.
What I'm trying to do is to create a method in a generated class which
will reflect arguments and return type of another method of some other
class. The created method will provide a decoration for the reflected
method.
Pseudocode implementation:
#define RPCCLASS(class_name) class RPC##class_name : public class_name \
{ \
using SelfType = RPC##class_name; \
using ParentType = class_name;
#define RPCCLASS_END() };
#define RPCBIND(method_name) \
using method_name_##tag =
reflect_method<decltype(ParentType::method_name)>; \
method_name_##tag::method_type
method_name(method_name_##tag::method_args::at<0>::type arg0, \
method_name_##tag::method_args::at<1>::type arg1, \
/* ... */ \
/*don't know how to put correct number of arguments
here)*/) \
{
\
/* do some stuff */
\
/* ... */
\
/* invoke the reflected method */
\
return Invoke<method_name_##tag>::apply(this, method_name,
\
arg0,
\
arg1
\
/*again don't know how to put correct number of arguments
here)*/) \
}
// USAGE:
class MyOwnClass {
public:
virtual long long doFun(int a, char b, const std::string& c);
};
RPCCLASS(MyOwnClass)
RPCBIND(doFun)
RPCCLASS_END()

No comments:

Post a Comment