can you do this in C++:
vector<int> v1={1,2}, v2={3,4};
vector<int> v3={...v1, ...v2, 5};
//v3 = {1,2,3,4,5}
What is the simplest way to do this with C++ ?
>Solution :
No spread operator in C++.
Probably the simplest way would be a sequence of inserts
std::vector<int> v3;
v3.insert(v3.end(), v1.begin(), v1.end());
v3.insert(v3.end(), v2.begin(), v2.end());
v3.insert(v3.end(), 5);
Various range libraries have a concat function
auto v3 = ranges::views::concat(v1, v2, { 5 }) |
ranges::views::join |
ranges::views::to<vector>;
C++23 or ranges::v3. Still more verbose than spread operator.