On Tuesday 21 July 2015 09:09:36 Julien Blanc wrote: > > The templateness changes how a type different than the vector's type gets > > constructed (it might undergo a conversion first). > > Not sure i understand you well there. The variadic and templateness > changes it so that no temporary gets constructed at all, object is > constructed in-place with a call to a placement new and T’s constructor > with provided arguments. > > > But assuming I am pushing > > back a T, is there any reason I'd want emplace_back? Or vice-versa? > > emplace_back is really designed to avoid the creation of a temporary > object, so, passing a T to it shouldn’t make any difference : that woul
I'm asking why one of the two would be better than the other if I'm trying to add a single T to std::vector<T>. You've explained that emplace_back is efficient, but you haven't said whether push_back is as efficient, more efficient or less efficient than that. emplace_back will do perfect forwarding without copy direct into the vector. Does push_back do the same? -- Thiago Macieira - thiago.macieira (AT) intel.com Software Architect - Intel Open Source Technology Center _______________________________________________ Development mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/development
