summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/tanya/typecons.d40
1 files changed, 40 insertions, 0 deletions
diff --git a/source/tanya/typecons.d b/source/tanya/typecons.d
index 772e979..db1abfa 100644
--- a/source/tanya/typecons.d
+++ b/source/tanya/typecons.d
@@ -19,6 +19,7 @@ module tanya.typecons;
import tanya.algorithm.mutation;
import tanya.format;
+import tanya.functional;
import tanya.meta.metafunction;
import tanya.meta.trait;
@@ -35,6 +36,8 @@ import tanya.meta.trait;
*
* Params:
* Specs = Field types and names.
+ *
+ * See_Also: $(D_PSYMBOL tuple).
*/
template Tuple(Specs...)
{
@@ -134,6 +137,43 @@ template Tuple(Specs...)
}
/**
+ * Creates a new $(D_PSYMBOL Tuple).
+ *
+ * Params:
+ * Names = Field names.
+ *
+ * See_Also: $(D_PSYMBOL Tuple).
+ */
+template tuple(Names...)
+{
+ /**
+ * Creates a new $(D_PSYMBOL Tuple).
+ *
+ * Params:
+ * Args = Field types.
+ * args = Field values.
+ *
+ * Returns: Newly created $(D_PSYMBOL Tuple).
+ */
+ auto tuple(Args...)(auto ref Args args)
+ if (Args.length >= Names.length && isTypeTuple!Args)
+ {
+ alias Zipped = ZipWith!(AliasSeq, Pack!Args, Pack!Names);
+ alias Nameless = Args[Names.length .. $];
+
+ return Tuple!(Zipped, Nameless)(forward!args);
+ }
+}
+
+///
+@nogc nothrow pure @safe unittest
+{
+ auto t = tuple!("one", "two")(20, 5);
+ assert(t.one == 20);
+ assert(t.two == 5);
+}
+
+/**
* $(D_PSYMBOL Option) is a type that contains an optional value.
*
* Params: