Search code examples
c++boostembeddedkeil

what does the following bit of boost code do?


I'm trying to compile parts of the boost library for my STM32. I've used bcp to export the static_vector.

bcp boost/container/static_vector.hpp .

I can successfully compile the code and use a static_vector as per this code

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

But I need to disable this bit of code located inside boost\container\allocator_traits.hpp:467 before I can successfully compile.

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; }

When I don't disable that bit code the following error occurs:

../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; }

I'm using the following defines:

BOOST_NO_CXX11_RVALUE_REFERENCES BOOST_NO_ALIGNMENT BOOST_NO_TYPEID BOOST_NO_STD_LOCALE

And am using Keil µVision 5 with the "default arm compiler version 5". The boost library is version 1.58.

It seems to me that a definition of new is missing in this version of Keil. But I'm unable to determine what that bit of code does, let alone define my own version which fill that missing gap.

So what does that bit of code do and can I implement my own fix?


Solution

  • As commented by all above. This is the placement new operator.

    The problem is the version of boost. Version 1.65 (at least) has fixed this by changing

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

    into

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


    Side note on a comment: Keil does have an implementation inside <new> for the placement new operator but this isn't included by boost. Snippet from <new>:89

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