boostorg / serialization

Boost.org serialization module
http://boost.org/libs/serialization
120 stars 139 forks source link

Archive iterator to use algorithms to populate archives #273

Closed correaa closed 1 year ago

correaa commented 1 year ago

I wonder if something like this exists already, the analogue to std::ostream_iterator but for Archives.

I find myself doing this often:

    package_oarchive poa(p);
    while(count--) { poa << *first++; }

with a hypothetical boost::serialization::oarchive_iterator I could use a proper algorithm for this.

    package_oarchive poa(p);
    std::copy_n(first, count, boost::serialization::oarchive_iterator<>(poa));

Please let me know if it exists already, or if someone else ever needed something like this.

Ideally, I wish I could reuse std::ostream_iterator for this, but its constructors only accept things derived from std::ostream& and not Boost Serialization Archives.

For what it is worth I propose adding it to the library. The implementation is relatively easy to layout, but there are a lot of design details to discuss.

robertramey commented 1 year ago

I would think it would be almost trivial to implement. (Famous last words!) If you want to do this then ask me to include it in the library I will look at it. A couple of notes:

a) if you're going to to oarchive_iterator, you should do archive_iterator as well. b) it should work for all archives c) needs a test d) needs an update to the documentation.

So even a "trivial" entails a lot of work. If I can accept I will. You'll get full credit in the appropriate places. Might be a nice addition to your resume