假設我們有以下的模板類幫助型性狀
template<typename T> class Wrap { /* ... */ };
我們不能改變Wrap
。這很重要。
讓我們從Wrap<T>
派生類。例如,
class NewInt : public Wrap<int> { /* ... */ };
class MyClass : public Wrap<myclass> { /* ... */ };
class Foo : public Wrap<Bar> { /* ... */ };
我們不能改變這些類了。以上所有課程均爲第三方。他們不是我的。
我需要以下編譯時type_traits
:
template<class T>
struct is_derived_from_Wrap {
static const bool value = /* */;
};
我需要做什麼?
assert(is_derived_from_Wrap<Int>::value == true); // Indeed I need static assert
assert(is_derived_from_Wrap<MyClass>::value == true);
assert(is_derived_from_Wrap<char>::value == false);
struct X {};
assert(is_derived_from_Wrap<X>::value == false);
但是你能改變'Int'和'MyClass'嗎? :p – kennytm 2010-01-14 08:22:59
不,謝謝你的提示。 – 2010-01-14 08:24:23
你的類型特徵不會有更好的命名:'has_Wrap_for_base'?實際上,MyClass並不是Wrap的基礎。 – 2010-01-14 08:31:57