Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-12-07 19:18:44


One other problem with the macros is that they're macros. Macros walk
indiscriminately across namespace boundaries, sometimes even silently
changing the meaning of otherwise correct code. It's too bad we can't write
"for x in S:" in C++, though ;->

----- Original Message -----
From: <rwgk_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, December 07, 2000 10:50 AM
Subject: [boost] What is wrong with iterator macros?

> On request of David Abrahams I removed my beloved iterator
> macros from a few 'getting started' examples that I wrote
> for the Boost Python Library.
>
> Here is what I normally use:
>
> #ifndef DEFINE_RANGE_H
> #define DEFINE_RANGE_H
>
> #define rangei(n) for (int i = 0; i < n; i++)
> #define range1(i, n) for (int i = 0; i < n; i++)
> #define range2(i, f, n) for (int i = f; i < n; i++)
> #define range3(i, f, n, s) for (int i = f; i < n; i += s)
>
> #endif // DEFINE_RANGE_H
>
> This simple include file allows me to make my source code
> look a lot more concise. What is bad with this approach?
> Is it just "bad style" (why?), or are there more fundamental
> (i.e. real) problems?
>
> This is probably not the most important question in the world,
> but each time I see myself typing (for int i = 0; i < 3; i++)
> I keep saying to myself that there must be a better way of
> doing this...
>
> Ralf
>
>
>
>
>


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