From 695ee5c0b87365857925ecb53a45b97ba4582974 Mon Sep 17 00:00:00 2001 From: "graehl@gmail.com" Date: Sun, 15 Aug 2010 03:35:23 +0000 Subject: warning git-svn-id: https://ws10smt.googlecode.com/svn/trunk@551 ec762483-ff6d-05da-a07a-a48fb63a330f --- utils/logval.h | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'utils/logval.h') diff --git a/utils/logval.h b/utils/logval.h index 37f14ae5..b337cf0e 100644 --- a/utils/logval.h +++ b/utils/logval.h @@ -3,12 +3,13 @@ #define LOGVAL_CHECK_NEG false +#include #include #include #include #include -template +template class LogVal { public: LogVal() : s_(), v_(-std::numeric_limits::infinity()) {} @@ -23,6 +24,11 @@ class LogVal { static LogVal e() { return LogVal(1,false); } void logeq(const T& v) { s_ = false; v_ = v; } + std::size_t hash_impl() const { + using namespace boost; + return hash_value(v_)+s_; + } + LogVal& operator+=(const LogVal& a) { if (a.v_ == -std::numeric_limits::infinity()) return *this; if (a.s_ == s_) { @@ -98,31 +104,31 @@ class LogVal { }; // copy elision - as opposed to explicit copy of LogVal const& o1, we should be able to construct Logval r=a+(b+c) as a single result in place in r. todo: return std::move(o1) - C++0x -template +template LogVal operator+(LogVal o1, const LogVal& o2) { o1 += o2; return o1; } -template +template LogVal operator*(LogVal o1, const LogVal& o2) { o1 *= o2; return o1; } -template +template LogVal operator/(LogVal o1, const LogVal& o2) { o1 /= o2; return o1; } -template +template LogVal operator-(LogVal o1, const LogVal& o2) { o1 -= o2; return o1; } -template +template T log(const LogVal& o) { #ifdef LOGVAL_CHECK_NEG if (o.s_) return log(-1.0); @@ -130,12 +136,12 @@ T log(const LogVal& o) { return o.v_; } -template +template LogVal pow(const LogVal& b, const T& e) { return b.pow(e); } -template +template bool operator<(const LogVal& lhs, const LogVal& rhs) { if (lhs.s_ == rhs.s_) { return (lhs.v_ < rhs.v_); @@ -145,28 +151,32 @@ bool operator<(const LogVal& lhs, const LogVal& rhs) { } #if 0 -template +template bool operator<=(const LogVal& lhs, const LogVal& rhs) { return (lhs.v_ <= rhs.v_); } -template +template bool operator>(const LogVal& lhs, const LogVal& rhs) { return (lhs.v_ > rhs.v_); } -template +template bool operator>=(const LogVal& lhs, const LogVal& rhs) { return (lhs.v_ >= rhs.v_); } #endif -template + +template +std::size_t hash_value(const LogVal& x) { return x.hash_impl(); } + +template bool operator==(const LogVal& lhs, const LogVal& rhs) { return (lhs.v_ == rhs.v_) && (lhs.s_ == rhs.s_); } -template +template bool operator!=(const LogVal& lhs, const LogVal& rhs) { return !(lhs == rhs); } -- cgit v1.2.3