From: Paul A. Bristow (boost_at_[hidden])
Date: 2003-10-28 06:02:50
I share Rob's concern about this but I sense the discussion is getting nowhere.
The root cause is the insane choice of zero as index for the first element, but
that mistake was made decades ago and we have to continue to live with it - or
use another language.
(John Barnes, designer of RTL/2 and Ada, discusses the choice of base in his
book on RTL/2 circa 1968, concluding that only mathematicians prefer zero and
they have special enough brains to cope with using one or zero, so to please the
rest of us, it has to be one).
So despite being counter-intuitive, I think the existing scheme is the least
wrong, but it does need plenty of prominent 'skull and crossbones' warnings in
Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK
+44 1539 561830 Mobile +44 7714 33 02 04
| -----Original Message-----
| From: boost-bounces_at_[hidden]
| [mailto:boost-bounces_at_[hidden]]On Behalf Of Rob Stewart
| Sent: Monday, October 27, 2003 8:24 PM
| To: boost_at_[hidden]
| Cc: boost_at_[hidden]
| Subject: Re: [boost] Re: [string algo formal review]
| From: David Abrahams <dave_at_[hidden]>
| > Rob Stewart <stewart_at_[hidden]> writes:
| > >
The first element of a sequence is s. Why
| > shouldn't the first matching substring be find_nth(s, XX, 0)?
| Because s isn't the 0th element; it's the first. As I said,
| we use ordinals to refer to things like this. Addressing an
| element uses an index, and indexes start at zero. "nth"
| explicitly refers to ordinals, and there's no 0th; you start with
| 1st, so find_nth() should reasonably start numbering from one.
| > You can think of find_nth as indexing into a view onto the matching
| > substrings of s if you want.
| OK, but where's the view object with a subscript operator to
| which I can supply 0 as an index?
| > I imagine most C++ programmers will have the same trouble
| > understanding why the first should be 1 in this case.
| You have a good imagination! ;-)
| > 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.
| I find "0th" confusing and that's what find_nth(s, XX, 0) is
| asking for. That should always fail, IMO, since there is no such
| thing as a 0th entity.
| Why not just specialize find_nth() for 0 so it does not compile?
| Rob Stewart stewart_at_[hidden]
| Software Engineer http://www.sig.com
| Susquehanna International Group, LLP using std::disclaimer;
| Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk