C++ Logo

std-discussion

Advanced search

Re: Rationale for return type of the non-array version of std::ssize()

From: Thiago Macieira <thiago_at_[hidden]>
Date: Wed, 29 Apr 2020 17:56:02 -0700
On Tuesday, 28 April 2020 09:42:17 PDT Bo Persson via Std-Discussion wrote:
> Unless it is a wider type. It could be that ptrdiff_t is int and some
> container's size() function returns unsigned long long. It just *could*.

That is a distinct possibility if the container is not of objects in memory.
Examples: files in the filesystem, objects in an object store database,
database entries, etc. Or even simpler: bytes in a file.

Or on some exotic platform with small size_t and ptrdiff_t.. ptrdiff_t is not
required to work for any two arbitrary pointers, only those of one memory
block. So sizeof(uintptr_t) >= sizeof(ptrdiff_t).

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel System Software Products

Received on 2020-04-29 19:59:05