Peter Hu Peter Hu - 3 months ago 43
C++ Question

c++ inplace_merge expression: sequence not ordered

The following codes work for some data file, but for some other data files it didn't work, the following screen displayed:

enter image description here

Anyone can help to resolve this problem?

if (
int s = parsed_contents.size();
parsed_contents += QString(file.readAll()).split("\n").filter(datestr);
std::inplace_merge (parsed_contents.begin(), parsed_contents.begin() + s, parsed_contents.end(), [&](const QString &a, const QString &b) -> bool
QDateTime dt_a = (dt.indexIn(a) != -1)?QDateTime().fromString(dt.cap(2) + "-" + year + " " + dt.cap(3), "MM-dd-yyyy hh:mm:ss:zzz"):QDateTime();
QDateTime dt_b = (dt.indexIn(b) != -1)?QDateTime().fromString(dt.cap(2) + "-" + year + " " + dt.cap(3), "MM-dd-yyyy hh:mm:ss:zzz"):QDateTime();

return dt_a < dt_b;

lcs lcs

One of the pre-requisites for std::inplace_merge is that the data already be sequenced (in order).

The elements in both ranges shall already be ordered according to this same criterion (operator< or comp). The resulting range is also sorted according to this.

You need to sort your lists according to the same operator< prior to merging.