From 801cbea9cce1e04e6921bb087add8206cffe1fe1 Mon Sep 17 00:00:00 2001 From: glx Date: Fri, 12 Apr 2019 01:28:11 +0200 Subject: Codechange: use std::sort() for all std::vector types --- src/timetable_cmd.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/timetable_cmd.cpp') diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp index 4ab7c746f..2b2de28a9 100644 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -216,15 +216,12 @@ CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1, * Order vehicles based on their timetable. The vehicles will be sorted in order * they would reach the first station. * - * @param ap First Vehicle pointer. - * @param bp Second Vehicle pointer. + * @param a First Vehicle pointer. + * @param b Second Vehicle pointer. * @return Comparison value. */ -static int CDECL VehicleTimetableSorter(Vehicle * const *ap, Vehicle * const *bp) +static bool VehicleTimetableSorter(Vehicle * const &a, Vehicle * const &b) { - const Vehicle *a = *ap; - const Vehicle *b = *bp; - VehicleOrderID a_order = a->cur_real_order_index; VehicleOrderID b_order = b->cur_real_order_index; int j = (int)b_order - (int)a_order; @@ -242,15 +239,15 @@ static int CDECL VehicleTimetableSorter(Vehicle * const *ap, Vehicle * const *bp /* First check the order index that accounted for loading, then just the raw one. */ int i = (int)b_order - (int)a_order; - if (i != 0) return i; - if (j != 0) return j; + if (i != 0) return i < 0; + if (j != 0) return j < 0; /* Look at the time we spent in this order; the higher, the closer to its destination. */ i = b->current_order_time - a->current_order_time; - if (i != 0) return i; + if (i != 0) return i < 0; /* If all else is equal, use some unique index to sort it the same way. */ - return b->unitnumber - a->unitnumber; + return b->unitnumber < a->unitnumber; } /** @@ -295,7 +292,7 @@ CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1, int num_vehs = (uint)vehs.size(); if (num_vehs >= 2) { - QSortT(vehs.data(), vehs.size(), &VehicleTimetableSorter); + std::sort(vehs.begin(), vehs.end(), &VehicleTimetableSorter); } int idx = vehs.begin() - std::find(vehs.begin(), vehs.end(), v); -- cgit v1.2.3-54-g00ecf