From 918d8f54503fb1035ffb3465770e6a107950fc99 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 10 Aug 2018 15:34:07 +0200 Subject: [PATCH] Deprecated putting an input into an output range Use copy instead. --- source/tanya/range/primitive.d | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/source/tanya/range/primitive.d b/source/tanya/range/primitive.d index c9134de..72824a5 100644 --- a/source/tanya/range/primitive.d +++ b/source/tanya/range/primitive.d @@ -851,6 +851,8 @@ void put(R, E)(ref R range, auto ref E e) } else static if (isInputRange!E) { + pragma(msg, "Putting an input range into an output range is " + ~ "deprecated. Use tanya.algorithm.mutation.copy instead"); for (; !e.empty; e.popFront()) { put(range, e.front); @@ -963,7 +965,22 @@ void put(R, E)(ref R range, auto ref E e) * Returns: $(D_KEYWORD true) if $(D_PARAM R) is an output range for the * elements of the type $(D_PARAM E), $(D_KEYWORD false) otherwise. */ -enum bool isOutputRange(R, E) = is(typeof((ref R r, ref E e) => put(r, e))); +template isOutputRange(R, E) +{ + static if (is(typeof((R r, E e) => put(r, e)))) + { + enum bool isOutputRange = true; + } + else static if (isInputRange!E) + { + alias ET = ElementType!E; + enum bool isOutputRange = is(typeof((R r, ET e) => put(r, e))); + } + else + { + enum bool isOutputRange = false; + } +} /// @nogc nothrow pure @safe unittest