Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does boost include two different versions of strong_typedef.hpp?

Tags:

c++

boost

As I was building a project recently, I noticed that I got a compiler warning (turned to error) about the BOOST_STRONG_TYPEDEF macro being redefined. Upon further investigation I noticed that there are two different versions of strong_typedef.hpp included in boost: One at the top level, and one within serialization/.

There is actually a difference between the two versions as well, not just a duplicate version of the macro. The top level version doesn't explicitly value-init its T while the serialization version does:

Code snips:

boost/strong_typedef.hpp:

    T t;                                                        \
    explicit D(const T t_) : t(t_) {};                          \
    D(){};                                                      \
    D(const D & t_) : t(t_.t){}                                 \

boost/serialization/strong_typedef.hpp:

    T t;                                                        \
    explicit D(const T t_) : t(t_) {};                          \
    D(): t() {};                                                \
    D(const D & t_) : t(t_.t){}                                 \

Why are there two different versions of the macro, and which one makes more sense as the implementation? The one that will force builtin types to be initialized, or the one that doesn't (as closely as possible mimicing the underlying type being strongly typedeffed)?

like image 223
Mark B Avatar asked Jun 03 '13 16:06

Mark B


1 Answers

I am the author of both versions of boost/strong_typedef.hpp.

Because of strident objections to inclusion to in the boost base header directly, I moved to the serialization library. In order to maintain backward compatibility, I left it in the boost base header directory. I forgot to merge this file into the release branch so the warning would appear. I also forgot to change the name to BOOST_SERIALIZATION_STRONG_TYPEDEF. And since then I added the initialization to the base class. I guess since I made the split, I included a correction in version in the serialization library.

I just looked at the serialization library and usage of strong_typedef is now minimal. I guess I'll get around to removing it entirely. So then it would be disappear entirely.

It really should be a separate utility. But I can't really deal with all that boost requires (tests, docs, build, review). And boost doesn't have a really good place for these small header only utilities. I had one day hoped that these small utilities that I needed for the serialization library would migrate to the the boost base. But I came to be discouraged from that idea.

like image 89
Robert Ramey Avatar answered Oct 19 '22 23:10

Robert Ramey