|
Boost Users : |
Subject: Re: [Boost-users] [ptr_container] Transferring the Last Element from a ptr_vector
From: Sebastian Theophil (stheophil_at_[hidden])
Date: 2009-09-09 12:52:13
> 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.
>
> 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.
Nat,
you would be half right only if GeneVectType::iterator were a
forward_iterator, but a ptr_sequence_adapter is always reversible, so
the iterator must be bidirectional.
Internally, the boost::reverse_iterator you propose also has to
decrement, so it doesn't work any better. Additionally, your proposed
solution crashes because other->geneVect.rbegin().base() returns in fact
other->geneVect.end(). Only *other->geneVect.rbegin() returns
*(other->geneVect.end()-1).
Regards
Sebastian
-- Sebastian Theophil . stheophil_at_[hidden] Software Engineer think-cell Software GmbH . Invalidenstr. 34 . 10115 Berlin, Germany http://www.think-cell.com . phone +49-30-666473-10 . toll-free (US) +1-800-891-8091 Directors: Dr. Markus Hannebauer, Dr. Arno Schoedl . Amtsgericht Berlin-Charlottenburg, HRB 85229
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