Boost logo

Boost Users :

Subject: Re: [Boost-users] reversible_ptr_container question
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-01-24 14:43:44


AMDG

Archie14 wrote:
> I am using ptr_vector and tried to get last element from the vector using
> rbegin() - which apparently is not supported by ptr_vector unless I missed
> smth.

rbegin is supported.

> After some search I found "reversible_ptr_container" in
> #include <boost/ptr_container/detail/reversible_ptr_container.hpp>
>
> I have my doubts if this is the one I should use because it is not easily found
> in the documentation and buried in the "details".
>
> The questions are:
> 1. For rbegin() relative to ptr_vector - should I employ
> reversible_ptr_containier?
No. ptr_vector uses reversible_ptr_container internally.
> If yes then short example will be highly
> appreciated.
>
> 2. How to get last element from ptr_vector (not using --end())?
>

Use back().

#include <boost/ptr_container/ptr_vector.hpp>

int main() {
    boost::ptr_vector<int> v;
    v.push_back(new int(0));
    boost::ptr_vector<int>::reverse_iterator iter = v.rbegin();
    int& ip = v.back();
}

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