本文介绍了为什么boost包含两个不同版本的strong_typedef.hpp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

由于我最近正在建立一个项目,我注意到我有一个编译器警告(转向错误)关于重新定义的 BOOST_STRONG_TYPEDEF 宏。进一步调查我注意到有两个不同版本的 strong_typedef.hpp 包括在boost:一个在顶层,一个在序列化/ / code>。

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/.

这两个版本之间实际上有区别,不仅仅是宏的重复版本。顶层版本没有显式赋值 - 初始化它的 T ,而序列化版本:

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:

代码剪辑:

boost / strong_typedef.hpp

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


$ b b

boost / serialization / strong_typedef.hpp

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


$ b b

为什么有两个不同的版本的宏,哪一个更有意义的实现?这将强制内置类型被初始化,或者一个没有(尽可能模仿底层类型被强类型化)。

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

推荐答案

看起来 boost / strong_typedef.hpp 目录是一个历史文物。

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

缺少显式初始化 t 成员是一个错误修复在 boost / serialization / strong_typedef.hpp 几年前。请参阅。

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.

在Boost的Subversion中继线中,是一个很大的空文件,说:

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"

更改,r48575,2008年不知道为什么它从来没有被合并到一个版本。也许是因为它会打破用户没有很多的上升或也许是一个疏忽。同样的改变(r48575)是在trunk中创建 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.

如果他们不想破坏现有用户,那么也许已弃用的文件应该包含 boost / serialization 所以有一个单一的,规范的实现。在任何情况下,似乎如果你可以避免使用 boost / strong_typedef.hpp 赞成使用序列化

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.

注意,记住一年前Boost Serialization的作者(和 strong_typedef.hpp ),Bob Ramey,大约 strong_typedef.hpp 您可能会感兴趣:

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:

这篇关于为什么boost包含两个不同版本的strong_typedef.hpp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 22:33