[Development] QVector now has rvalue push_back

Julien Blanc julien.blanc at nmc-company.com
Wed Jul 22 09:09:50 CEST 2015


Le mardi 21 juillet 2015 à 19:00 +0200, Gunnar Roth a écrit :
> Hello,
> Out of curiosity i just looked at the Xcode 6.4 headers for the
> implementation of std::vector::emplace_back,
> and i don’t think there is any difference between
> push_back(QPen(Qt::red,1.5f)) and emplace_back(Qt::red,1,5f))
> 
> 
> The implementation is like this:
>     template <class... _Args>
>     _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args)
>         { push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); }

> Am i wrong?

That’s a suboptimal but valid implementation (there’s no requirement
about not constructing a temporary object in the C++11 standard).

gnu stl does the opposite : implement push_back in terms of
emplace_back, which is better.

Regards,

Julien Blanc 




More information about the Development mailing list