Boost logo

Boost :

Subject: Re: [boost] [range] Proposal: addition of front(), back(), at(), operator[]
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2014-03-24 13:36:26


On Mar 24, 2014, at 2:14 AM, Valentin Ziegler <vziegler_at_[hidden]> wrote:

> Hi Adam,
>
>> 1. front()
>> returning the reference to the first element precondition (assert): !empty(rng)
>
>> return *begin(rng);
>
>> 2. back()
>> returning the reference to the last element precondition (assert): !empty(rng)
>
>> For BidirectionalRange
>> return *(--end(rng));
>
> In 99% of all cases above implementations will work just fine. However, there may be rare cases where the lifetime of the reference is bound to the lifetime of the iterator:
>
> [iterator.requirements.general] 9. Destruction of an iterator may invalidate pointers and references previously obtained from that iterator.

Interesting. I think that in C++14, the committee put that possibility to bed.
See LWG issue 2360 http://cplusplus.github.io/LWG/lwg-defects.html#2360

I’ll open an issue that gets that cleared up.

— Marshall

>
> Valentin
>
>
> --
> Valentin Ziegler | vziegler_at_[hidden]
> Senior Software Engineer
>
> We are looking for C++ Developers: http://www.think-cell.com/career
>
> think-cell Software GmbH | Chausseestr. 8/E | 10115 Berlin | Germany
> http://www.think-cell.com | phone +49 30 666473-10 | US phone +1 800 891 8091
>
> Amtsgericht Berlin-Charlottenburg, HRB 85229 | European Union VAT Id DE813474306
> Directors: Dr. Markus Hannebauer, Dr. Arno Sch?dl
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk