2003-09-18 19:58:27 +00:00
|
|
|
// Copyright (C) 2002-2003 Doug Gregor (gregod@cs.rpi.edu)
|
2002-10-03 14:16:55 +00:00
|
|
|
//
|
|
|
|
|
// Permission to copy, use, sell and distribute this software is granted
|
|
|
|
|
// provided this copyright notice appears in all copies.
|
|
|
|
|
// Permission to modify the code and to distribute modified code is granted
|
|
|
|
|
// provided this copyright notice appears in all copies, and a notice
|
|
|
|
|
// that the code was modified is included with the copyright notice.
|
|
|
|
|
//
|
|
|
|
|
// This software is provided "as is" without express or implied warranty,
|
|
|
|
|
// and with no claim as to its suitability for any purpose.
|
2003-09-18 19:58:27 +00:00
|
|
|
|
2002-10-03 14:16:55 +00:00
|
|
|
// For more information, see http://www.boost.org
|
|
|
|
|
|
|
|
|
|
#include <boost/tribool.hpp>
|
|
|
|
|
#include <cassert>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
BOOST_TRIBOOL_THIRD_STATE(maybe)
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
using namespace boost;
|
|
|
|
|
|
|
|
|
|
tribool x; // false
|
|
|
|
|
tribool y(true); // true
|
|
|
|
|
tribool z(maybe); // maybe
|
|
|
|
|
|
|
|
|
|
assert(!x);
|
|
|
|
|
assert(x == false);
|
|
|
|
|
assert(false == x);
|
|
|
|
|
assert(x != true);
|
|
|
|
|
assert(true != x);
|
2003-09-18 19:58:27 +00:00
|
|
|
assert(maybe(x == maybe));
|
|
|
|
|
assert(maybe(maybe == x));
|
|
|
|
|
assert(maybe(x != maybe));
|
|
|
|
|
assert(maybe(maybe != x));
|
2002-10-03 14:16:55 +00:00
|
|
|
assert(x == x);
|
|
|
|
|
assert(!(x != x));
|
|
|
|
|
assert(!(x && true));
|
|
|
|
|
assert(!(true && x));
|
|
|
|
|
assert(x || true);
|
|
|
|
|
assert(true || x);
|
|
|
|
|
|
|
|
|
|
assert(y);
|
|
|
|
|
assert(y == true);
|
|
|
|
|
assert(true == y);
|
|
|
|
|
assert(y != false);
|
|
|
|
|
assert(false != y);
|
2003-09-18 19:58:27 +00:00
|
|
|
assert(maybe(y == maybe));
|
|
|
|
|
assert(maybe(maybe == y));
|
|
|
|
|
assert(maybe(y != maybe));
|
|
|
|
|
assert(maybe(maybe != y));
|
2002-10-03 14:16:55 +00:00
|
|
|
assert(y == y);
|
|
|
|
|
assert(!(y != y));
|
|
|
|
|
|
2003-09-18 19:58:27 +00:00
|
|
|
assert(maybe(z || !z));
|
2002-10-03 14:16:55 +00:00
|
|
|
assert(maybe(z == true));
|
|
|
|
|
assert(maybe(true == z));
|
|
|
|
|
assert(maybe(z == false));
|
|
|
|
|
assert(maybe(false == z));
|
2003-09-18 19:58:27 +00:00
|
|
|
assert(maybe(z == maybe));
|
|
|
|
|
assert(maybe(maybe == z));
|
|
|
|
|
assert(maybe(z != maybe));
|
|
|
|
|
assert(maybe(maybe != z));
|
|
|
|
|
assert(maybe(z == z));
|
|
|
|
|
assert(maybe(z != z));
|
2002-10-03 14:16:55 +00:00
|
|
|
|
|
|
|
|
assert(!(x == y));
|
|
|
|
|
assert(x != y);
|
2003-09-18 19:58:27 +00:00
|
|
|
assert(maybe(x == z));
|
|
|
|
|
assert(maybe(x != z));
|
|
|
|
|
assert(maybe(y == z));
|
|
|
|
|
assert(maybe(y != z));
|
2002-10-03 14:16:55 +00:00
|
|
|
|
|
|
|
|
assert(!(x && y));
|
|
|
|
|
assert(x || y);
|
|
|
|
|
assert(!(x && z));
|
2003-09-18 19:58:27 +00:00
|
|
|
assert(maybe(y && z));
|
|
|
|
|
assert(maybe(z && z));
|
2002-10-03 14:16:55 +00:00
|
|
|
assert(maybe(z || z));
|
2003-09-18 19:58:27 +00:00
|
|
|
assert(maybe(x || z));
|
2002-10-03 14:16:55 +00:00
|
|
|
assert(y || z);
|
|
|
|
|
|
|
|
|
|
assert(maybe(y && maybe));
|
|
|
|
|
assert(maybe(maybe && y));
|
|
|
|
|
assert(!(x && maybe));
|
|
|
|
|
assert(!(maybe && x));
|
|
|
|
|
|
|
|
|
|
assert(maybe || y);
|
|
|
|
|
assert(y || maybe);
|
|
|
|
|
assert(maybe(x || maybe));
|
|
|
|
|
assert(maybe(maybe || x));
|
|
|
|
|
|
2003-09-18 19:58:27 +00:00
|
|
|
// Test the if (z) ... else (!z) ... else ... idiom
|
2002-10-03 14:16:55 +00:00
|
|
|
if (z) {
|
|
|
|
|
assert(false);
|
|
|
|
|
}
|
|
|
|
|
else if (!z) {
|
|
|
|
|
assert(false);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
assert(true);
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-18 19:58:27 +00:00
|
|
|
z = true;
|
|
|
|
|
if (z) {
|
|
|
|
|
assert(true);
|
|
|
|
|
}
|
|
|
|
|
else if (!z) {
|
|
|
|
|
assert(false);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
assert(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
z = false;
|
|
|
|
|
if (z) {
|
|
|
|
|
assert(false);
|
|
|
|
|
}
|
|
|
|
|
else if (!z) {
|
|
|
|
|
assert(true);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
assert(false);
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-03 14:16:55 +00:00
|
|
|
std::cout << "no errors detected\n";
|
|
|
|
|
return 0;
|
|
|
|
|
}
|