0

Consider this snippet:

#include <vector>

struct A
{
   A(int b): m_b(b) { }

private:
   int m_b;
};

int main()
{
    std::vector<A> vec;

    vec.push_back( A(3) );

    vec.emplace_back( 3 );
}

In that particular case where a temporary value is passed, is there any difference between the 2 calls that a compiler won’t optimize away? Should I prefer one to the other?

qdii
  • 12,505
  • 10
  • 59
  • 116

0 Answers0