From 31d4f30a4965a0806317909bd84beabbd7bc327c Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 21 Sep 2018 06:23:59 +0200 Subject: [PATCH] functional.forward: Fix template visibility bug Because of the private template forwardOne, forward couldn't be used in other modules. forwardOne cannot be a local template either since it accepts an alias as its template parameter. --- source/tanya/functional.d | 43 +++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/source/tanya/functional.d b/source/tanya/functional.d index 3b5adf5..f628a51 100644 --- a/source/tanya/functional.d +++ b/source/tanya/functional.d @@ -17,21 +17,6 @@ module tanya.functional; import tanya.algorithm.mutation; import tanya.meta.metafunction; -private template forwardOne(alias arg) -{ - static if (__traits(isRef, arg) || __traits(isOut, arg)) - { - alias forwardOne = arg; - } - else - { - @property auto forwardOne() - { - return move(arg); - } - } -} - /** * Forwards its argument list preserving $(D_KEYWORD ref) and $(D_KEYWORD out) * storage classes. @@ -47,13 +32,35 @@ private template forwardOne(alias arg) */ template forward(args...) { - static if (args.length == 1) + static if (args.length == 0) { - alias forward = forwardOne!(args[0]); + alias forward = AliasSeq!(); + } + else static if (__traits(isRef, args[0]) || __traits(isOut, args[0])) + { + static if (args.length == 1) + { + alias forward = args[0]; + } + else + { + alias forward = AliasSeq!(args[0], forward!(args[1 .. $])); + } } else { - alias forward = Map!(forwardOne, args); + @property auto forwardOne() + { + return move(args[0]); + } + static if (args.length == 1) + { + alias forward = forwardOne; + } + else + { + alias forward = AliasSeq!(forwardOne, forward!(args[1 .. $])); + } } }