From 0f9cf43c751f1319ef3b24d7519e30b1bd108396 Mon Sep 17 00:00:00 2001 From: Gerd von Egidy Date: Fri, 10 Feb 2012 11:38:01 +0100 Subject: [PATCH] add ostream handling to Tribool --- src/tribool.hpp | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-) diff --git a/src/tribool.hpp b/src/tribool.hpp index a6469ae..1cb722c 100644 --- a/src/tribool.hpp +++ b/src/tribool.hpp @@ -27,6 +27,11 @@ on this file might be covered by the GNU General Public License. * overloading the comparison operators, we rolled our own class. */ +#ifndef __TRIBOOL_HPP +#define __TRIBOOL_HPP + +#include + namespace I2n { @@ -64,3 +69,25 @@ private: }; } + +namespace std +{ + +// allow Tribools to be easily printed to ostreams +template +inline std::basic_ostream& operator<<(std::basic_ostream& os, + const I2n::Tribool& x) +{ + if (x == I2n::Tribool::False) + os << '0'; + else if (x == I2n::Tribool::True) + os << '1'; + else + os << '?'; + + return os; +} + +} + +#endif -- 1.7.1