我知道它boost::variant
使用boost::mpl
了它背后的东西并且有一个与 mpl 兼容的 typedef types
。
假设我有一个简单的 typedef:typedef boost::variant<bool, int> Variant;
现在我有了另一个模板函数,比如说:
template <typename T> T function() {
// ...
}
我希望这个函数在两种情况下表现不同:当它的T
一部分Variant::types
和不是的时候。
显然,我必须做类似的事情
template <typename T>
typename boost::enable_if<CONDITION, T>::type function() {
// Implementation for the case T is in Variant::types
}
template <typename T>
typename boost::disable_if<CONDITION, T>::type function() {
// Implementation for the case T is ***NOT*** in Variant::types
}
我唯一不知道的是这个CONDITION
。
现在 - 我确实认为如果T
是Variant::types
.
有人知道怎么做吗?