diff options
| author | Eugen Wissner <belka@caraus.de> | 2018-09-22 07:32:30 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2018-09-22 07:32:30 +0200 |
| commit | 03b45ae4412915edd9741812e477f809ba815a50 (patch) | |
| tree | 771f825a105b70f422f7fc0bf311b2db8c27320e | |
| parent | 31d4f30a4965a0806317909bd84beabbd7bc327c (diff) | |
| download | tanya-03b45ae4412915edd9741812e477f809ba815a50.tar.gz | |
Add typecons.tuple(), Tuple construction function
| -rw-r--r-- | source/tanya/typecons.d | 40 |
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: |
