diff options
author | Tim King <taking@cs.nyu.edu> | 2018-01-07 16:46:16 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-07 16:46:16 -0800 |
commit | 20957db27201d594a83e0e5abe77875ed4932faf (patch) | |
tree | 47c665493a2a26d9ad50d2f53de310a7ce8193e0 /src/util/maybe.h | |
parent | 8497910df4d1c254b26f09c3dc5ee6191c970b12 (diff) |
Removes RationalFromDoubleException. Replaces this with an explicit M… (#1476)
* Removes RationalFromDoubleException. Replaces this with an explicit Maybe<Rational> datatype. Makes Maybe<T> CVC4_PUBLIC. Updates the users of Rational::fromDouble(). Miscellaneous cleanup of ApproxSimplex.
Diffstat (limited to 'src/util/maybe.h')
-rw-r--r-- | src/util/maybe.h | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/util/maybe.h b/src/util/maybe.h index b2c8b9797..f27f320ae 100644 --- a/src/util/maybe.h +++ b/src/util/maybe.h @@ -22,9 +22,10 @@ ** Nothing using a value of T ** - High level of assurance that a value is not used before it is set. **/ -#include "cvc4_private.h" +#include "cvc4_public.h" -#pragma once +#ifndef __CVC4__UTIL__MAYBE_H +#define __CVC4__UTIL__MAYBE_H #include <ostream> @@ -33,12 +34,9 @@ namespace CVC4 { template <class T> -class Maybe { -private: - bool d_just; - T d_value; - -public: +class CVC4_PUBLIC Maybe +{ + public: Maybe() : d_just(false), d_value(){} Maybe(const T& val): d_just(true), d_value(val){} @@ -50,6 +48,7 @@ public: inline bool nothing() const { return !d_just; } inline bool just() const { return d_just; } + explicit operator bool() const noexcept { return just(); } void clear() { if(just()){ @@ -58,16 +57,18 @@ public: } } - T& value() { - Assert(just(), "Maybe::value() requires the maybe to be set."); - return d_value; - } - const T& constValue() const { - Assert(just(), "Maybe::constValue() requires the maybe to be set."); + const T& value() const + { + if (nothing()) + { + throw Exception("Maybe::value() requires the maybe to be set."); + } return d_value; } - operator const T&() const { return constValue(); } + private: + bool d_just; + T d_value; }; template <class T> @@ -77,10 +78,12 @@ inline std::ostream& operator<<(std::ostream& out, const Maybe<T>& m){ out << "Nothing"; }else{ out << "Just "; - out << m.constValue(); + out << m.value(); } out << "}"; return out; } }/* CVC4 namespace */ + +#endif /* __CVC4__UTIL__MAYBE_H */ |