下面的 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 和 "default arm compiler version 5"。 boost 库是 1.58 版本。

在我看来,这个版本的 Keil 中缺少 new 的定义。但是我无法确定那段代码的作用,更不用说定义我自己的版本来填补那个缺失的空白了。

那段代码有什么作用,我可以实施自己的修复吗?

正如上面所有评论的那样。这是placement new operator

问题出在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; }