Boost logo

Boost :

From: Vesa Karvonen (vesa.karvonen_at_[hidden])
Date: 2001-06-29 06:56:50


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.

...

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


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