//Purpose: // Explore how to minimize space taken by struct of // optionals. //Reference: // // http://article.gmane.org/gmane.comp.lib.boost.devel/209212 // #include #include #include struct A { int a; double b; double c; std::string d; }; struct B { boost::optional< int > a; boost::optional< double > b; boost::optional< double > c; boost::optional< std::string > d; }; struct Atags { int a; bool ta; double b; bool tb; double c; bool tc; std::string d; bool td; }; struct tagsA { bool ta; int a; bool tb; double b; bool tc; double c; bool td; std::string d; }; struct A_bools { int a; double b; double c; std::string d; bool ta; bool tb; bool tc; bool td; }; struct bools{ bool ta; bool tb; bool tc; bool td; }; struct bools_A { bool ta; bool tb; bool tc; bool td; //bool te; //uncomment this, and sizeof(bools_A) jumps by alignment_of::value. int a; double b; double c; std::string d; }; int main(void) { std::cout<<"alignment_of::value="<::value<<"\n"; std::cout<<"sizeof(A)="<::value="<::value<<"\n"; return 0; }