|
Boost Users : |
Subject: Re: [Boost-users] Delete and free all elements of ptr_vector
From: Richard Hodges (hodges.r_at_[hidden])
Date: 2017-09-07 09:45:04
Complete example:
#include <iostream>
#include <boost/utility.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
struct Foo : boost::noncopyable
{
Foo() { std::cout << "made a Foo\n"; }
~Foo() { std::cout << "destroyed a Foo\n"; }
};
int main() {
boost::ptr_vector<Foo> foos;
foos.push_back(new Foo());
foos.push_back(new Foo());
foos.clear();
}
On 7 September 2017 at 11:28, Thorsten Ottosen via Boost-users <
boost-users_at_[hidden]> wrote:
> Den 07-09-2017 kl. 11:09 skrev Florian Lindner via Boost-users:
>
>> Hello,
>>
>> in my project we have a simple ptr_vector that has a member function:
>>
>> void deleteElements ()
>> {
>> for ( CONTENT_T * elem : _content ) {
>> assertion ( elem != NULL );
>> delete ( elem );
>> }
>> }
>>
>> I want to replace this ptr_vector with boost::ptr_vector. However, I
>> haven't found a way to delete and free all pointers
>> stored in the container. How can I do that?
>>
>
> boost::ptr_vector<Foo> container;
> ...
> container.clear()
>
> kind regards
>
> -Thorsten
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
>
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