簡體   English   中英

下面的Boost代碼有什么作用?

[英]what does the following bit of boost code do?

我正在嘗試為我的STM32編譯boost庫的某些部分。 我已經使用bcp導出static_vector

bcp boost/container/static_vector.hpp .

我可以成功編譯代碼並按照此代碼使用static_vector

boost::container::static_vector<int,10> vec;

但是我需要先禁用位於boost\\container\\allocator_traits.hpp:467這段代碼,然后才能成功進行編譯。

template<class T>
   static void priv_construct_dispatch_next(container_detail::false_type, Allocator &, T *p, const ::boost::container::default_init_t&)
   {  ::new((void*)p) T; }

當我不禁用該位代碼時,會發生以下錯誤:

../Inc/boost/container/allocator_traits.hpp(469): error:  #384: no instance of overloaded "operator new"  matches the argument list
            argument types are: (unsigned int, void *)
     {  ::new((void*)p) T; }

我正在使用以下定義:

BOOST_NO_CXX11_RVALUE_REFERENCES BOOST_NO_ALIGNMENT BOOST_NO_TYPEID BOOST_NO_STD_LOCALE

並且正在將Keil µVision 5與“默認的arm編譯器版本5”一起使用。 Boost庫是1.58版。

在我看來,此版本的Keil中缺少對new的定義。 但是我無法確定代碼的功能,更不用說定義我自己的版本了,以填補缺失的空白。

那么,那段代碼是做什么的,我可以實施自己的修復程序嗎?

正如以上所有評論。 這是放置新運算符

問題是boost的版本。 1.65版(至少)已通過更改來解決此問題

{  ::new((void*)p) T; }

{  ::new((void*)p, boost_container_new_t()) T; }


注釋上的旁注:Keil在<new>內確實有一個位置new運算符的實現,但boost不包含此實現。 摘錄自<new>:89

/* Placement new. */
inline void *operator new(std::size_t, void* __ptr) throw() { return __ptr; }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM