Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2001-06-29 09:29:53


On Friday 29 June 2001 07:56, you wrote:
> From: "Beman Dawes" <bdawes_at_[hidden]>
>
> > >[David Abrahams]
> > >I think the arguments for interoperability of zero-based indexing are
> > >compelling. All the same, is there any reason we can't have both
> >
> > zero-based
> >
> > >indexing and '_1st', '_2nd', etc. as suggested below?
> >
> > I also vote for 0-based indexing but 1-based naming (_1st, _2nd, _3rd,
> > ...).
> >
> > --Beman
>
> I also vote for this solution.
>
> The enumeration proposal by Joel de Guzman:
>
> enum
> {// NAME INDEX
> _1st // = 0 (according to both C and C++ standards)
> , _2nd // = 1
> , _3rd // = 2
> , ... // ...
> };
>
> makes it seem like this issue had already been codified into the design of
> C.

This doesn't do what tuples, binders, etc. need it to. They need to know
which position is being referenced at compile-time, not run-time. So we want
something like:

template<int N>
struct index {
  operator int() const { return N; }
};

Then:
const index<0> _1st;
const index<1> _2nd;
etc.

        Doug

> ...
>
> In case someone is interested, it is possible to generate the enumeration
> list using the PREPROCESSOR library up to 100 like this:
>
> #define BOOST_MAKE_INDEX_NAME(I,TAIL)\
> BOOST_PREPROCESSOR_CAT\
> ( _\
> , BOOST_PREPROCESSOR_CAT\
> ( BOOST_PREPROCESSOR_INC(BOOST_PREPROCESSOR_INC(I))\
> , TAIL\
> )\
> )
>
> #define BOOST_MAKE_10_INDEX_NAMES(I,A,B)\
> , BOOST_MAKE_INDEX_NAME(I,1st)\
> , BOOST_MAKE_INDEX_NAME(I,2nd)\
> , BOOST_MAKE_INDEX_NAME(I,3rd)\
> , BOOST_MAKE_INDEX_NAME(I,4th)\
> , BOOST_MAKE_INDEX_NAME(I,5th)\
> , BOOST_MAKE_INDEX_NAME(I,6th)\
> , BOOST_MAKE_INDEX_NAME(I,7th)\
> , BOOST_MAKE_INDEX_NAME(I,8th)\
> , BOOST_MAKE_INDEX_NAME(I,9th)\
> , BOOST_MAKE_INDEX_NAME(BOOST_PREPROCESSOR_INC(I),0th)
>
> enum
> { _1st
> , _2nd
> , _3rd
> , _4th
> , _5th
> , _6th
> , _7th
> , _8th
> , _9th
> , _10th
>
> , _11th // special case!
> , _12th // special case!
> , _13th // special case!
> , _14th
> , _15th
> , _16th
> , _17th
> , _18th
> , _19th
> , _20th
>
> BOOST_PREPROCESSOR_REPEAT
> ( 8
> , BOOST_MAKE_10_INDEX_NAMES
> , A
> , B
> )
> };
>
> #undef BOOST_MAKE_10_INDEX_NAMES
> #undef BOOST_MAKE_INDEX_NAME
>
>
>
> Info: http://www.boost.org Unsubscribe:
> <mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/


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