これがC++03では不可能だったことは知っていますが、これを可能にする新しいブードゥーがあることを望んでいます。下記参照:
template <class T>
struct Binder
{
template<typename FT, FT T::*PtrTomember>
void AddMatch();
};
struct TestType
{
int i;
};
int main(int argc, char** argv)
{
Binder<TestType> b;
b.AddMatch<int,&TestType::i>(); //I have to do this now
b.AddMatch<&TestType::i>(); //I'd like to be able to do this (i.e. infer field type)
}
C ++ 11でこれを行う方法はありますか?decltypeは役に立ちますか?
**更新:Vladの例を使用して、私はこのようなものが機能すると考えていました(警告:現在decltypeをサポートするコンパイラを構築しているため、コンパイルしていません)
template <class T>
struct Binder
{
template<typename MP, FT ft = decltype(MP)>
void AddMatch()
{
//static_assert to make sure MP is a member pointer of T
}
};
struct TestType
{
int i;
};
int main()
{
Binder<TestType> b;
b.AddMatch<&TestType::i>();
}
これは機能しますか?