aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/variant-wrapper.hh
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-08-16 12:29:23 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-08-18 11:44:00 -0400
commit9121fed4b4d02c286166373fe9805773afb13694 (patch)
tree195ec159fde2c2b2e81b8270101f2c37f38e097c /src/libutil/variant-wrapper.hh
parent284c18073233b3c7e7e027d696465a0e773dc881 (diff)
Fixing #7479
Types converted: - `NixStringContextElem` - `OutputsSpec` - `ExtendedOutputsSpec` - `DerivationOutput` - `DerivationType` Existing ones mostly conforming the pattern cleaned up: - `ContentAddressMethod` - `ContentAddressWithReferences` The `DerivationGoal::derivationType` field had a bogus initialization, now caught, so I made it `std::optional`. I think #8829 can make it non-optional again because it will ensure we always have the derivation when we construct a `DerivationGoal`. See that issue (#7479) for details on the general goal. `git grep 'Raw::Raw'` indicates the two types I didn't yet convert `DerivedPath` and `BuiltPath` (and their `Single` variants) . This is because @roberth and I (can't find issue right now...) plan on reworking them somewhat, so I didn't want to churn them more just yet. Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
Diffstat (limited to 'src/libutil/variant-wrapper.hh')
-rw-r--r--src/libutil/variant-wrapper.hh30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libutil/variant-wrapper.hh b/src/libutil/variant-wrapper.hh
new file mode 100644
index 000000000..cedcb999c
--- /dev/null
+++ b/src/libutil/variant-wrapper.hh
@@ -0,0 +1,30 @@
+#pragma once
+///@file
+
+// not used, but will be used by callers
+#include <variant>
+
+/**
+ * Force the default versions of all constructors (copy, move, copy
+ * assignment).
+ */
+#define FORCE_DEFAULT_CONSTRUCTORS(CLASS_NAME) \
+ CLASS_NAME(const CLASS_NAME &) = default; \
+ CLASS_NAME(CLASS_NAME &) = default; \
+ CLASS_NAME(CLASS_NAME &&) = default; \
+ \
+ CLASS_NAME & operator =(const CLASS_NAME &) = default; \
+ CLASS_NAME & operator =(CLASS_NAME &) = default;
+
+/**
+ * Make a wrapper constructor. All args are forwarded to the
+ * construction of the "raw" field. (Which we assume is the only one.)
+ *
+ * The moral equivalent of `using Raw::Raw;`
+ */
+#define MAKE_WRAPPER_CONSTRUCTOR(CLASS_NAME) \
+ FORCE_DEFAULT_CONSTRUCTORS(CLASS_NAME) \
+ \
+ CLASS_NAME(auto &&... arg) \
+ : raw(std::forward<decltype(arg)>(arg)...) \
+ { }