We have dropped the dependency on Boost.Foreach by implementing `foreach`
and friends in terms of 'range-based for' (MESOS-3214
<https://issues.apache.org/jira/browse/MESOS-3214>). There are no changes
in terms of recommended usage and patterns.

A notable difference is that the scoping rules follows range-based for.

```
void F(const V& value) {
  foreach (const V& value, value.get<array>()) {
    /* ... */
  }
}
```

We probably meant for the `value` in `value.get<array>()` to refer to the
`value` function parameter as opposed to the loop variable. This used to
work fine with the previous macro due to the magic of macros which can
reorder things within. However, 'range-based for' follows the C++ scoping
rules and therefore the `value` in `value.get<array>()` binds to the loop
variable instead. This leads to undefined behavior. Note that this is no
different than `int x = x;` binding to itself. Refer to r46945
<https://reviews.apache.org/r/46945/> for an instance of this problem.

The new implementation is in r46165 <https://reviews.apache.org/r/46165/>.
It has a similar level of magic as `synchronized`, so some of you may find
it interesting. I've also explained it line-by-line in a Stackoverflow
answer <http://stackoverflow.com/a/36615023/2968284>.

Thanks,

MPark

Reply via email to