Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Bool<true> in C++ - is it from boost?

Tags:

c++

I am trying to use some sample code and my compiler won't compile this line:

static void exitActions(Host& h, Bool<true>) {}

Compiler is MS VS2005. I don't recognise Bool - so not sure how to replace it. Is this default parameter equivalent:

static void exitActions(Host& h, bool b = true) {}

The sample is from http://accu.org/index.php/journals/252. The code is just snippets in the text - no snippet about what is #include'd - so hard to work out. There is no definition for a Bool template.

like image 359
Angus Comber Avatar asked Mar 22 '12 18:03

Angus Comber


1 Answers

I guess Bool is defined like

template <bool B> struct Bool{};

You can use this for some rudimentary 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"
}

This of course only makes sense if you overload Bool<true> with Bool<false>. But in the source http://accu.org/index.php/journals/252 (guessed by Marcin), this is the case.

There is also a similar function call

Tran<T,S,T>::entryActions(host_, Bool<false>());
like image 68
ipc Avatar answered Oct 09 '22 21:10

ipc