mutatedCount

Indicates how many elements of a range are different from the default element value.

size_t
mutatedCount
(
Range
)
(
Range range
)
if (
isInputRange!Range &&
is(typeof((ElementType!Range).init))
&&
isMutable!(ElementType!Range)
&&
!isNarrowString!Range
)

Parameters

range Range

An input range. The elements must be mutable and initializable. Narrow srings are not considered as validate input parameter.

Return Value

Type: size_t

A number equal to the count of elements that are different from their initializer.

Examples

int[] i = [0,0,1];
assert(i.mutatedCount == 1);
assert(i[0..$-1].mutatedCount == 0);

string[] s = ["","a"];
assert(s.mutatedCount == 1);

dchar[] dc = [dchar.init, 'g'];
assert(dc.mutatedCount == 1);

class Foo {}
Foo[] f = new Foo[](8);
assert(f.mutatedCount == 0);
f[0] = new Foo;
f[1] = new Foo;
assert(f.mutatedCount == 2);

// w/char.init leads to decoding invalid UTF8 sequence
static assert(!is(typeof(mutatedCount!(char[]))));
static assert(!is(typeof(mutatedCount!(wchar[]))));

static assert(is(typeof(mutatedCount!(dchar[]))));

Meta