Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-10-27 14:21:04

Rob Stewart <stewart_at_[hidden]> writes:

> From: Pavol Droba <droba_at_[hidden]>
>> On Mon, Oct 27, 2003 at 02:07:47AM +1100, Thorsten Ottosen wrote:
>> > "Pavol Droba" <droba_at_[hidden]> wrote in message
>> >
>> > > Then you would also need a type which holds values in range 1..n. Arrays
>> > > and
>> > > containers are 0-indexed also because unsigned types are denoting exactly
>> > > this
>> > > domain. And actualy what conteptual difference between "first element" and
>> > > "first match of substring"?
>> >
>> > well, you almost said it The first element of an array is index 0. The first
>> > substring of a string
>> > is a index X. Also, array objects(chars). are not substrings unless we're
>> > talking about substrings of lenght 1.
>> > You also called your functions firnd_first, not find_0th, and we have
>> >
>> > find_first( s, XX ) == find_nth( s, XX, 0 )
>> >
>> > which doesn't seem natural. It's like having an integer variable and making
>> > zero mean you have got one
>> > of something.
> A substring is not a structural element of the container. A
> container is, by definition, composed of elements. A substring
> is a semantic notion temporarily associated with a portion of a
> container. Thus, the former should be denoted using the usual
> C/C++ indexing notation. The latter, OTOH, should be denoted
> using the vernacular: we use ordinals to refer to things like
> substrings. That means numbering from one for substrings.
>> What would then denote find_nth( s, XX, 0 )? Should it throw an exception?
> Sure.

I don't get it. The first element of a sequence is s[0]. Why
shouldn't the first matching substring be find_nth(s, XX, 0)?

You can think of find_nth as indexing into a view onto the matching
substrings of s if you want.

I imagine most C++ programmers will have the same trouble
understanding why the first should be 1 in this case.

Finally, interfaces which allow values to be passed at compile-time
which are *always* illegal at runtime are a bad idea. That's
especially true for an unsigned zero, and especially in this case
which is clearly confusable.

Dave Abrahams
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at