1

I have a large std::vector<X> where X is a structure with a serialize function for Boost.

I would like to serialize only part (a contiguous segment) of this vector in such a way that deserializing the result would give me an std::vector<X> with just the elements I serialized.

I can provide iterators pointing to the beginning and the end of the segment I want to serialize, or I can provide begin and end indices. Is there a way to do that without creating a smaller vector and copying the desired elements in it?

Note that I am using binary archives so any solution that would work only for this type of archive is fine.

Michael Kemmerzell
  • 4,115
  • 4
  • 23
  • 38
sunmat
  • 6,271
  • 3
  • 26
  • 41

1 Answers1

0

Using std::valarray(https://en.cppreference.com/w/cpp/numeric/valarray) is the way to go here. Coincidentally, boost serialization supports valarray as well, so you're good to go. Here's a comparison btw std::vector and std::valarray for clarity's sake: C++ valarray vs. vector

theWiseBro
  • 1,331
  • 8
  • 8