mirror of
https://github.com/dlang/phobos.git
synced 2025-05-04 00:54:05 +03:00
Fix Issue 10104 - Group of array of const/immutable
This commit is contained in:
parent
3abf8c1a29
commit
d1ffb938b5
2 changed files with 56 additions and 4 deletions
|
@ -4454,10 +4454,26 @@ forward range in all other cases.
|
||||||
*/
|
*/
|
||||||
struct Group(alias pred, R) if (isInputRange!R)
|
struct Group(alias pred, R) if (isInputRange!R)
|
||||||
{
|
{
|
||||||
private R _input;
|
|
||||||
private Tuple!(ElementType!R, uint) _current;
|
|
||||||
private alias comp = binaryFun!pred;
|
private alias comp = binaryFun!pred;
|
||||||
|
|
||||||
|
private alias E = ElementType!R;
|
||||||
|
static if ((is(E == class) || is(E == interface)) &&
|
||||||
|
(is(E == const) || is(E == immutable)))
|
||||||
|
{
|
||||||
|
private alias MutableE = Rebindable!E;
|
||||||
|
}
|
||||||
|
else static if (is(E : Unqual!E))
|
||||||
|
{
|
||||||
|
private alias MutableE = Unqual!E;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
private alias MutableE = E;
|
||||||
|
}
|
||||||
|
|
||||||
|
private R _input;
|
||||||
|
private Tuple!(MutableE, uint) _current;
|
||||||
|
|
||||||
this(R input)
|
this(R input)
|
||||||
{
|
{
|
||||||
_input = input;
|
_input = input;
|
||||||
|
@ -4494,7 +4510,7 @@ struct Group(alias pred, R) if (isInputRange!R)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@property ref Tuple!(ElementType!R, uint) front()
|
@property auto ref front()
|
||||||
{
|
{
|
||||||
assert(!empty);
|
assert(!empty);
|
||||||
return _current;
|
return _current;
|
||||||
|
@ -4547,6 +4563,31 @@ Group!(pred, Range) group(alias pred = "a == b", Range)(Range r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
// Issue 13857
|
||||||
|
immutable(int)[] a1 = [1,1,2,2,2,3,4,4,5,6,6,7,8,9,9,9];
|
||||||
|
auto g1 = group(a1);
|
||||||
|
|
||||||
|
// Issue 13162
|
||||||
|
immutable(ubyte)[] a2 = [1, 1, 1, 0, 0, 0];
|
||||||
|
auto g2 = a2.group;
|
||||||
|
|
||||||
|
// Issue 10104
|
||||||
|
const a3 = [1, 1, 2, 2];
|
||||||
|
auto g3 = a3.group;
|
||||||
|
|
||||||
|
interface I {}
|
||||||
|
class C : I {}
|
||||||
|
const C[] a4 = [new const C()];
|
||||||
|
auto g4 = a4.group!"a is b";
|
||||||
|
|
||||||
|
immutable I[] a5 = [new immutable C()];
|
||||||
|
auto g5 = a5.group!"a is b";
|
||||||
|
|
||||||
|
const(int[][]) a6 = [[1], [1]];
|
||||||
|
auto g6 = a6.group;
|
||||||
|
}
|
||||||
|
|
||||||
// Used by groupBy.
|
// Used by groupBy.
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -438,7 +438,10 @@ template Tuple(Specs...)
|
||||||
{
|
{
|
||||||
auto lhs = typeof(tup1.field[i]).init;
|
auto lhs = typeof(tup1.field[i]).init;
|
||||||
auto rhs = typeof(tup2.field[i]).init;
|
auto rhs = typeof(tup2.field[i]).init;
|
||||||
auto result = mixin("lhs "~op~" rhs");
|
static if (op == "=")
|
||||||
|
lhs = rhs;
|
||||||
|
else
|
||||||
|
auto result = mixin("lhs "~op~" rhs");
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -1113,6 +1116,14 @@ unittest
|
||||||
static assert(!__traits(compiles, tuple!("x", int)(2)));
|
static assert(!__traits(compiles, tuple!("x", int)(2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
class C {}
|
||||||
|
Tuple!(Rebindable!(const C)) a;
|
||||||
|
Tuple!(const C) b;
|
||||||
|
a = b;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns a $(D Tuple) object instantiated and initialized according to
|
Returns a $(D Tuple) object instantiated and initialized according to
|
||||||
the arguments.
|
the arguments.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue