On 25 March 2011 10:13, Rodrigo Rivas wrote:
>
> 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...

It's FAR too late - do you want a new standard today or next year?

If you want something that behaves like range-for use range-for.

Or just don't use range-for, it's not essential (given the trouble
it's caused I'd quite happily have lived without it in C++0x!)

Reply via email to