I am trying to make a copy of a vector of string and append it to the end of its original vector, i.e. duplicating its contents. Example:
Input : vector<string> s = {"abc", "def"}
Output: vector<string> s = {"abc", "def", "abc", "def"}
I was using the insert method, i.e.
s.insert(s.end(), s.begin(), s.end());
However, this exhibits compiler-dependent results. In, LLVM clang, it gave me the expected answer.
With GCC it gave me
Output: vector<string> s = {"abc", "def", "", ""}
I am wondering why this happens and what's the safest way to achieve this vector duplication goal?
Here is the ideone.com link for the program above: http://ideone.com/40CH8q