What is a Bool <true> in C ++ - is it from a boost?
I am trying to use some sample code and my compiler will not compile this line:
static void exitActions(Host& h, Bool<true>) {}
The compiler is MS VS2005. I do not recognize Bool, so I do not know how to replace it. Is this default equivalent:
static void exitActions(Host& h, bool b = true) {}
Sample is from http://accu.org/index.php/journals/252 . The code is just fragments of text - there are no fragments about what # include'd is - it's so hard to work. There is no definition for the Bool template.
+5
1 answer
I think Booldefined as
template <bool B> struct Bool{};
You can use this for some basic pattern matching:
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 ( ) .
Tran<T,S,T>::entryActions(host_, Bool<false>());
+5