Tại sao mã này (giá trị fnc trong lớp M) không được giải quyết bởi các quy tắc SFINAE? Tôi gặp lỗi:Vấn đề với SFINAE
Error 1 error C2039: 'type' : is not a member of
'std::tr1::enable_if<_Test,_Type>'
Tất nhiên loại không phải là thành viên, không được xác định trong ver chung này của enable_if nhưng không phải là toàn bộ ý tưởng đằng sau việc này để bật ver này nếu bool là đúng và không khởi tạo nó nếu nó sai? Xin vui lòng ai đó giải thích điều đó cho tôi?
#include <iostream>
#include <type_traits>
using namespace std;
template <class Ex> struct Null;
template <class Ex> struct Throw;
template <template <class> class Policy> struct IsThrow;
template <> struct IsThrow<Null> {
enum {value = 0};
};
template <> struct IsThrow<Throw> {
enum {value = 1};
};
template <template <class> class Derived>
struct PolicyBase {
enum {value = IsThrow<Derived>::value};
};
template<class Ex>
struct Null : PolicyBase<Null> { };
template<class Ex>
struct Throw : PolicyBase<Throw> { } ;
template<template< class> class SomePolicy>
struct M {
//template<class T>
//struct D : SomePolicy<D<T>>
//{
//};
static const int ist = SomePolicy<int>::value;
typename std::enable_if<ist, void>::type value() const
{
cout << "Enabled";
}
typename std::enable_if<!ist, void>::type value() const
{
cout << "Disabled";
}
};
int main()
{
M<Null> m;
m.value();
}