C++ (11)이 작업을 수행 할 수 있습니다에서
하지만, 거의 패배,이 클래스의 목적 :
template<typename T, typename U, U ptr, typename... Args>
struct TypeOverload;
template<typename T, typename U, typename... Args, U(T::* ptr)(Args...)>
struct TypeOverload<T, U(T::*)(Args...), ptr, Args...>
{
using type = decltype((std::declval<T>().*ptr)(std::declval<Args>() ...)) (T::*)(Args ...);
};
다음과 같이 사용이 될 것이기 때문에 :
using bar_t = TypeOverload<Foo, decltype(&Foo::bar), &Foo::bar, int, int>::type;
static_assert(std::is_same<bar_t, void(Foo::*)(int,int)>::value, "");
demo
auto
템플릿 매개 변수가 C++ 17 인 경우, 그의 :
template<typename T, auto ptr, typename... Args>
struct TypeOverload
{
using type = decltype((std::declval<T>().*ptr)(std::declval<Args>() ...)) (T::*)(Args ...);
};
다음과 같이 당신은 그것을 사용하십시오 :
using bar_t = TypeOverload<Foo, &Foo::bar, int, int>::type;
static_assert(std::is_same<bar_t, void(Foo::*)(int,int)>::value, "");
demo
요청하신 내용이 정확하지 않지만 [this] (http://coliru.stacked-crooked.com/a/0197cd774882606c)와 같은 것이 귀하의 요구 사항을 충족합니까? – TartanLlama
@TartanLlama 아니요, 오버로드 된 메서드에 대해 작동하지 않기 때문에 –