派生が絡むとちょっと面倒くさかった。結果として以下の様な感じに。
template <typename T>
struct has_xxx
{
private:
typedef char yes_t;
typedef double no_t;
template <typename F, F> struct Sfinae;
template <typename U, void (U::*P)() const>
struct Sfinae<void (U::*)() const, P> {};
template <typename U> static yes_t check(Sfinae<decltype(&U::xxx), &U::xxx>*);
template <typename U> static no_t check(...);
public:
static bool const value = sizeof(yes_t) == sizeof(check<T>(0));
};
Sfinaeの特殊化でシグニチャを調整すればOK。この実装ならxxxが親クラス側で実装されていても正しく判定できる。
0 件のコメント:
コメントを投稿