std::sort
is not guaranteed to be stable.
Is it guaranteed to be deterministic though?
For example, will this code always print 1
?
struct S
{
int a, b;
};
bool cmp(const S& lhs, const S& rhs)
{
return lhs.a < rhs.a;
}
int main()
{
std::vector<S> seq1 = {{1, 2}, {1, 3}};
std::vector<S> seq2 = seq1;
std::sort(seq1.begin(), seq1.end(), cmp);
std::sort(seq2.begin(), seq2.end(), cmp);
std::cout << (seq1.back().b == seq2.back().b) << '\n';
}
Also, is C++ standard library deterministic in general (apart from obviously indeterministic elements, like RNG and clocks)?