Delete and free all elements of ptr_vector
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? Thanks, Florian
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
Complete example:
#include <iostream>
#include
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@lists.boost.org https://lists.boost.org/mailman/listinfo.cgi/boost-users
Thanks for your answer! One more question: Is there a way to store an incomplete (forward declared) type. I get the compiler error message: /home/florian/precice/src/mesh/Group.cpp:70:45: required from here /usr/include/boost/ptr_container/detail/reversible_ptr_container.hpp:111:17: error: invalid use of incomplete type 'class precice::mesh::Vertex' BOOST_ASSERT( typeid(*res) == typeid(*x) && In file included from /home/florian/precice/src/mesh/Group.cpp:1:0: /home/florian/precice/src/mesh/Group.hpp:8:11: note: forward declaration of 'class precice::mesh::Vertex' class Vertex; ^~~~~~ In file included from /usr/include/boost/assert.hpp:58:0, from /usr/include/boost/range/size.hpp:23, from /usr/include/boost/range/functions.hpp:20, from /usr/include/boost/ptr_container/detail/reversible_ptr_container.hpp:29, from /usr/include/boost/ptr_container/ptr_sequence_adapter.hpp:20, from /usr/include/boost/ptr_container/ptr_vector.hpp:20, from /home/florian/precice/src/mesh/Group.hpp:4, from /home/florian/precice/src/mesh/Group.cpp:1: /usr/include/boost/ptr_container/detail/reversible_ptr_container.hpp:111:17: error: invalid use of incomplete type 'class precice::mesh::Vertex' BOOST_ASSERT( typeid(*res) == typeid(*x) && So I assume no, or is there? Thanks, Florian Am 07.09.2017 um 17:28 schrieb Thorsten Ottosen:
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
Den 07-09-2017 kl. 12:57 skrev Florian Lindner via Boost-users:
Thanks for your answer!
One more question: Is there a way to store an incomplete (forward declared) type. I get the compiler error message:
Please see the FAQ: http://www.boost.org/doc/libs/1_64_0/libs/ptr_container/doc/faq.html Short answer: yes, but not at instantiation time. -Thorsten
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?
Note also that the destructor automatically cleans up. -T
participants (3)
-
Florian Lindner
-
Richard Hodges
-
Thorsten Ottosen