On Wed, Mar 23, 2011 at 5:46 PM, Jason Merrill <[email protected]> wrote:
> Yep. Here is the wording that we approved today:
[snip]
Nice. Thank you.
But now I'm a bit concerned about the complexity of this issue. Mind
me, I think that this solution is nice, but maybe it is a burden for
library implementors.
Let's say that I want to imitate 'exactly' the behavior of the
range-for, but with a plain old for (there are plenty of reasons for
that):
template<typename C> void foo(C &c)
{
auto _b = begin(c);
auto _e = end(c);
for (auto _i = _b; _i != _e; ++_i)
{
auto _e = *_i;
//do stuff
}
}
But this will fail sometimes for the reasons stated in N3257. If I
change the first line to:
auto _b = c.begin();
it will fail in a lot of different cases.
So I'm forced to write a pair of functions, let's name them
'range_begin/range_end' with a lot of SFINAE tricks to mimic the
range-for behavior. And there are a lot of subtleties and magic in the
range-for specification that makes that a hard work, if at all
possible.
IMHO, it would be much easier if the standard library provided these
functions for me. Before, I considered that was what
std::begin/std::end did, but now...
--
Rodrigo