|
Boost Users : |
Subject: Re: [Boost-users] [ptr_container] Transferring the Last Element from a ptr_vector
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-09-09 12:47:59
AMDG
Nat Goodspeed wrote:
> Charles Brockman wrote:
>
>> Thorsten Ottosen wrote:
>>> You can't use reverse iterators in transfer.
>>
>> Thank you, Thorsten. I'll create an iterator to the last element and
>> use that in the transfer.
>>
>> GeneVectType::iterator othEndIter = other->geneVect.end();
>> --othEndIter;
>> geneVect.transfer(geneVect.begin(), othEndIter, other->geneVect);
>
> Um -- I'm under the impression that decrementing the iterator returned
> by end() is discouraged. There are containers for which that
> definitely would not work.
It should work for any container that supports bidirectional iterators.
> I'm guessing that he would recommend something like
> other->geneVect.rbegin().base() instead -- presuming you've already
> ensured that other->geneVect isn't empty.
other->geneVect.rbegin().base() is equivalent to other->getVect.end().
In Christ,
Steven Watanabe
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net