Are there any cases where it is incorrect to replace push_back with emplace_back?

前端 未结 6 1474
不思量自难忘°
不思量自难忘° 2021-01-02 09:44

Can I break a valid C++03 program by replacing std::vector::push_back with emplace_back and compiling it with C++ 11 compiler? From reading e

6条回答
  •  长情又很酷
    2021-01-02 10:22

    If you don't have crazy side-effects in copy constructor of the objects that you hold in your vector, then no.

    emplace_back was introduced to optimise-out unnecessary copying and moving.

提交回复
热议问题