On 11/6/14 4:19 PM, Meta wrote:
This is the code for std.range.put:
void put(R, E)(ref R r, E e)
{
//Why?
@property ref E[] EArrayInit(); //@@@9186@@@: Can't use (E[]).init
//First level: simply straight up put.
static if (is(typeof(doPut(r, e))))
{
doPut(r, e);
}
//Optional optimization block for straight up array to array copy.
else static if (isDynamicArray!R && !isNarrowString!R &&
isDynamicArray!E && is(typeof(r[] = e[])))
{
immutable len = e.length;
r[0 .. len] = e[];
r = r[len .. $];
}
//Accepts E[] ?
else static if (is(typeof(doPut(r, [e]))) && !isDynamicArray!R)
{
if (__ctfe)
doPut(r, [e]);
else
doPut(r, (&e)[0..1]);
}
//special case for char to string.
else static if (isSomeChar!E && is(typeof(putChar(r, e))))
{
putChar(r, e);
}
//Extract each element from the range
//We can use "put" here, so we can recursively test a RoR of E.
else static if (isInputRange!E && is(typeof(put(r, e.front))))
{
//Special optimization: If E is a narrow string, and r accepts
characters no-wider than the string's
//Then simply feed the characters 1 by 1.
static if (isNarrowString!E && (
(is(E : const char[]) && is(typeof(doPut(r, char.max))) &&
!is(typeof(doPut(r, dchar.max))) && !is(typeof(doPut(r, wchar.max)))) ||
(is(E : const wchar[]) && is(typeof(doPut(r, wchar.max)))
&& !is(typeof(doPut(r, dchar.max)))) ) )
{
foreach(c; e)
doPut(r, c);
}
else
{
for (; !e.empty; e.popFront())
put(r, e.front);
}
}
else
{
import std.string;
static assert (false, format("Cannot put a %s into a %s.",
E.stringof, R.stringof));
}
}
What is the reason for that first function declaration, EArrayInit? It's
not referenced anywhere else in the function, and it doesn't even have a
body.
github blame is quite useful:
https://github.com/D-Programming-Language/phobos/blame/master/std/range.d#L668
The commit:
https://github.com/D-Programming-Language/phobos/commit/c717b503e7305a92410c23ca2bc2ea14b40f8aa2
It apparently was used when it was added, but is no longer used. Here is
the commit that removed the use:
https://github.com/D-Programming-Language/phobos/commit/87c71e6e14c3e9365a2cbf10105d7e6854824275
I think it can be safely removed.
-Steve