次のステートメントを簡単にする方法はありますか? (おそらく、 を使用boost::enable_if
) .
私は単純なクラス構造を持っています-Base
基本クラス、、Derived1
からDerived2
継承しBase
ます。
次のコードがあります。
template <typename Y> struct translator_between<Base, Y> {
typedef some_translator<Base, Y> type;
};
template <typename Y> struct translator_between<Derived1, Y> {
typedef some_translator<Derived1, Y> type;
};
template <typename Y> struct translator_between<Derived2, Y> {
typedef some_translator<Derived2, Y> type;
};
の 1 つのテンプレート特殊化を使用して、同じステートメントを記述したいと考えていtranslator_between
ます。
私が書きたいものの例(疑似コード):
template <typename Class, typename Y>
ONLY_INSTANTIATE_THIS_TEMPLATE_IF (Class is 'Base' or any derived from 'Base')
struct translator_between<Class, Y> {
typedef some_translator<Class, Y> type;
};
とを使用してこれを達成する方法はboost::enable_if
ありboost::is_base_of
ますか?