Why is copy constructor called in call to std::vector::emplace_back()?

前端 未结 1 404
心在旅途
心在旅途 2021-01-03 19:53

It is my understanding that the purpose of std::vector::emplace_back() is specifically to avoid calling a copy constructor, and instead to cons

相关标签:
1条回答
  • 2021-01-03 20:32

    Visual Studio 2013 and earlier fails to write default move constructors for you. Add a simple explicit move constructor to stuff.

    A push or emplace back can cause stuff to be moved if it needs to reallocate, which in your case copies, as stuff has no move.

    It is a msvc bug.

    0 讨论(0)
提交回复
热议问题