Boost logo

Boost :

Subject: Re: [boost] [preprocessor] half-open or closed ranges?
From: David Abrahams (dave_at_[hidden])
Date: 2008-11-26 14:07:13


on Wed Nov 26 2008, Eric Niebler <eric-AT-boost-consulting.com> wrote:

> I've noticed an inconsistency with how the preprocessor library handles integer
> ranges. Consider this:
>
> #define M0(Z,N,DATA) N
> BOOST_PP_REPEAT_FROM_TO(1,3,M0,~)
>
> This treats the range 1,3 as half-open. It generates the sequence "1 2". But consider
> this:
>
> #define BOOST_PP_LOCAL_MACRO(N) N
> #define BOOST_PP_LOCAL_LIMITS (1,3)
> #include BOOST_PP_LOCAL_ITERATE()
>
> This treats the range 1,3 as closed. It generates the sequence "1 2 3".
>
> Why the difference?

I know Paul explained his rationale for that at one point, but I don't
remember what it was. If I had to guess, I'd say a closed range allows
a natural and minimal implementation of vertical repetition, whereas the
use of an open range would add a dependency on BOOST_PP_DEC. Total
guess, though.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

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