c++ - Boost Intrusive unordered_set 在 C++11 模式下使用 GCC 在 1.48 中被破坏

标签 c++ gcc boost c++11 intrusive-containers

如果您对 GCC 4.7 和 Boost 1.48 附带的 Fedora 17 进行普通安装,并使用 C++11 模式,Boost Intrusive 的 unordered_set 会被破坏。在 GCC 4.6.2 和 Boost 1.47 附带的 Fedora 16 上,它可以工作。这破坏了真正的代码,甚至破坏了 official documentation 中的示例。 :

#include <boost/intrusive/unordered_set.hpp>

using namespace boost::intrusive;

struct MyClass : public unordered_set_base_hook<>
{};

typedef unordered_set<MyClass>::bucket_type   bucket_type;
typedef unordered_set<MyClass>::bucket_traits bucket_traits2;

int main()
{
   bucket_type buckets[100];
   unordered_set<MyClass> uset(bucket_traits2(buckets, 100)); // FAILS
}

错误信息:

/usr/include/boost/intrusive/hashtable.hpp:227:65: 错误:使用删除的函数 'constexpr boost::intrusive::detail::bucket_traits_impl >::type>::bucket_traits_impl(const boost: :intrusive::detail::bucket_traits_impl >::type>&)'

在/usr/include/boost/intrusive/hashtable.hpp:30:0 包含的文件中, 来自/usr/include/boost/intrusive/unordered_set.hpp:18, 来自 t.cpp:23:

/usr/include/boost/intrusive/detail/hashtable_node.hpp:80:8: 注意:'constexpr boost::intrusive::detail::bucket_traits_impl >::type>::bucket_traits_impl(const boost::intrusive::detail::bucket_traits_impl >::type>&)' 被隐式声明为已删除,因为'boost::intrusive::detail::bucket_traits_impl >::type>' 声明了移动构造函数或移动赋值运算符

这里是它引用的代码,hashtable.hpp:227:

template<class BucketTraits>
bucket_plus_size(BOOST_FWD_REF(BucketTraits) b_traits)
   : bucket_traits_(::boost::forward<BucketTraits>(b_traits))
{}

在 Boost 1.47 中,这是:

bucket_plus_size(const bucket_traits &b_traits)
   : bucket_traits_(b_traits)
{}                 

BOOST_FWD_REF(TYPE) 在我的系统上默认定义为 TYPE &&,但是如果定义了 BOOST_NO_RVALUE_REFERENCES 那么它就变成了 常量类型 &。如果我确实那样定义它,代码就会编译!

关于这是为什么的任何想法?是 GCC、Boost、Fedora 还是我的错?

最佳答案

这看起来与 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53234 中描述的问题相同

即Boost 1.48 采用 GCC 4.6 的旧行为,但 GCC 4.7 已更改为实现关于隐式定义的复制/移动构造函数的正确 C++11 语义。

关于c++ - Boost Intrusive unordered_set 在 C++11 模式下使用 GCC 在 1.48 中被破坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10440860/

相关文章:

Android:链接到预建的静态库

macos - 在 ghci 或 ghc 中使用 gcc 而不是 clang

c - 释放内存/跨平台兼容性问题

C++ : Seeding mt的低32位包含什么

c++ - 在 C++ 中以精度 2 打印 float 但不带小数点 (.)

c++ - 什么可能导致 DefWindowProc 停止处理消息?

c++ - 标准如何定义运行时绑定(bind)数组的捕获?

c - 这个 c 程序在 windows 中工作正常但在 Linux 中不工作

c++ - 禁用 boost 的 `progress_display` 输出

c++ - 使用 boost::bind 时出错