mutatedCount

Indicates how many elements of a range are mutated.

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

Parameters

range
Type: 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

1 int[] i = [0,0,1];
2 assert(i.mutatedCount == 1);
3 assert(i[0..$-1].mutatedCount == 0);
4 
5 string[] s = ["","a"];
6 assert(s.mutatedCount == 1);
7 
8 dchar[] dc = [dchar.init, 'g'];
9 assert(dc.mutatedCount == 1);
10 
11 class Foo {}
12 Foo[] f = new Foo[](8);
13 assert(f.mutatedCount == 0);
14 f[0] = new Foo;
15 f[1] = new Foo;
16 assert(f.mutatedCount == 2);
17 
18 // w/char.init leads to decoding invalid UTF8 sequence
19 static assert(!is(typeof(mutatedCount!(char[]))));
20 static assert(!is(typeof(mutatedCount!(wchar[]))));
21 
22 static assert(is(typeof(mutatedCount!(dchar[]))));

Meta