Boost logo

Boost :

From: Brock Peabody (brock.peabody_at_[hidden])
Date: 2003-10-09 17:06:08

> -----Original Message-----
> From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]]
> On Behalf Of Eric Niebler
> Sent: Thursday, October 09, 2003 4:28 PM
> To: Boost mailing list
> Subject: [boost] Re: any interest in a foreach looping construct?
> Brian McNamara wrote:
> > accepting something like this opens the door to other
> > container-facades, like
> >
> > BOOST_TRANSFORM( int_list, f )
> > // means std::transform( int_list.begin(), int_list.end(), f )
> >
> > and it's unclear to me that this is a road I want to go down.
> >
> > So, I dunno. I'm mildly in favor of it, but I don't like the idea of
> > it setting a precedent.
> I don't think it would be setting a precedent. I see this as filling a
> hole in the language. Other languages have foreach looping constructs,
> and C++ is often criticised for the lack of one. Many new C++
> programmers ask for foreach (See the "D vs. C++" and "anonymous blocks"
> threads on c.l.c++.m, for example). Nobody asks for a "transform"
> keyword -- it's not an important enough concept.

One thing I use a lot is a "for_each" that takes a container rather than
iterators. It's a lot easier to write:

   for_each(make_a_list(), f);


   const std::vector<int> l = make_a_list();

   std::for_each(l.begin(), l.end(), f);

I thought there was a thread a while back about container (or even range)
based algorithms vs the stl iterator based algorithms.

Anyway, I think BOOST_FOREACH is cool, but it I'd be more likely to use a
container based for_each in conjunction with boost::lambda and/or FC++.
Maybe it's just going to take some soaking in before the coolness of
BOOST_FOREACH overcomes my macro bigotry.


Boost list run by bdawes at, gregod at, cpdaniel at, john at