我期待着擴展描述here的功能,但對於成員函數,這種情況下的語法是什麼?C++推演成員函數參數
另外,模板定義中的(*)是否會引用函數指針,以便編譯器可以推導出模板參數?
將不勝感激!
感謝
template <class F> struct ArgType;
template <class R, class T>
struct ArgType<R(*)(T)> {
typedef T type;
};
void f(int) {}
#include <type_traits>
#include <iostream>
int main() {
// To prove
std::cout << std::is_same< ArgType<decltype(&f)>::type, int >::value << '\n';
// To use
ArgType<decltype(&f)>::type a;
}
模板定義中的'*'只是函數指針語法的一部分。 – phantom
這是一個函數指針,你需要一個成員函數指針,它是一個'R(T :: *)(參數...)' – chris
分解成員函數類型通常在一個叫做「成員函數類型)特徵「。 StackOverflow已經有幾個實現;提升也包含一個。 – dyp