diff options
author | Andres Noetzli <andres.noetzli@gmail.com> | 2021-08-17 11:18:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-17 18:18:16 +0000 |
commit | 42b8e0a4fc5b23dfce79cbadc08a8aa8542997e0 (patch) | |
tree | 080b4b48b245aa2f055033708b6788a92610ce55 /src/util/utility.h | |
parent | e8f18dd65c829c3c12158d57e1fc7d2c9dcdcfd4 (diff) |
Replace `Maybe` with `std::optional` (#7005)
Because we are now using C++17, we can get rid of Maybe and instead
use std::optional, which offers the same functionality.
Diffstat (limited to 'src/util/utility.h')
-rw-r--r-- | src/util/utility.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/util/utility.h b/src/util/utility.h index 3958ff166..9126d3e25 100644 --- a/src/util/utility.h +++ b/src/util/utility.h @@ -21,6 +21,7 @@ #include <algorithm> #include <fstream> #include <memory> +#include <optional> #include <string> namespace cvc5 { @@ -61,6 +62,31 @@ void container_to_stream(std::ostream& out, } /** + * Generates a string representation of std::optional and inserts it into a + * stream. + * + * @param out The stream + * @param m The value + * @return The stream + */ +template <class T> +std::ostream& operator<<(std::ostream& out, const std::optional<T>& m) +{ + out << "{"; + if (m) + { + out << "Just "; + out << *m; + } + else + { + out << "Nothing"; + } + out << "}"; + return out; +} + +/** * Opens a new temporary file with a given filename pattern and returns an * fstream to it. The directory that the file is created in is either TMPDIR or * /tmp/ if TMPDIR is not set. |