Moving objects from one Boost ptr_container to another

I want to move a specific 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 sending back.

How should I proceed?

EDIT: I found that the returned object has .get () .release() , which provides a raw pointer (which may also lead to some exception security issues). However, I would prefer not to rely on undocumented internal functions, so feel free to share the best solutions ...

+4
source share
2 answers
 boost::ptr_vector<Foo> a, b; // transfer one element a[i] to the end of b b.transfer( b.end(), a.begin() + i, a ); // transfer N elements a[i]..a[i+N] to the end of b b.transfer( b.end(), a.begin() + i, a.begin() + i + N, a ); 
+4
source

Personally, I prefer to use std :: vector <> of boost :: shared_ptr (i.e. std :: vector> a, b).

Then you can use standard vector functions.

0
source

Source: https://habr.com/ru/post/1302840/


All Articles