mirror of
https://github.com/dlang/phobos.git
synced 2025-05-06 11:07:39 +03:00
Merge pull request #7530 from Just-Harry/fix-issue-20929
Fix issue 20929 - std.experimental.allocator.expandArray's range-based overload fails to instantiate for char and wchar arrays.
This commit is contained in:
commit
a3dd382e66
1 changed files with 39 additions and 9 deletions
|
@ -2082,12 +2082,12 @@ if (isInputRange!R && !isInfinite!R)
|
||||||
|
|
||||||
version (StdUnittest)
|
version (StdUnittest)
|
||||||
{
|
{
|
||||||
private struct ForcedInputRange
|
private struct ForcedInputRange(T)
|
||||||
{
|
{
|
||||||
int[]* array;
|
T[]* array;
|
||||||
pure nothrow @safe @nogc:
|
pure nothrow @safe @nogc:
|
||||||
bool empty() { return !array || (*array).empty; }
|
bool empty() { return !array || (*array).empty; }
|
||||||
ref int front() { return (*array)[0]; }
|
ref T front() { return (*array)[0]; }
|
||||||
void popFront() { *array = (*array)[1 .. $]; }
|
void popFront() { *array = (*array)[1 .. $]; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2100,7 +2100,7 @@ version (StdUnittest)
|
||||||
|
|
||||||
void test(A)(auto ref A alloc)
|
void test(A)(auto ref A alloc)
|
||||||
{
|
{
|
||||||
ForcedInputRange r;
|
ForcedInputRange!int r;
|
||||||
long[] a = alloc.makeArray!long(r);
|
long[] a = alloc.makeArray!long(r);
|
||||||
assert(a.length == 0 && a.ptr is null);
|
assert(a.length == 0 && a.ptr is null);
|
||||||
auto arr2 = arr;
|
auto arr2 = arr;
|
||||||
|
@ -2221,13 +2221,13 @@ if (isInputRange!R)
|
||||||
toFill.uninitializedFillDefault;
|
toFill.uninitializedFillDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; !range.empty; range.popFront, toFill.popFront)
|
for (; !range.empty; range.popFront, toFill = toFill[1 .. $])
|
||||||
{
|
{
|
||||||
assert(!toFill.empty);
|
assert(toFill.length > 0);
|
||||||
import std.conv : emplace;
|
import std.conv : emplace;
|
||||||
emplace!T(&toFill.front, range.front);
|
emplace!T(&toFill[0], range.front);
|
||||||
}
|
}
|
||||||
assert(toFill.empty);
|
assert(toFill.length == 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2267,7 +2267,7 @@ if (isInputRange!R)
|
||||||
@system unittest
|
@system unittest
|
||||||
{
|
{
|
||||||
auto arr = theAllocator.makeArray!int([1, 2, 3]);
|
auto arr = theAllocator.makeArray!int([1, 2, 3]);
|
||||||
ForcedInputRange r;
|
ForcedInputRange!int r;
|
||||||
int[] b = [ 1, 2, 3, 4 ];
|
int[] b = [ 1, 2, 3, 4 ];
|
||||||
auto temp = b;
|
auto temp = b;
|
||||||
r.array = &temp;
|
r.array = &temp;
|
||||||
|
@ -2275,6 +2275,36 @@ if (isInputRange!R)
|
||||||
assert(arr == [1, 2, 3, 1, 2, 3, 4]);
|
assert(arr == [1, 2, 3, 1, 2, 3, 4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Regression test for https://issues.dlang.org/show_bug.cgi?id=20929
|
||||||
|
@system unittest
|
||||||
|
{
|
||||||
|
static void test(Char, Allocator)(auto ref Allocator alloc)
|
||||||
|
{
|
||||||
|
auto arr = alloc.makeArray!Char(1, Char('f'));
|
||||||
|
|
||||||
|
import std.utf : byUTF;
|
||||||
|
auto forwardRange = "oo".byUTF!Char();
|
||||||
|
static assert(isForwardRange!(typeof(forwardRange)));
|
||||||
|
// Test the forward-range code-path.
|
||||||
|
assert(alloc.expandArray(arr, forwardRange));
|
||||||
|
|
||||||
|
assert(arr == "foo");
|
||||||
|
|
||||||
|
immutable(Char)[] temp = "bar";
|
||||||
|
auto inputRange = ForcedInputRange!(immutable(Char))(&temp);
|
||||||
|
// Test the input-range code-path.
|
||||||
|
assert(alloc.expandArray(arr, inputRange));
|
||||||
|
|
||||||
|
assert(arr == "foobar");
|
||||||
|
}
|
||||||
|
|
||||||
|
import std.experimental.allocator.gc_allocator : GCAllocator;
|
||||||
|
test!char(GCAllocator.instance);
|
||||||
|
test!wchar(GCAllocator.instance);
|
||||||
|
test!char(theAllocator);
|
||||||
|
test!wchar(theAllocator);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Shrinks an array by `delta` elements.
|
Shrinks an array by `delta` elements.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue