[英]C++ boost variant question
我知道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
的一部分,則可以進行編譯時查詢。
有人知道嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.