Topic: streamoff


Author: James Kuyper <kuyper@wizard.net>
Date: 1998/11/20
Raw View
In footnote 174, a comment is made about "types described as synonyms
for basic integral types, such as size_t (18.1) and streamoff (27.4.1)".
However, I can't find any such description of streamoff. Here are all
the parts of the standard that seem relevant:
=================================================================
21.1.2 traits typedefs        [lib.char.traits.typedefs]
....
 typedef OFF_T off_type;
....
3 Requires: Requirements for off_type and pos_type are described in
27.1.2
=================================================================
21.1.3.1 struct char_traits<char>
  [lib.char.traits.specializations.char]
....
4 The type streamoff is an implementation-defined type that satisfies
the requirements for OFF_T in 21.1.2
=================================================================
27.1.2 Positioning Type Limitations    [lib.iostreams.limits.pos]
The classes of clause 27 with template arguments charT and traits behave
as described if traits::pos_type and traits::off_type are streampos and
streamoff respectively. Except as noted explicitly below, their behavior
when traits::pos_type and traits::off_type are other types is
implementation-defined.
=================================================================
27.4.1 Types   [lib.stream.types]

 typedef OFF_T streamoff;

1 The type streamoff is an implementation-defined type that satisfies
the requirements of 27.4.3.2.

 typedef SZ_T streamsize;

2 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. 266)
==================================================================
27.4.3.2 fpos requirements [lib.fpos.operations]
1 Operations specified in Table 88 are permitted. In that table:

 -- P refers to an instance of fpos,
 -- p and q refer to an values of type P,
 -- O refers to type streamoff.
 -- o refers to a value of type streamoff.
 -- sz refers to a value of type streamsize
....
 Table 88 -- Position type requirements
[Only the entries relevant to streamoff are shown:]
+---------------------------------------------------------------+
|expression return type operational assertion/note +
|    semantics     pre/post-condition|
+===============================================================+
|P(o)  fpos  coverts from                    |
|    offset    |
+---------------------------------------------------------------+
|O(p)  OFF_T  converts to P(O(p))==p      |
|    offset    |
+---------------------------------------------------------------+
|q = p + o fpos  + offset q-o == p        |
|p += o        |
+---------------------------------------------------------------+
|q = p - o fpos  - offset q+o == p |
|p -= o        |
+---------------------------------------------------------------+
|o = p - q OFF_T  distance q+o == p |
+---------------------------------------------------------------+
|streamsize(o) streamsize converts  streamsize(O(sz))==sz |
|O(sz)  OFF_T  converts  streamsize(O(sz))==sz |
+---------------------------------------------------------------+
=================================================================
Is it possible that the word 'integral' was left out of the first
paragraph of 27.4.1?

A simple implementation that meets all of these requirements is that
OFF_T is the same as SZ_T, and I don't see any reason for a more
complicated implementation.

I want to be able to divide an off_type by an integer, getting another
off_type. I don't see anything that would guarantee my being able to do
that. I could convert to a streamsize and back again for the division,
but that seems more complicated than it should be.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]