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

  • Home
  • SEARCH
  • 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 7533171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:39:49+00:00 2026-05-30T05:39:49+00:00

Consider a structure to serialize: struct MyStruct { int a; std::string b; template<class Archive>

  • 0

Consider a structure to serialize:

struct MyStruct {
   int a;
   std::string b;

template<class Archive>
void serialize(Archive &ar, const unsigned int)
   {
   ar & a & b;
   }
};

I want to explicitly tag it, using boost::serialization::traits, to be both track_never and object_serializable. I’ve stared at the traits docs, but can’t seem to get my mind around how to apply it, and can’t find an example anywhere. So…

a) What’s the code that applies traits to this particular class?

b) What’s the BOOST_STATIC_ASSERT() that verifies each is in place?

c) I assume I can’t make this class primitive_type since there’s no member function or template in a typical archive class that can handle this type directly. Correct?

I don’t care about cross-platform or cross-version archive compatibility, just fast reads (and writes) and intruding on MyStruct is OK, but it would be nice to see it done both ways if possible.

  • 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-30T05:39:51+00:00Added an answer on May 30, 2026 at 5:39 am

    Since MyStruct is not a templatized struct or class to apply the the traits all you need to do is use the BOOST_CLASS_IMPLEMENTATION and BOOST_CLASS_TRACKING macros:

    Outside of your class definition you’d need to write the following two lines:

    BOOST_CLASS_IMPLEMENTATION(MyStruct, boost::serialization::object_serializable);
    BOOST_CLASS_TRACKING(MyStruct, boost::serialization::track_never);
    

    A BOOST_STATIC_ASSERT() to verify you’re doing the right thing looks like:

    BOOST_STATIC_ASSERT(boost::serialization::implementation_level<MyStruct>::value 
                        == boost::serialization::object_serializable);
    BOOST_STATIC_ASSERT(boost::serialization::tracking_level<MyStruct>::value 
                        == boost::serialization::track_never);
    

    I would say it doesn’t make sense to make this a primitive type because its not a primitive type.

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

Sidebar

Related Questions

Consider the following class structure: class Filter { virtual void filter() = 0; virtual
Consider the following class structure: public class Foo<T> { public virtual void DoSomething() {
Consider the following data structure: List<Person> People; class Person { List<Car> Cars; List<Hobby> Hobbies;
Consider the following structure: <ul> <li><a href=>Home</a><img src=menu_hover_line.jpg class=whiteBarHover /></li> <li><a href=>Contacts</a><img src=menu_hover_line.jpg class=whiteBarHover
Consider the following HTML structure: <div class=content> <div class=field field-type-date field-field-event-date> <div class=field-items> <div
Consider following structure where the length of both username and password is 17: struct
consider the following html structure: <div> <div class=top> <div id=id1>123</div> <div> <div class=top> <div
Consider the following HTML structure for drop-down menu: <ul class=tabMenu> <li><a href=#>Games</a> <div id=sub>
Consider these as my table structure class Physician < ActiveRecord::Base has_many :appointments has_many :patients,
Situation Consider I've got the following class structure: // a user model class UserModel

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.