Serializing containers of movable but noncopyable types
While attempting to serialize a std::vector<T>, where T is a movable but noncopyable type, I was getting blown up by the call to s.push_back() on line 65 of collections_load_imp.hpp (Boost 1.53.0). In my local copy of that header I changed s.push_back(t.reference()) to s.push_back(std::move(t.reference())). Is this a safe change? Is there a better way to handle this case?
Daniel Mitchell wrote:
While attempting to serialize a std::vector<T>, where T is a movable but noncopyable type, I was getting blown up by the call to s.push_back() on line 65 of collections_load_imp.hpp (Boost 1.53.0).
In my local copy of that header I changed s.push_back(t.reference()) to s.push_back(std::move(t.reference())). Is this a safe change? Is there a better way to handle this case?
Hmmm - When I look at the type requirements for the vector class: http://www.sgi.com/tech/stl/Vector.html http://www.sgi.com/tech/stl/Sequence.html http://www.sgi.com/tech/stl/Container.html http://www.sgi.com/tech/stl/Assignable.html I see that items in vectors must be assignable and that assignable means "copyable". I realize that this information might now be out of date, but since I use the weakest common denominator of type requirements to diminish portability problems, that's what I use. I'm sure someone might have something more useful to add here. Robert Ramey
On Jul 1, 2013, at 11:21 AM, "Robert Ramey"
Daniel Mitchell wrote:
While attempting to serialize a std::vector<T>, where T is a movable but noncopyable type, I was getting blown up by the call to s.push_back() on line 65 of collections_load_imp.hpp (Boost 1.53.0).
In my local copy of that header I changed s.push_back(t.reference()) to s.push_back(std::move(t.reference())). Is this a safe change? Is there a better way to handle this case?
Hmmm -
When I look at the type requirements for the vector class:
http://www.sgi.com/tech/stl/Vector.html http://www.sgi.com/tech/stl/Sequence.html http://www.sgi.com/tech/stl/Container.html http://www.sgi.com/tech/stl/Assignable.html
I see that items in vectors must be assignable and that assignable means "copyable".
I realize that this information might now be out of date, but since I use the weakest common denominator of type requirements to diminish portability problems, that's what I use.
I'm sure someone might have something more useful to add here.
Robert Ramey
I've found that I can work around this by using array optimization on my vectors.
participants (2)
-
Daniel Mitchell
-
Robert Ramey