According to the N4562 proposal, the newly proposed std::shared_ptr::operator[]
takes in std::ptrdiff_t
, which is a signed type.
This is inconsistent with every indexing operator in standard library. Even std::unique_ptr::operator[]
takes std::size_t
.
What's the rationale for this decision?
Probably this should be pointer interface unification. Good ol' C pointers when used as arrays accept negative indices: p[-2]
is the same as *(p - 2)
; and ptrdiff_t
is thus naturally signed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With