summaryrefslogtreecommitdiff
path: root/common/external
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2020-07-31 12:20:11 -0700
committerJacob Palecki <[email protected]>2020-07-31 12:20:11 -0700
commit6537db04f7e717eda2f21e007cdba7e13b7f559e (patch)
treeefb65bf3f305f376ea75f4f687b08bf8998c020f /common/external
parentAdd class for storing settings from file (diff)
parentMerge pull request #6 from a1xd/st-refactor (diff)
downloadrawaccel-6537db04f7e717eda2f21e007cdba7e13b7f559e.tar.xz
rawaccel-6537db04f7e717eda2f21e007cdba7e13b7f559e.zip
Show no settings for off, remove unused class for PR
Diffstat (limited to 'common/external')
-rw-r--r--common/external/nillable.h30
-rw-r--r--common/external/tagged-union-single.h2
2 files changed, 31 insertions, 1 deletions
diff --git a/common/external/nillable.h b/common/external/nillable.h
new file mode 100644
index 0000000..40cf01c
--- /dev/null
+++ b/common/external/nillable.h
@@ -0,0 +1,30 @@
+inline constexpr struct nil_t {} nil;
+
+// Requirements: T is default-constructible and trivially-destructible
+template<typename T>
+struct nillable {
+ bool has_value = false;
+ T value;
+
+ nillable() = default;
+
+ nillable(nil_t) : nillable() {}
+ nillable(const T& v) : has_value(true), value(v) {}
+
+ nillable& operator=(nil_t) {
+ has_value = false;
+ return *this;
+ }
+ nillable& operator=(const T& v) {
+ value = v;
+ has_value = true;
+ return *this;
+ }
+
+ const T* operator->() const { return &value; }
+ T* operator->() { return &value; }
+
+ explicit operator bool() const { return has_value; }
+};
+
+template<typename T> nillable(T)->nillable<T>;
diff --git a/common/external/tagged-union-single.h b/common/external/tagged-union-single.h
index bcfc1cf..3353325 100644
--- a/common/external/tagged-union-single.h
+++ b/common/external/tagged-union-single.h
@@ -137,7 +137,7 @@ struct tagged_union {
int tag = 0;
struct storage_t {
- alignas(max_align_of<First, Rest...>) char bytes[max_size_of<First, Rest...>];
+ alignas(max_align_of<First, Rest...>) char bytes[max_size_of<First, Rest...>] = "";
template <typename T>
inline constexpr T& as() {