Why isn’t inplace_merge merging the strings in the code below?
string src = "abc";
string new_str = "def";
src += new_str;
inplace_merge(src.begin(), src.begin()+3, src.end());
cout << src; // abcdef
Edit: I expected “adbecf”
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It does work properly, but you have chosen bad test data.
std::inplace_mergedoes a merge on two sorted consecutive ranges in a sequence, like in a merge sort.That is, if you pass the string
adebcf(supposing the parameters are set as in your question), it will be merged intoabcdef.If you pass a string
abcdef, the result is the same as the input, because this string is already in order.