有两个向量:std::vector<int> collA{2,4,6,3,5,7}
& std::vector<int> collB(collA.size())
,我正在尝试将collA
(包含偶数)的左半部分与collA
(包含奇数)的右半部分合并为collB
:
std::merge(collA.cbegin(), std::next(collA.cbegin(), collA.size()/2 + 1), // left source
std::next(collA.cbegin(), collA.size()/2), collA.cend(), // right source
collB.begin()); // Output
但是,std::merge()
在某处失败,Visual Studio 2012 给了我以下错误:
---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Debug Assertion Failed!
Program: C:\Windows\system32\MSVCP110D.dll
File: c:\program files (x86)\microsoft visual studio 11.0\vc\include\algorithm
Line: 3102
Expression: sequence not ordered
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
两个输入范围都已排序,为什么会出现此错误?(注:VS2012 不支持 C++11 初始化列表语法,我用的是节省一些空间)