Topic: Defect report: 24.1.5 contains unintented limitation for operator-=


Author: Daniel Frey <daniel.frey@aixigo.de>
Date: Fri, 27 Feb 2004 15:42:59 +0000 (UTC)
Raw View
[ Note: Forwarded to C++ Committee. -sdc ]

In 24.1.5 [lib.random.access.iterators], table 76 the operational
semantics for the expression "r -= n" are defined as "return r += -n".
This means, that the expression -n must be valid, which is not the case
for unsigned types. To remove this limitation, I suggest to change the
operational semantics for this column to:

{ Distance m = n; if (m >= 0) while (m--) --r; else while (m++) ++r;
return r; }

--
Daniel Frey

aixigo AG - financial solutions & technology
Schlo   -Rahe-Stra   e 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey@aixigo.de, web: http://www.aixigo.de



[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Gennaro Prota <gennaro_prota@yahoo.com>
Date: Sat, 28 Feb 2004 20:07:14 CST
Raw View
On Fri, 27 Feb 2004 15:42:59 +0000 (UTC), Daniel Frey
<daniel.frey@aixigo.de> wrote:

>
>[ Note: Forwarded to C++ Committee. -sdc ]
>
>In 24.1.5 [lib.random.access.iterators], table 76 the operational
>semantics for the expression "r -= n" are defined as "return r += -n".
>This means, that the expression -n must be valid, which is not the case
>for unsigned types.

Well, see 24.1/9. It's assumed that the type of n is the Distance type
of the described iterator. Since table 76 describes random access
iterators then n can't be unsigned (if it could, BTW, then the line
with "b-a", in the same table, would be flawed too)


--
Genny.

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Daniel Frey <d.frey@gmx.de>
Date: Sun, 29 Feb 2004 05:16:14 CST
Raw View
Gennaro Prota wrote:
> On Fri, 27 Feb 2004 15:42:59 +0000 (UTC), Daniel Frey
> <daniel.frey@aixigo.de> wrote:
>
>>[ Note: Forwarded to C++ Committee. -sdc ]
>>
>>In 24.1.5 [lib.random.access.iterators], table 76 the operational
>>semantics for the expression "r -= n" are defined as "return r += -n".
>>This means, that the expression -n must be valid, which is not the case
>>for unsigned types.
>
> Well, see 24.1/9. It's assumed that the type of n is the Distance type
> of the described iterator. Since table 76 describes random access
> iterators then n can't be unsigned (if it could, BTW, then the line
> with "b-a", in the same table, would be flawed too)

I stand corrected. Just to make sure: It wasn't intended to limit
containers to a maximum size of 31 bits on a 32-bit systems, right?
Wouldn't this mean that we have a potential source of bugs? (Although
unlikely to occur)

Regards, Daniel

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Gennaro Prota <gennaro_prota@yahoo.com>
Date: Sun, 29 Feb 2004 16:17:49 CST
Raw View
On Sun, 29 Feb 2004 05:16:14 CST, Daniel Frey <d.frey@gmx.de> wrote:

>I stand corrected. Just to make sure: It wasn't intended to limit
>containers to a maximum size of 31 bits on a 32-bit systems, right?
>Wouldn't this mean that we have a potential source of bugs? (Although
>unlikely to occur)

I'm not sure what your question is. Yes, if one managed to create,
say, a vector<char> v of size_type(-1) elements then, for instance,
std::distance(v.begin(), v.end()) would pose some problems :) But I
think you know this.

In practice distance between iterators is limited to [-T_MAX, T_MAX]
where T is the Distance type. Note the symmetry (even if T_MIN is
actually -T_MAX-1), which is another prerequisite for the "-n" to be
acceptable.


--
Genny.

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]