Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-10-10 18:39:32


"Eric Niebler" <eric_at_[hidden]> writes:

> David Abrahams wrote:
>> Eric Niebler wrote:
>>> putting the type there is more explicit, and
>>>it makes it look more like a for(;;) loop. Besides, you might want a
>>>conversion to occur; for example, BOOST_FOREACH( int i,
>>>vector_of_bools ). Also it's impossible to achieve without typeof()
>>>AFAICT.
>> That all sounds unconvincing to me. I believe the conversion should
>> be more explicit if you want it:
>> FOR_EACH(b, vector_of_bools)
>> {
>> whatever((int)b);
>> }
>
> Yes, but "it's impossible to achieve without typeof()". I think that's
> pretty convincing. ;-) Besides, if you don't declare the type, how do
> you know whether the loop variable should be a reference or a value?

You use decltype ;-)

> Defaulting to a value or const reference is limitting; defaulting to a
> non-const reference is dangerous.

Surely if the non-const reference was wrong in some case, you'd get a
compile-time error, no?

> I have an idea for how we could disallow an implicit conversion from
> happening, if people think it's the Right Thing. But personally, I
> don't.

No, I don't think so either, once you have to declare the thing
anyway.

>
>>>int i;
>>>BOOST_FOREACH( i, int_list )
>>>{ ... }
>>>
>>>That way you can have access to the loop variable after the loop finishes.
>> It's important to be able to do that; no doubt. It'd be nice to
>> find
>> a more-verbose syntax for that one, though ;^)
>
>
> OK. I'm open to suggestions.

Well, there's really no point without decltype/typeof, is there? I
only wanted something more verbose to make way for the implicit
version we discussed first off.

-- 
Dave Abrahams
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