且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

添加到C ++中的集合之前或之后

更新时间:2023-12-03 18:46:40

当复制构造函数/较小。如果你正在生成数据,很可能会增加复杂性,在生成之前插入。

Add it when the complexity of copy constructor/operator == is smaller. If you are generating data, most likely increasing that complexity, insert before generating.

如果你有很多矢量拷贝,并且关注性能,我的建议是有一个向量的指针和 new (当然还有一天 delete )对象,并将它们放在向量中。这样,插入向量的成本不取决于对象的复杂性。

If you have many vector copies and you are concerned about performance, my suggestion is to have a vector of pointers and new (and of course one day delete) the objects and put them in the vector. That way, the cost of inserting in vector is not dependent on the complexity of the object.