型が特定のCRTP基本クラスから派生しているかどうかを判断するためis_foo
に、で使用できる関数を作成しようとしています。enable_if
以下のコードは、is_foo
関数を実装するための私の試みですが、実際には機能しません。誰かがそれを修正するために何を変更する必要があるか教えてもらえますか?
ありがとう。
#include <iostream>
#include <type_traits>
#include <functional>
using namespace std;
template <class Underlying, class Extra>
struct Foo
{
int foo() const { return static_cast<const Underlying*>(this)->foo(); }
};
template<class T>
struct Bar : Foo<Bar<T>, T>
{
int foo() const { return 42; }
};
template<class T>
struct is_foo { static const bool value = false; };
template<class Underlying, class Extra>
struct is_foo<Foo<Underlying, Extra> > { static const bool value = true; };
template<class T>
void test(const T &t)
{
cout << boolalpha << is_foo<T>::value << endl;
}
int main()
{
Bar<int> b;
test(b);
}