1

According to std::streamsize at cppreference.com:

It is used as a signed counterpart of std::size_t

What does it mean? Does the standard require that std::is_same_v<std::streamsize, std::make_signed_t<std::size_t>>? If not, is either guaranteed to be at least as wide as the other?

Can it be used to simplify the type std::common_type_t<std::ptrdiff_t, std::make_signed_t<decltype(c.size())>> given at std::size, std::ssize?

ByteEater
  • 885
  • 4
  • 13
  • `static_assert(sizeof(std::size_t) == sizeof(std::streamsize));` Otherwise eventually we may have `posix::ssize_t` (the `posix` namespace is reserved). – Eljay Jul 30 '23 at 14:00
  • There are no guarantees, or otherwise we could just use one of the other types. On a "normal" system, `streamsize` could very well be the same as `ptrdiff_t`, but the standard also makes room for "unnormal" systems. – BoP Jul 30 '23 at 14:00
  • 1
    No. "used as" doesn't mean "is". – Pete Becker Jul 30 '23 at 14:07
  • __The type streamsize is a synonym for one of the signed basic integral types. It is used to represent the number of characters transferred in an I/O operation, or the size of I/O buffers.__ ← This is literally all standard has to say about this type. – Revolver_Ocelot Jul 30 '23 at 14:19
  • It's virtually impossible to say what is meant by "counterpart" in this context. The C++ standard doesn't use the word "counterpart" in the text on `streamsize` at all, let alone specify what such a counterpart might be. So the wording you're quoting is an interpretation by whoever wrote the page at cppreference - and they haven't expanded on what that means either. – Peter Jul 30 '23 at 14:30
  • 1
    For specifics like this you really have to read the standard. Section [`stream.types`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/n4849.pdf) says the type is implementation-defined and "is used in most places where ISO C would use `size_t`". That and that it's signed is all we can say for sure about the type – Homer512 Jul 30 '23 at 14:36
  • @Peter, IIUC, integer types in C++ come in pairs: one signed, one unsigned. And how you can get counterprarts is by using `make_signed` and `make_unsigned`. – ByteEater Jul 30 '23 at 16:52
  • 2
    @ByteEater -- that is **one** possible meaning for "a signed counterpart" (note: not "the" signed counterpart). But even so, "used as" still doesn't mean "is". You're trying too hard. It's a sloppy statement; don't try to impose rigor on it. – Pete Becker Jul 30 '23 at 22:54

0 Answers0