From 4452bd6b0a61edb905d1726429ca27353c273a9e Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Sun, 28 Feb 2016 14:45:47 +0100 Subject: [PATCH] Modified cipher.d to be more tidied up. --- source/cipher.d | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/source/cipher.d b/source/cipher.d index ca470b2..96a73c4 100644 --- a/source/cipher.d +++ b/source/cipher.d @@ -14,11 +14,8 @@ enum Cipher chacha20 } -mixin(cipherFunctionString.format(q{InputRange}, - q{isInputRange!R && !(isForwardRange!R)})); - -mixin(cipherFunctionString.format(q{ForwardRange}, - q{isForwardRange!R})); +mixin(cipherFunctionString!(InputRange, isOnlyInputRange)); +mixin(cipherFunctionString!(ForwardRange, isForwardRange)); unittest { @@ -37,9 +34,14 @@ unittest private: -enum cipherFunctionString = q{ +template isOnlyInputRange(R) +{ + enum isOnlyInputRange = isInputRange!R && !(isForwardRange!R); +} + +enum cipherFunctionString(alias ReturnType, alias Constraint) = q{ %s!(ElementType!R) cipherFunction(R)(R range, ubyte[32] key, ubyte[8] nonce, Cipher cipher) - if (is(ElementType!R : ubyte) && %s) + if (is(ElementType!R : ubyte) && %s!R) { final switch (cipher) { @@ -49,4 +51,4 @@ enum cipherFunctionString = q{ return range.chacha20Cipher(key, nonce).inputRangeObject; } } -}; +}.format(__traits(identifier, ReturnType), __traits(identifier, Constraint));