如果您对 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/