microsoft / GSL

Guidelines Support Library
Other
6.11k stars 736 forks source link

Remove unnecessary check from size_bytes() #1105

Closed dmitrykobets-msft closed 1 year ago

dmitrykobets-msft commented 1 year ago

size_bytes() returns the span's size in bytes. Assuming the span was constructed with an accurate size parameter, the check size() < dynamic_extent / sizeof(element_type) isn't required, since size_t(-1) (which is dynamic_extent) represents the size of the address space, so the number of bytes will never exceed it and in practice won't even come close. Otherwise, it is not actually feasible to detect cases when the size parameter does not correspond to the dimensions of the underlying data pointer. In these cases, the relationship size() < dynamic_extent / sizeof(element_type) is simply one of many ways in which the size() could be incorrect, and serves no necessary purpose.

Resolves #1012