2012-05-03 75 views
3

如果您執行GCC 4.7和Boost 1.48附帶的Fedora 17的vanilla安裝並使用C++ 11模式,則Boost Intrusive的unordered_set會中斷。在GCC 4.6.2和Boost 1.47的Fedora 16上,它工作正常。這打破了真正的代碼,它甚至打破在official documentation的例子:Boost Intrusive unordered_set在C++ 11模式下使用GCC在1.48中破解

#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升壓::侵入::詳細:: bucket_traits_impl> ::類型> :: bucket_traits_impl(常量升壓::侵入::詳細:: bucket_traits_impl> ::類型> &)'

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

/usr/include/boost/intrusive/detail/hashtable_node.hpp:80:8:note:'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)) 
{} 

在升壓1.47,這是:

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

我的系統上BOOST_FWD_REF(TYPE)被定義爲TYPE &&默認,但如果BOOST_NO_RVALUE_REFERENCES定義則變得const TYPE &。如果我這樣定義它,代碼編譯!

想到這是爲什麼?是GCC的錯,Boost的,Fedora的還是我的?

+2

如果是已經修復的侵入(或配置)錯誤,一個好的開始是使用Boost 1.49.0進行測試。 – ildjarn

+0

我使用Boost 1.49和GCC 4.7.0(與OP中的相同)對它進行了測試,並且它可以工作,但這是在Mac OS上而不是在Fedora上。 –

+0

Boost 1.48中intrusive :: unordered_set的第二個問題是BOOST_FOREACH失敗。我想知道Fedora包維護人員是否應該考慮在Boost的config.hpp中定義BOOST_NO_RVALUE_REFERENCES,以便其他人不必這樣做。 –

回答