I want to fill a std::vector
with another vector
. For example:
std::vector<int> src = {1, 2, 3};
std::vector<int> dst(9);
I want to fill dst to make it become: 1, 2, 3, 1, 2, 3, 1, 2, 3
Is there an efficient method to do this?
I have two methods now:
The first is two loop:
for (int i = 0; i < dst.size() / src.size(); i++) {
for (int val : src) {
dst.emplace_back(val);
}
}
Or use the std::copy
in one loop.
Maybe exist a more efficient method?
Aucun commentaire:
Enregistrer un commentaire