Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6799411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:50:44+00:00 2026-05-26T18:50:44+00:00

I am using boost::variant and boost::serialize in my application. The serialization module has built

  • 0

I am using boost::variant and boost::serialize in my application. The serialization module has built in support for serializing variants, so:

boost::variant<int,double> u(3.14);

// Do something with u;

// Serialize
oa << u;

works. However, my problem is that the serialization is not robust. Depending on how my application is compiled the elements of the variant may change. Currently the serialization module appears to be simply embedding the index of the ‘active’ variant type; which is an issue if the variant changed to, say, boost::variant<double,string>.

Can anyone suggest ways of improving this so that the serialization/un-serialization works so as the type that has been serialized is a template parameter of the boost::variant. (So, in the above case boost::variant<int,double> u(3.14) could be un-serialized to a boost::variant<double,std::string>. I am aware this may require me to provide additional information such as a stringified form of the type.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:50:44+00:00Added an answer on May 26, 2026 at 6:50 pm

    How would an off-the-shelf mechanism for such a thing work? For instance, what should it do if you changed boost::variant<int,double> to boost::variant<int,std::string> and can no longer hold a double? Throw an exception?

    If you want something like that I’d imagine you’d have to write it yourself to cover the cases you’re anticipating and fit your definition of “robust”.

    You might also build in some file upgrading logic…for instance every version N of your program keeps around old copies of the definitions of structures for (N-1, N-2…) so that you’re able to write routines that can be used in offering the ability to upgrade old files it encounters.

    But really, it’s best to get your file formats right the first time as much as possible, before you let the program out into the wild! Especially the data encoding the user’s intent (derived structures that are effectively just caches can be thrown away and recomputed if a version doesn’t recognize them).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a boost variant of looking like this: typedef boost::variant<int, float, double, long,
I'm using boost::asio, and I have code like this: void CServer::Start(int port) { tcp::acceptor
I faced a problem using a Boost variant. I have a segmentation fault when
I'm implementing a variant class (not using boost) and I'm wondering how you'd handle
im just installing the boost library using an installer. Its asking me which variants
typedef boost::variant<long long,double,string> possibleTypes ; set<possibleTypes,less<possibleTypes> > ascSet ; set<possibleTypes,greater<possibleTypes> > descSet ; When
I'm attempting to create a list of objects using the variant boost. #include <string>
I can't find a proper way how to access members of boost::variant using boost::phoenix
I am using boost recursive variant to store the variant data which I want
I'm using the library boost::variant to store a large number of types. As the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.