Home

In article <RJ_Ii.4992$3Y1.4503@newssvr17.news.prodigy.net>,
Mark P <usenet@fall2005REMOVE.fastmailCAPS.fm> wrote:

> Daniel T. wrote:
> > In article <cLidnSe9sp-m9GnbnZ2dnUVZ_gudnZ2d@comcast.com>,
> > "Howard" <me@here.com> wrote:
> >
> >> "Mark P" <usenet@fall2005REMOVE.fastmailCAPS.fm> wrote in message
> >> news:c%YIi.54627$YL5.28332@newssvr29.news.prodigy.net...
> >>> Ian Collins wrote:
> >>>> Howard wrote:
> >>>>> Is there an easy way to get an iterator (*not* a reverse-iterator) to
> >>>>> the last element in a list? The last() function returns the element
> >>>>> itself, not an iterator.
> >>>>>
> >>>> How about list.end()-1 or list.start()+(list.size()-1)
> >>>>
> >>> list iterators are bidirectional, not random access, so you can't do
> >>> arithmetic like this. Not to mention that list.size() is O(n).
> >>>
> >>> But you can do:
> >>>
> >>> list<T>::iterator it = l.end();
> >>> if( !l.empty())
> >>> --it;
> >>>
> >>> Now "it" points to either the last element or, if the list is empty,
> >>> end().
> >> Yeah, that's what I'm doing now, but I was hoping for a single expression
> >> I
> >> could use. This is working fine.
> >
> > Or how about:
> >
> > assert( !l.empty() );
> > list<T>::iterator it = l.rend().base();
>
> Isn't rend().base() the beginning of the list?

Right, sorry. rbegin().base().

previous
next

Re: Importing * From a Package
Re: Problem understanding pass by value and pass by reference of arrays and what happens in the memo
Re: compilation error related to template parameter
Re: Drawing a 640x480 Raw Image
Re: datetime.timedelta division confusion
Fundacja Hobbit
Niechciane i Zapomniane
Krwinka
Pajacyk
Akogo