Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2005-10-12 12:53:17


Eric Niebler wrote:
> A. Azuma wrote:
>
>>2005/10/9, Daniel James <daniel_at_[hidden]>:
>>
>>
>>>Unfortunately, this technique is not standards compliant. The problem is
>>>in this code:
>>>[snip]
>>
>>
>>Ah, I see. I overlooked this problem. I'm ashamed of my
>>misinterpretation . After a
>>little thought, I have concluded that there might not be any tricks to
>>enable this
>>kind of ADL. I would have to abandon my idea. Does anyone have good idea?
>>
>
>
>
> No reason to be ashamed -- it was a clever idea. There was one other
> person during the FOREACH review who argued for a similar interface,
> using TYPEOF in the implementation. There are a few reasons IMO why it
> wasn't a good idea:
>
> 1) ...

<snip>

Oh, and I forgot ...

4) It breaks some perfectly reasonable assumptions. Consider:

     std::string str = "hello";
     std::string::iterator iter = str.begin();
     FOREACH(iter, str) {
       if(some-condition) break;
     }
     // use iter here

People familiar with for(;;) would naturally expect this code to reuse
the variable "iter" found in the enclosing scope, but with your version
it wouldn't. Rather, it would create a new var named iter, hiding the
outer one. The code after the loop would be using the outer iter, which
is still pointing at the beginning of the string. Very counter-intuitive.

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