summaryrefslogtreecommitdiff
path: root/impl/Complete.hpp
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@carlo-laptop>2012-10-23 14:40:38 +1100
committerCarlo Zancanaro <carlo@carlo-laptop>2012-10-23 14:40:38 +1100
commita1b28d756fe52a53d9d4da4d23853969fd529115 (patch)
treee599c1d3820ab9613af6ab129843f4a2132e5dbc /impl/Complete.hpp
parent697c1c0cd3815eee72b3eedb874fe0e044a69432 (diff)
Make the recursive solver work properly.
If you ignore the intermediate results for the strategy iteration phase then you're in the clear! I think!
Diffstat (limited to 'impl/Complete.hpp')
-rw-r--r--impl/Complete.hpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/impl/Complete.hpp b/impl/Complete.hpp
index 8c5559a..38b637e 100644
--- a/impl/Complete.hpp
+++ b/impl/Complete.hpp
@@ -7,23 +7,38 @@
template<typename T>
T infinity() { }
+template<typename T>
+T unknown(const T&) { }
template<typename T>
struct Complete {
Complete()
- : _value(0), _infinity(false) { }
+ : _value(0), _infinity(false), _unknown(false) { }
Complete(const T& value)
- : _value(value), _infinity(false) { }
+ : _value(value), _infinity(false), _unknown(false) { }
Complete(const T& value, const bool& infinity)
- : _value(value), _infinity(infinity) {
+ : _value(value), _infinity(infinity), _unknown(false) {
assert(value != 0 || infinity == false);
}
Complete(const Complete& other)
- : _value(other._value), _infinity(other._infinity) { }
+ : _value(other._value), _infinity(other._infinity), _unknown(other._unknown) { }
+ Complete(const Complete& other, bool unknown)
+ : _value(other._value), _infinity(other._infinity), _unknown(unknown) { }
+
+ Complete asUnknown() const {
+ return Complete(*this, true);
+ }
+ Complete asKnown() const {
+ return Complete(*this, false);
+ }
+ bool isUnknown() const {
+ return _unknown;
+ }
Complete& operator=(const Complete& other) {
_value = other._value;
_infinity = other._infinity;
+ _unknown = other._unknown;
return *this;
}
Complete& operator+=(const Complete& other) {
@@ -98,6 +113,7 @@ struct Complete {
private:
T _value;
bool _infinity;
+ bool _unknown;
};
template<typename Z>
@@ -110,6 +126,8 @@ std::istream& operator>>(std::istream& cin, Complete<Z>& num) {
template<typename Z>
std::ostream& operator<<(std::ostream& cout, const Complete<Z>& num) {
+ if (num._unknown)
+ cout << "(unknown)";
if (num._infinity) {
cout << (num._value > 0 ? "inf" : "-inf");
} else {
@@ -122,5 +140,9 @@ template<>
Complete<int> infinity() {
return Complete<int>(1, true);
}
+template<>
+Complete<int> unknown(const Complete<int>& x) {
+ return Complete<int>(x, true);
+}
#endif