Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions std/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -2475,7 +2475,12 @@ if (isDynamicArray!A)
auto bigDataFun() @trusted nothrow { return _data.arr.ptr[0 .. len + 1];}
auto bigData = bigDataFun();

emplaceRef!T(bigData[len], item);
static if (is(Unqual!T == T))
alias uitem = item;
else
auto ref uitem() @trusted nothrow @property { return cast(Unqual!T)item; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the result of a cast always be non-ref? Couldn't this block be replaced by changing the original line to

emplaceRef!T(bigData[len], cast(Unqual!T)item);
?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the result of a cast always be non-ref?

Yes, the result of the cast from qualified to unqualified is always non-ref. But I'd like just to revert lines back to proven code 2.065.

emplaceRef!T(bigData[len], cast(Unqual!T)item);

It's not possible because the cast will make this put member function unsafe.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the result of the cast from qualified to unqualified is always non-ref. But I'd like just to revert lines back to proven code 2.065.

Fair enough, do you have a link to the patch that this is reverting?

It's not possible because the cast will make this put member function unsafe.

Ah I missed that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, do you have a link to the patch that this is reverting?

The change was introduced in:

https://github.com/D-Programming-Language/phobos/pull/2015/files#diff-54cf8402b22024ae667d4048a5126f0eL2437


emplaceRef!(Unqual!T)(bigData[len], uitem);

//We do this at the end, in case of exceptions
_data.arr = bigData;
Expand Down Expand Up @@ -2947,7 +2952,8 @@ unittest
}

unittest
{ //9528
{
//9528
const(E)[] fastCopy(E)(E[] src) {
auto app = appender!(const(E)[])();
foreach (i, e; src)
Expand All @@ -2963,15 +2969,16 @@ unittest
}

unittest
{ //10753
{
//10753
struct Foo {
immutable dchar d;
}
struct Bar {
immutable int x;
}
"12".map!Foo.array;
[1, 2].map!Bar.array;
"12".map!Foo.array;
[1, 2].map!Bar.array;
}

unittest
Expand Down Expand Up @@ -3064,6 +3071,24 @@ unittest
static assert(!is(typeof(appender(foo()))));
}

unittest
{
// Issue 13077
static class A {}

// reduced case
auto w = appender!(shared(A)[])();
w.put(new shared A());

// original case
import std.range;
InputRange!(shared A) foo()
{
return [new shared A].inputRangeObject;
}
auto res = foo.array;
}

/++
Convenience function that returns a $(D RefAppender!A) object initialized
with $(D array). Don't use null for the $(D array) pointer, use the other
Expand Down