以下示例在使用GCC 4.4.6時使用--std = C++ 0x標誌進行編譯,但無法在C++ 03中進行編譯模式。boost :: container :: vector無法使用C++ 03編譯器進行編譯
#include <stdint.h>
#include <boost/container/vector.hpp>
struct data
{
int i_;
boost::container::vector<data> v_;
};
int main(int argc, char** argv)
{
data myData;
myData.i_ = 10;
data myData2;
myData2.i_ = 30;
myData.v_.push_back(myData2);
return 0;
}
它與
g++ --std=c++0x test-cont.cpp
但是編譯成功,如果我刪除--std=c++0x
我收到以下錯誤: G ++測試cont.cpp 在文件從 包括/ C++/4.4.6包括/存儲器:49, 升壓/容器/ container_fwd.hpp:36, 升壓/容器/ vector.hpp:20, 從測試cont.cpp:2:
include/c++/4.4.6/bits/stl_algobase.h: In static member function
static _OI std::__copy_move<false, false, std::random_access_iterator_tag>::
__copy_m(_II, _II, _OI) [with _II =
boost::container::constant_iterator<data, long int>, _OI = data*]:
include/c++/4.4.6/bits/stl_algobase.h:397: instantiated from
_OI std::__copy_move_a(_II, _II, _OI)
[with bool _IsMove = false,
_II = boost::container::constant_iterator<data, long int>, _OI = data*]
include/c++/4.4.6/bits/stl_algobase.h:436: instantiated from
_OI std::__copy_move_a2(_II, _II, _OI)
[with bool _IsMove = false,
_II = boost::container::constant_iterator<data, long int>, _OI = data*]
include/c++/4.4.6/bits/stl_algobase.h:468: instantiated from
_OI std::copy(_II, _II, _OI)
[with _II = boost::container::constant_iterator<data, long int>, _OI = data*]
boost/move/move.hpp:1147: instantiated from
boost::copy_or_move(I, I, F,
typename boost::move_detail::disable_if< boost::move_detail::is_move_iterator<I>, void>::type*)
[with I = boost::container::constant_iterator<data, long int>, F = data*]
boost/container/detail/advanced_insert_int.hpp:58: instantiated from
void boost::container::container_detail::advanced_insert_aux_proxy<A, FwdIt, Iterator>::copy_remaining_to(Iterator)
[with A = std::allocator<data>, FwdIt = boost::container::constant_iterator<data, long int>, Iterator = data*]
test-cont.cpp:21: instantiated from here
include/c++/4.4.6/bits/stl_algobase.h:343: error:
no match for operator= in * __result =
__first.boost::container::constant_iterator<T, Difference>::operator*
[with T = data, Difference = long int]()
test-cont.cpp:5: note: candidates are: data& data::operator=(data&)
它看起來像boost :: container :: vector需要move
語義,我認爲它會自動使用boost::move
編譯時使用C++ 03編譯器。
如果我手動修改struct data
定義:
- 默認的構造函數
- 拷貝構造函數
- 賦值運算符
- 使用BOOST_RV_REF
- 一個模擬移動分配的模擬移動構造函數運營商使用BOOST_RV_REF
該示例編譯。
必須爲C++ 03手動添加這些移動/複製構造函數和賦值運算符是很費力的。
這是一個缺陷boost::container
?如果是的話,向助推社區報告的最佳方式是什麼?
問題是什麼?我懷疑這是更好的針對助推社區 - 看起來像一個錯誤。 – marko
@Marko看起來像你的寫,因爲手動添加仿真移動語義使代碼編譯。 – mark