Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2005-05-09 12:31:49


Stefan Strasser wrote:
> you might be interested in this document from the new c++0x mailing:
>
> http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1796.html
>
> for the naming discussion, proposed syntax is for(int i : vec)
> (personally I don't care if it's called BOOST_FOREACH or BOOST_FOR)
>
> I've questioned in the past if it is expected behaviour to do
> "hoisting". the proposal does.
>
> "4 Making a custom type work with the for loop" may also be
> interesting to make the BOOST_FOREACH extension mechanism similar.
>

This essentially *is* the BOOST_FOREACH extension mechanism, or what it
would be if we had auto and decltype today.

I'm glad to see foreach moving ahead in the committee. Obviously, I'm of
the opinion that C++ needs this.

This proposal is a good start, but it seems to take quite a bit for
granted. It depends on the auto function(...) -> decltype(...) syntax.
It depends on rvalue references. It assumes that the Boost.Range begin()
and end() functions exist in std namespace (and I'm not aware of a
proposal to add those). Perhaps the proposal should discuss alternate
designs should certain features not make it into the language.

It also relies on ADL of the begin() and end() functions, even though we
decided, after a very lengthy discussion on Boost.Users, that this isn't
the way to go, IIRC.

Also it requires users to #include <iterator> in order to use the new
looping construct. There's precedent for that, though, because users
must #include <typeinfo> to use typeid. I can't decide how I feel about
that. Perhaps there's another way.

It surprises me a bit that Thorsten makes no mention of BOOST_FOREACH in
this proposal, though. Seems relevant, if only to establish interest and
existing practice.

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com

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