[cfe-dev] Transforming push_back(T(args, ...)) into emplace_back(args)

David Blaikie via cfe-dev cfe-dev at lists.llvm.org
Fri Apr 29 08:19:45 PDT 2016


Transformation as in clang-tidy? Or as in optimization in Clang? I doubt
the latter, but could imagine the former. I'm not sure if it's a
universally preferred transformation, though (but that's one of the
benefits of clang-tidy, it doesn't have to be)

On Thu, Apr 28, 2016 at 7:00 PM, Vedant Kumar via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hi all,
>
> It's common to see code which does this:
>
>   (1) V.push_back(T(args, ...));
>
> When it could do this instead:
>
>   (2) V.emplace_back(args, ...);
>
> IIUC, the copy constructor for T is never called in case (2).
>
> Would it be possible/worthwhile/correctness-preserving to perform this
> transformation in clang? Based on a cursory grep it doesn't seem like we do
> this today, but I could've missed something.
>
> thanks
> vedant
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160429/9e4a5fa6/attachment.html>


More information about the cfe-dev mailing list