diff options
Diffstat (limited to 'impl/Complete.hpp')
-rw-r--r-- | impl/Complete.hpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/impl/Complete.hpp b/impl/Complete.hpp index e3ec15a..336ab24 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) { @@ -102,6 +117,7 @@ struct Complete { private: T _value; bool _infinity; + bool _unknown; }; template<typename Z> @@ -114,6 +130,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 { @@ -126,5 +144,9 @@ template<> Complete<int> infinity() { return Complete<int>(1, true); } +template<> +Complete<int> unknown(const Complete<int>& x) { + return Complete<int>(x, true); +} #endif |