summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2017-05-19 21:15:56 +0200
committerEugen Wissner <belka@caraus.de>2017-05-19 21:15:56 +0200
commitba0aff6737784e93fbc7c4b80b86694259d44913 (patch)
tree9f8112701f2394a33476ea16efc9217361ca8038
parenta648e2120a5f672fece538b516b8ce3644aebe3d (diff)
downloadtanya-ba0aff6737784e93fbc7c4b80b86694259d44913.tar.gz
Add tanya.typecons.Pair
-rw-r--r--source/tanya/typecons.d41
1 files changed, 41 insertions, 0 deletions
diff --git a/source/tanya/typecons.d b/source/tanya/typecons.d
new file mode 100644
index 0000000..cf09d52
--- /dev/null
+++ b/source/tanya/typecons.d
@@ -0,0 +1,41 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * Type constructors.
+ *
+ * Copyright: Eugene Wissner 2017.
+ * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
+ * Mozilla Public License, v. 2.0).
+ * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
+ */
+module tanya.typecons;
+
+import std.meta;
+
+/**
+ * $(D_PSYMBOL Pair) can store two heterogeneous objects. The objects can be
+ * accessed than by the index. The objects can by accessed by index as
+ * $(D_INLINECODE obj[0]) and $(D_INLINECODE obj[1]).
+ */
+template Pair(Field1, Field2)
+{
+ /// Field types.
+ alias Types = AliasSeq!(Field1, Field2);
+
+ struct Pair
+ {
+ /// Represents the values of the $(D_PSYMBOL Pair) as a list of values.
+ Types expand;
+
+ alias expand this;
+ }
+}
+
+///
+unittest
+{
+ static assert(is(Pair!(int, int)));
+ static assert(!is(Pair!(int, 5)));
+}