boost tribool

boost::logic::tribool is similar to bool. However, while bool can distinguish two states, boost::logic::tribool handles three.

#include <boost/logic/tribool.hpp>
#include <boost/logic/tribool_io.hpp>
#include <iostream>usingnamespace boost::logic;int main() {
  std::cout.setf(std::ios::boolalpha);
  tribool b1 = true;
  std::cout << (b1 || indeterminate) << std::endl;
  std::cout << (b1 && indeterminate) << std::endl;
  tribool b2 = false;
  std::cout << (b2 || indeterminate) << std::endl;
  std::cout << (b2 && indeterminate) << std::endl;
  tribool b3

 




= indeterminate;
  std::cout << (b3 || b3) << std::endl;
  std::cout << (b3 && b3) << std::endl;

  return 0;
}

The output is:

true

indeterminate

indeterminate

false

indeterminate

indeterminate

You can use logical operators with variables of type boost::logic::tribool, just as you can with variables of type bool. In fact, this is only way to process variables of type boost::logic::tribool because the class dosen't provide any member functions.

Guess you like

Origin www.cnblogs.com/sssblog/p/11122721.html