cmcstl2
cmcstl2 copied to clipboard
Do unsigned integral types satisfy RandomAccessIterable?
Required expression i += n
where n
is the (signed) difference type. To evaluate, n
is first converted to unsigned ([conv.integral]):
If the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source integer (modulo 2n where n is the number of bits used to represent the unsigned type). [ Note: In a two’s complement representation, this conversion is conceptual and there is no change in the bit pattern (if there is no truncation). —end note ]
Any sane semantics for RandomAccessIterable would give the result of i += n
the same result as n
applications of ++i
(or of -n
applications of --i
if n
is negative). I need to sit down and characterize the situations in which that is not true (if any).
Note that for a type like unsigned char
, given the way difference_type_t
is defined in the Ranges TS, the difference type will likely have more bits than unsigned char
.