struct S
{
static std::vector<std::pair<int, int>> * comparisonLog;
int x;
S(int t_x) : x(t_x) { }
bool operator <(const S & t_other) const
{
comparisonLog->push_back({x, t_other.x});
return x < t_other.x;
}
};
std::vector<std::pair<int, int>> * S::comparisonLog;
//test
std::vector<std::pair<int, int>> referenceComparisons, studentComparisons;
const std::vector<S> values = { 1, 5, 4, 3, 2 };
S::comparisonLog = &referenceComparisons;
{
auto toSort = values;
std::sort(toSort.begin(), toSort.end());
}
S::comparisonLog = &studentComparisons;
{
auto toSort = values;
studentSort(toSort);
assert(std::is_sorted(toSort.begin(), toSort.end()));
}
assert(referenceComparisons == studentComparisons);