Boost logo

Boost :

From: Ed Brey (edbrey_at_[hidden])
Date: 2001-06-28 09:28:00


From: "John Fletcher" <j.p.fletcher_at_[hidden]>
>
> Surely one based indexing is used naturally in relation to the
> counting of objects, starting from the experience of small children. I
> don't go to shop to buy 0 packets of soap powder.
>
> The tuple is a collection of objects of different types. I find it
entirely
> natural to think of the first object, second object, etc. in a
> collection.
>
> At their birthday, someone opens the first present, not the zeroth.

It's important not to confuse English language notation with indexing
notation. The English language does not have a word "zeroth", because
no corresponding concept exists. Even in C arrays, the a[0] is the
first element of the array. It so happens that the first element has an
offset from the beginning of the array of zero places (&a[0] == a + 0),
and hence zero is used for its index.

You don't buy zero packets of soap powder (laundry detergent, I gather?;
the term is unfamiliar to me) because the size of the container is not
equal any of the indexes of the packets. That is fine, since index and
size are two different concepts.

As far as "natural" indexing used in the real world, I've seen both
0-based and 1-based in use. An example is numbering of floors in a
building. In America, we use 1-based indexing, but in Europe (at least
where I've been, which doesn't include the UK), they use 0-based, e.g.
the first floor is the one immediately above the ground-level floor.

Real-world indexing convention is moot, however, since tuple indexing
will be used side-by-side with arrays, vectors, indexable maps, pointer
offset, etc. in C++. Compatibility with the rest of C++ is paramount,
since only very occasionally will the programmer be looking at a row of
elevator buttons while typing. As others have alluded to, as the power
of the tuple and lambda libraries grows, they will find increasingly
closer use with existing containers that use 0-based indexing. It would
be a recipe for confusion, and an invitation for future users to curse
the legacy decisions of old (made today), to have non-aligned indexing.

Compatibility between the tuple and lambda libraries is important. The
outcome of this discussion should apply to both libraries.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk