summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-03-20 23:22:04 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-03-20 23:22:04 +0000
commit3f2822035b3f1c67e0d6ce410bf43e84b0846037 (patch)
tree99200c7d6c6c617afbf7724768bbd5f1098cede8 /lib
parentLazy initialisation of SelectionPtr in persistValue (diff)
downloadilt-3f2822035b3f1c67e0d6ce410bf43e84b0846037.tar.bz2
ilt-3f2822035b3f1c67e0d6ce410bf43e84b0846037.tar.xz
ilt-3f2822035b3f1c67e0d6ce410bf43e84b0846037.zip
Add persistence support for std::optional<>s
Diffstat (limited to 'lib')
-rw-r--r--lib/persistence.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/persistence.h b/lib/persistence.h
index d38d4b1..cc2e4e5 100644
--- a/lib/persistence.h
+++ b/lib/persistence.h
@@ -6,6 +6,7 @@
#include <iosfwd>
#include <map>
#include <memory>
+#include <optional>
#include <span>
#include <special_members.hpp>
#include <sstream>
@@ -147,6 +148,10 @@ namespace Persistence {
}
};
+ template<typename T> struct SelectionT<std::optional<T>> : public SelectionT<T> {
+ explicit SelectionT(std::optional<T> & value) : SelectionT<T> {value.emplace()} { }
+ };
+
struct Persistable;
struct PersistenceStore {
using SelectionFactory = std::function<SelectionPtr()>;