Are you asking if you can push a map into a vector?
A simple code example might help. It's difficult interpreting what you are asking.
Consider the 'scope' class from here:
Confusing Template error
I have some global objects of that type.
Wouldn't it be bad to do the following and expect the map at the back() to be valid at a different scope?
Code:std::map<std::string,std::string > m = {{"foo","bar"},{"xip","bas"}}; global_object.new_local(m);
No.
Why? Because a vector follows an invariant. Whatever you push into that vector must be valid until that element is destroyed or the vector is destroyed.
Since you push a map into it, it will remain valid until one of those conditions are met.
This is implemented by a container copying whatever you push into its own storage (hence you need proper copy semantics).
This is no different from when pushing integers or strings into a vector.
Beware of pointers, though. Since the value is copied, only the pointer's value persists.
If you delete what it points to, the pointer will point to an invalid object. But that is a user error, not an error in the vector invariant. It does its job as it should.
Thanks.. that makes my work a bit simpler.
(Any special kind of copy/move bug I've to be aware about when changing dynamically containers to 'normal' ones ...in this case ?)
Yes I am.
Because it still does not manage memory. STL uses an allocator: there are a few standard ones such as alloc.Then why is it said that C++ does not automatically manage memory ?
(I've almost never delete `d a container....and AFAIK..that is a common practice)
The only exception that I know about is std::array, which can be implemented in such a way that it has a do-nothing destructor.
Last edited by whiteflags; 12-01-2011 at 08:42 PM.