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));