performance - C++ emplace_back parameters -


here piece of code in daily work. want ask if there difference between 2 cases, in terms of performance.

std::vector< std::pair<std::string, std::string> > avec;  // case 1 avec.emplace_back("hello", "bonjour");  // case 2 avec.emplace_back(std::pair("hello", "bonjour")); 

following question:

what std::list these 2 cases?

emplace_back construct element in-place, argument passed in perfect-forwarded constructor element.

for 1st case, conceptually 1 step needed, i.e. appropriate constructor of std::pair invoked construct element directly in vector.

for 2nd case, 3 steps needed; (1) appropriate constructor invoked construct temporary std::pair, (2) element move constructed in vector in-place temporary std::pair, (3) temporary std::pair destroyed.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -