ptr-vector

How to erase elements from boost::ptr_vector

So I'm trying to get rid of my std::vector's by using boost::ptr_vector. Now I'm trying to remove an element from one, and have the removed element deleted as well. The most obvious thing to me was to do: class A { int m; }; boost::ptr_vector<A> vec; A* a = new A; vec.push_back(a); vec.erase(a); But this won't even compile (see below...

[C++] Problems with boost::ptr_vector and boost::any

Hey all, ok, so I got a doubt, I want to know if this is possible: I'm using a database, with generic data (strings, ints, bools, etc...). Whenever an object is constructed or a member of an object is modified, I have to query the database with the specific action (SELECT or UPDATE). First of all, this isn't a DB related question, my r...

Releasing a boost::ptr_vector, not matching documentation

I'm using boost 1.37, and I'm trying to use a boost::ptr_vector, and transfer ownership of it so I can return it from a function. Looking at the boost documentation (http://www.boost.org/doc/libs/1_36_0/libs/ptr_container/doc/tutorial.html#new-functions) std::auto_ptr< boost::ptr_deque<animal> > get_zoo() { boost::ptr_deque<animal> ...

Adding boost::ptr_vector to deque, typeid mismatch

I'm trying to add a boost::ptr_vector to a std::deque, using push_back(). When I do, I get a BOOST::ASSERT for the typeid mismatch. In "boost_ptr_container_clone_allocator" T* res = new T( r ); BOOST_ASSERT( typeid(r) == typeid(*res) && "Default new_clone() sliced object!" ); return res; From TotalVi...

Moving objects from one Boost ptr_container to another

I want to move certain element from a to b: boost::ptr_vector<Foo> a, b; // ... b.push_back(a.release(a.begin() + i))); The above code does not compile because the release function returns boost::ptr_container_detail::static_move_ptr<...>, which is not suitable for pushing back. How should I proceed? EDIT: I found out that the objec...

pushing back an boost::ptr_vector<...>::iterator in another boost::ptr_vector?

Hi all, I have the following code (just typed it in here, might have typos or stuff): typedef boost::ptr_vector<SomeClass> tvec; tvec v; // ... fill v ... tvec vsnap; for(tvec::iterator it = v.begin(); it != v.end(); ++it) { if((*v).anyCondition) vsnap.push_back( it ); // (*it) or &(*it) doesn't work } My problem is now ...

Iterating through boost ptr_vector

Hello, I have a ptr_vector list of my own objects. Something like this: boost::ptr_vector<SomeClass> *list; list->push_back(new SomeClass()>; ... BOOST_FOREACH(SomeClass *tempObj, list) // [x] { tempObj->... } >‘boost::ptr_vector<SomeClass>*’ is not a class, struct, or union type ...

Is there a way to Boost.Assign a ptr_vector?

Usually like this: #include <boost/assign/std/vector.hpp> vector<int> v; v += 1,2,3,4,5; Except for a: #include <boost/ptr_container/ptr_vector.hpp> boost::ptr_vector<int> v; If you need to know the reason; I'm using ptr_vector instead of vector only so I don't have to delete elements, but I need to initialize it using Boost.Assign...

boost::ptr_vector and find_if

I have a class: //header file class CMDatabase { class Try; typedef boost::shared_ptr<Try> TryPtr; typedef boost::ptr_vector<Try> TryVector; typedef TryVector::iterator TryVectorIterator; class Try { public: virtual ~Try(); virtual bool equal(CMDatabase::TryPtr mySd) = 0; }; }...

ptr_vector - _CrtDumpMemoryLeaks() - memory leaks even though destructor is called

Hi. I'm working on a game engine and in an earlier question it was suggested that I start using boost::ptr_vector to maintain a list of pointers. The basic idea is to have several State's, each State has a SceneGraph. Each state has several resources that they initialize, and then stuff its own SceneGraph. The SceneGraph has a boost::p...

How to retrieve a reference from a boost ptr_vector?

I have two classes: an Object class, and an ObjectManager class. The ObjectManager class stores "Objects" via a ptr_vector container. There are some instances where I need to retrieve references to these stored pointers to perform individual actions on them. How would I go about doing so? Compilable Pseudo Code: #include <boost/ptr_con...

Boost FOR_EACH Over A Ptr_Vector?

I'm currently having fun trying to learn some of the Boost libary. I'm currently doing what I guess will be a future homework project (semester hasn't started yet). However, this question is not about the homework problem, but about Boost. Code: /* AuctionApplication.h */ class AuctionApplication : boost::noncopyable { private: boo...

Derived class stored in ptr_vector not being destructed

Was trying to find the best way to use ptr_vector to store, access and release objects, especially when the stored object is inherited from other (ptr_vector should not have any issues with object slicing). But when running the below program, surprisingly the derived class isn't being destructed. Anyone know why? #include <boost/ptr_con...

Does ptr_vector iterator not require increments?

#include <boost/ptr_container/ptr_vector.hpp> #include <iostream> using namespace std; class Derived { public: int i; Derived() {cout<<"Constructed Derived"<<endl;} Derived(int ii):i(ii) {cout<<"Constructed Derived"<<i<<endl;} ~Derived() {cout<<"* Destructed Derived"<<i<<endl;} }; int main() { boost::...