c++ - why are there two std::allocator::construct functions? -


the standard gives 2 construct functions in std::allocator<t> placement new syntax underneath:

void construct( pointer p, const_reference val );  (1)  (until c++11)  template< class u, class... args > void construct( u* p, args&&... args );            (2)  (since c++11)  1) calls new((void *)p) t(val) 2) calls ::new((void *)p) u(std::forward<args>(args)...)  

whats difference between 1) , 2) except fact forward arguments constructor in 2) reason need 1)?

imagine have signature 2) , passing argument (non-existing) first 1 result in calling:

::new((void *)p) t(std::forward<const_reference>val)  

which should call copy constructor t(val) anyway? here, asking me whats point of having additional signature 1)? there difference 1 calls new other 1 global function ::new

thanks shining light in :-)

the answer in excerpts posted: 1 pre-c++11 , 1 post-c++11. construct best expressed perfect-forwarding arguments rather calling copy-constructor, perfect-forwarding available in c++11, had make first option before reality.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -