aboutsummaryrefslogtreecommitdiff
path: root/libnitrokey/misc.h
diff options
context:
space:
mode:
Diffstat (limited to 'libnitrokey/misc.h')
-rw-r--r--libnitrokey/misc.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/libnitrokey/misc.h b/libnitrokey/misc.h
index 88254dd..d10c8df 100644
--- a/libnitrokey/misc.h
+++ b/libnitrokey/misc.h
@@ -29,12 +29,37 @@
#include "log.h"
#include "LibraryException.h"
#include <sstream>
+#include <stdexcept>
#include <iomanip>
namespace nitrokey {
namespace misc {
+/**
+ * Simple replacement for std::optional (C++17).
+ */
+template<typename T>
+class Option {
+public:
+ Option() : m_hasValue(false), m_value() {}
+ Option(T value) : m_hasValue(true), m_value(value) {}
+
+ bool has_value() const {
+ return m_hasValue;
+ }
+ T value() const {
+ if (!m_hasValue) {
+ throw std::logic_error("Called Option::value without value");
+ }
+ return m_value;
+ }
+
+private:
+ bool m_hasValue;
+ T m_value;
+};
+
template<typename T>
std::string toHex(T value){
using namespace std;