I want to create proxies for member functions and operators. They should have the same type and return parameters and should be good for several classes that are set as template parameters. Even if the class does not have a specific member function or operator, I want it to compile instead of failing with an error, mainly SFINAE. If it Xhas a method f(), but Ydoes not have any method with a name f, I need to Proxy<X>have f()as well as calls X::f(), and I need Proxy<Y>to compile and instantiate without any problems.
Retrieving the return type from a known function is no longer a problem after the previous question . However, it does not work with an error if there is no such function.
I already know a few tricks of metaprogramming templates to determine if a given function exists and activate a certain function if they do, however, they all work only with the names of hard functions, and not with arbitrary ones, which strictly limits their use in this case how do i need the same design for multiple functions.
I only need to check if there is any function with the given name, if there are overloaded options, I do not need to check if there is any specific, automatic template subtraction decides that (or I hope)
My current code is as follows:
template <class T>
class Proxy
{
template <class... Args>
resultof(T::f, Args...) f (Args... x)
{
return x.f(x...);
}
template <class... Args>
typeof(T::f(std::declval<Args>()...)) f (Args... x)
{
return x.f(x...);
}
T x;
};
, T f. , .
#define resultof(f, ...) typeof(Param<__VA_ARGS__>::Func(f))
template <class... Args>
class Param
{
public:
template <class R>
static R Func (R (*) (Args...));
template <class R, class C>
static R Func (R (C::*) (Args...));
template <class R, class C>
static R Func (R (C::*) (Args...) const);
};