Topic: definition of allocator::difference_type?
Author: John Max Skaller <maxtal@suphys.physics.su.oz.au>
Date: 1995/11/03 Raw View
ebiederm@cse.unl.edu (Eric Biederman) wrote:
>
>In reading through 20.1 Allocator requirements [lib.allocator.requirements]
>
>I have come across some wording which I find inconsistent with what is
>in the rest of the standard as I understand it.
>
>X::difference_type
>the type that can represent the difference between any two pointers in
>the memory model.
>
>Which seems to say that the operation
>X::pointer a,b;
> // initialize a & b to point into different objects
>X::difference t = a - b; // seems to be well defined.
>
>later in
>20.4.1 The default allocator [lib.default.allocator]
>in the definition of the default allocator,
>
>class allocator {
>public:
> typedef size_t size_type
> typedef ptrdiff_t difference_type
>
>If I understand the definition of ptrdiff_t from C the result is
>undefined if you take the difference of two pointers which do not
>point into the same object.
>
>So is it undefined or not, if you are using the types supplied with
>the allocators? What is the intent here?
This is a mathematical confusion in the WP found
in more than one place in the STL specs. Another example
is in the description of the < operator.
Both operator- and operator< need be well defined ONLY
on a set of pairs of iterators such that each pair
constitues a valid range.
--
John Max Skaller voice: 61-2-566-2189
81 Glebe Point Rd fax: 61-2-660-0850
GLEBE NSW 2037 email: maxtal@suphys.physics.oz.au
AUSTRALIA email: skaller@maxtal.com.au
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]