简体   繁体   中英

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

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)?

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.

It looks like boost/strong_typedef.hpp directory is a historical artifact.

The lack of explicit initialization of the t member was a bug fixed in boost/serialization/strong_typedef.hpp a couple years ago in svn revision 71183. See the bug ticket .

In Boost's Subversion trunk, boost/strong_typedef.hpp is a largely empty file that says:

#error "This header is deprecated. Please use: boost/serialization/strong_typedef.hpp"

That change, r48575, was made back in 2008 - I don't know why it has never been merged into a release. Maybe because it would break users without a lot of upside or maybe it's an oversight. That same change (r48575) was what created boost/serialization/strong_typedef.hpp in trunk.

If they don't want to break existing users, then maybe the deprecated file should just include the file in boost/serialization so there's a single, canonical implementation. In any case, it would appear that if you can avoid using boost/strong_typedef.hpp in favor of using the one in serialization , that's what I'd suggest.

As a side note, keep in mind that a year ago the author of Boost Serialization (and strong_typedef.hpp ), Bob Ramey, posted a comment in another bug ticket about strong_typedef.hpp that you might find interesting:

I don't think the serialization library uses this any more. Of course it's still in there. I have no idea if anyone uses it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM