現在、メンバー関数の戻り値の型を決定するために特性クラスを利用する CRTP 基本クラスがあります。私は C++11 をいじっていましたが、特性クラスの必要性を排除する次のコードがありますが、デフォルトの関数テンプレート パラメーターが必要です。C++ 11 のその機能をサポートしていない Visual Studio 2012 で動作するようにこれを変更する方法はありますか?
#include <iostream>
using namespace std;
template<typename T, typename Ignore>
struct ignore { typedef T type; };
template<typename T>
struct A
{
template<class IgnoredParam = void>
auto foo() -> decltype(declval<typename ignore<T*, IgnoredParam>::type >()->foo_impl())
{
return static_cast<T*>(this)->foo_impl();
}
};
struct B : public A<B>
{
int foo_impl() { return 0;}
};
int main()
{
B b;
int i = b.foo();
cout << i << '\n';
}