Skip to content

std_variant serialization does not instantiate variant alternatives via boost::serialization::access #338

@KJTsanaktsidis

Description

@KJTsanaktsidis

I have a variant that has some alternatives which do not have public default constructors. They do have private default constructors though, and are friended to boost::serialization::access. However, the variant serializer in boost/serialization/std_variant.hpp can't construct these types.

I wonder if the variant serializaer should, instead of this:

Do something along the lines of

alignas(type) unsigned char value_storage[sizeof(type)];
type *value_ptr = reinterpret_cast<type *>(value_storage);
access::construct(value_ptr);
std::experimental::scope_exit cleanup([&]() { access::destroy(value_ptr) };

ar >> BOOST_SERIALIZATION_NVP(*value_ptr);
v = std::move(*value_ptr);

If this sounds right I can send a PR. thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions