mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 22:21:09 +03:00
Fix issue 19257: Only remove const on .join if you can actually assign const to non-const values.
This commit is contained in:
parent
c029ef2ead
commit
7a32298747
1 changed files with 20 additions and 2 deletions
22
std/array.d
22
std/array.d
|
@ -1917,7 +1917,15 @@ if (isInputRange!RoR &&
|
|||
isInputRange!(Unqual!(ElementType!RoR)))
|
||||
{
|
||||
alias RetType = typeof(return);
|
||||
alias RetTypeElement = Unqual!(ElementEncodingType!RetType);
|
||||
alias ConstRetTypeElement = ElementEncodingType!RetType;
|
||||
static if (isAssignable!(Unqual!ConstRetTypeElement, ConstRetTypeElement))
|
||||
{
|
||||
alias RetTypeElement = Unqual!ConstRetTypeElement;
|
||||
}
|
||||
else
|
||||
{
|
||||
alias RetTypeElement = ConstRetTypeElement;
|
||||
}
|
||||
alias RoRElem = ElementType!RoR;
|
||||
|
||||
if (ror.empty)
|
||||
|
@ -1934,7 +1942,7 @@ if (isInputRange!RoR &&
|
|||
size_t len;
|
||||
foreach (r; ror)
|
||||
foreach (e; r)
|
||||
emplaceRef(result[len++], e);
|
||||
emplaceRef!RetTypeElement(result[len++], e);
|
||||
assert(len == result.length);
|
||||
return (() @trusted => cast(RetType) result)();
|
||||
}
|
||||
|
@ -2000,6 +2008,16 @@ if (isInputRange!RoR &&
|
|||
assert(arr.join(',') == "apple,banana");
|
||||
}
|
||||
|
||||
@safe unittest
|
||||
{
|
||||
class A { }
|
||||
|
||||
const A[][] array;
|
||||
auto result = array.join; // can't remove constness, so don't try
|
||||
|
||||
static assert(is(typeof(result) == const(A)[]));
|
||||
}
|
||||
|
||||
@safe unittest
|
||||
{
|
||||
import std.algorithm;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue