[英]What is Bool<true> in C++ - is it from boost?
我正在嘗試使用一些示例代碼,而我的編譯器將無法編譯此行:
static void exitActions(Host& h, Bool<true>) {}
編譯器為MS VS2005。 我不認識布爾-因此不確定如何更換它。 此默認參數是否等效:
static void exitActions(Host& h, bool b = true) {}
該示例來自http://accu.org/index.php/journals/252 。 該代碼只是文本中的代碼段-關於#include的內容沒有代碼段-很難解決。 Bool模板沒有定義。
我猜Bool
的定義像
template <bool B> struct Bool{};
您可以將其用於一些基本的模式匹配:
void exitActions(Bool<true>) { std::cout << "called with true\n"; }
void exitActions(Bool<false>) { std::cout << "called with false\n"; }
int main()
{
exitActions(Bool<true>()); // prints "called with true"
exitActions(Bool<false>()); // prints "called with false"
}
這當然只有在將Bool<true>
重載為Bool<false>
時才有意義。 但是,在來源http://accu.org/index.php/journals/252(Marcin猜測)中,情況就是這樣。
還有一個類似的函數調用
Tran<T,S,T>::entryActions(host_, Bool<false>());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.