When we need to fill std::vector with values and the size of vector is known in advance, there are two possibilities: using emplace_back() or using operator[]. For the emplace_back() we should reserve the necessary amount of space with reserve() before emplacing into vector. This will avoid unnecessary vector regrow and benefit performance. Alternatively, if we…
![What is faster: vec.emplace_back(x) or vec[x] ?](https://johnnysswlab.com/wp-content/uploads/1_X_4r58mARIdCdTRz14Eraw.jpeg)