tatically checking for overflow with
if constexpr (sizeof(std::size_t) <= sizeof(std::int64_t)) { return static_cast<std::int64_t>(length); }
Doesn't work if sizeof(std::size_t) == sizeof(std::int64_t) because std::size_t
is unsigned.
if length == std::numeric_limits<size_t> casting it to int64_t is going to overflow.
This code would be much simpler if returning a uint64_t instead of a signed
value...