Loading

convertsort.diff

  1. diff --git a/source.list b/source.list
  2. index df35cdd26..888578b4b 100644
  3. --- a/source.list
  4. +++ b/source.list
  5. @@ -442,7 +442,6 @@ core/smallmap_type.hpp
  6.  core/smallmatrix_type.hpp
  7.  core/smallstack_type.hpp
  8.  core/smallvec_type.hpp
  9. -core/sort_func.hpp
  10.  core/string_compare_type.hpp
  11.  
  12.  # GUI Source Code
  13. diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp
  14. index 1074d1dd7..7342c1864 100644
  15. --- a/src/autoreplace_gui.cpp
  16. +++ b/src/autoreplace_gui.cpp
  17. @@ -32,11 +32,9 @@
  18.  
  19.  void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group);
  20.  
  21. -static int CDECL EngineNumberSorter(const EngineID *a, const EngineID *b)
  22. +static bool CDECL EngineNumberSorter(const EngineID &a, const EngineID &b)
  23.  {
  24. -       int r = Engine::Get(*a)->list_position - Engine::Get(*b)->list_position;
  25. -
  26. -       return r;
  27. +       return Engine::Get(a)->list_position < Engine::Get(b)->list_position;
  28.  }
  29.  
  30.  /**
  31. diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp
  32. index 797ead1f5..dfbe5d435 100644
  33. --- a/src/bridge_gui.cpp
  34. +++ b/src/bridge_gui.cpp
  35. @@ -93,21 +93,21 @@ private:
  36.         Scrollbar *vscroll;
  37.  
  38.         /** Sort the bridges by their index */
  39. -       static int CDECL BridgeIndexSorter(const BuildBridgeData *a, const BuildBridgeData *b)
  40. +       static bool CDECL BridgeIndexSorter(const BuildBridgeData &a, const BuildBridgeData &b)
  41.         {
  42. -               return a->index - b->index;
  43. +               return a.index < b.index;
  44.         }
  45.  
  46.         /** Sort the bridges by their price */
  47. -       static int CDECL BridgePriceSorter(const BuildBridgeData *a, const BuildBridgeData *b)
  48. +       static bool CDECL BridgePriceSorter(const BuildBridgeData &a, const BuildBridgeData &b)
  49.         {
  50. -               return a->cost - b->cost;
  51. +               return a.cost < b.cost;
  52.         }
  53.  
  54.         /** Sort the bridges by their maximum speed */
  55. -       static int CDECL BridgeSpeedSorter(const BuildBridgeData *a, const BuildBridgeData *b)
  56. +       static bool CDECL BridgeSpeedSorter(const BuildBridgeData &a, const BuildBridgeData &b)
  57.         {
  58. -               return a->spec->speed - b->spec->speed;
  59. +               return a.spec->speed < b.spec->speed;
  60.         }
  61.  
  62.         void BuildBridge(uint8 i)
  63. diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
  64. index 655a18d7f..ab71593d0 100644
  65. --- a/src/build_vehicle_gui.cpp
  66. +++ b/src/build_vehicle_gui.cpp
  67. @@ -99,15 +99,14 @@ static CargoID _engine_sort_last_cargo_criteria[] = {CF_ANY, CF_ANY, CF_ANY, CF_
  68.  
  69.  /**
  70.   * Determines order of engines by engineID
  71. - * @param *a first engine to compare
  72. - * @param *b second engine to compare
  73. + * @param a first engine to compare
  74. + * @param b second engine to compare
  75.   * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
  76.   */
  77. -static int CDECL EngineNumberSorter(const EngineID *a, const EngineID *b)
  78. +static bool CDECL EngineNumberSorter(const EngineID &a, const EngineID &b)
  79.  {
  80. -       int r = Engine::Get(*a)->list_position - Engine::Get(*b)->list_position;
  81. -
  82. -       return _engine_sort_direction ? -r : r;
  83. +       bool r = Engine::Get(a)->list_position < Engine::Get(b)->list_position;
  84. +       return _engine_sort_direction != r;
  85.  }
  86.  
  87.  /**
  88. @@ -116,15 +115,14 @@ static int CDECL EngineNumberSorter(const EngineID *a, const EngineID *b)
  89.   * @param *b second engine to compare
  90.   * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
  91.   */
  92. -static int CDECL EngineIntroDateSorter(const EngineID *a, const EngineID *b)
  93. +static bool CDECL EngineIntroDateSorter(const EngineID &a, const EngineID &b)
  94.  {
  95. -       const int va = Engine::Get(*a)->intro_date;
  96. -       const int vb = Engine::Get(*b)->intro_date;
  97. -       const int r = va - vb;
  98. +       const int va = Engine::Get(a)->intro_date;
  99. +       const int vb = Engine::Get(b)->intro_date;
  100.  
  101.         /* Use EngineID to sort instead since we want consistent sorting */
  102. -       if (r == 0) return EngineNumberSorter(a, b);
  103. -       return _engine_sort_direction ? -r : r;
  104. +       if (va == vb) return EngineNumberSorter(a, b);
  105. +       return _engine_sort_direction != (va < vb);
  106.  }
  107.  
  108.  /**
  109. @@ -133,13 +131,13 @@ static int CDECL EngineIntroDateSorter(const EngineID *a, const EngineID *b)
  110.   * @param *b second engine to compare
  111.   * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
  112.   */
  113. -static int CDECL EngineNameSorter(const EngineID *a, const EngineID *b)
  114. +static bool CDECL EngineNameSorter(const EngineID &a, const EngineID &b)
  115.  {
  116.         static EngineID last_engine[2] = { INVALID_ENGINE, INVALID_ENGINE };
  117.         static char     last_name[2][64] = { "\0", "\0" };
  118.  
  119. -       const EngineID va = *a;
  120. -       const EngineID vb = *b;
  121. +       const EngineID va = a;
  122. +       const EngineID vb = b;
  123.  
  124.         if (va != last_engine[0]) {
  125.                 last_engine[0] = va;
  126. @@ -157,7 +155,7 @@ static int CDECL EngineNameSorter(const EngineID *a, const EngineID *b)
  127.  
  128.         /* Use EngineID to sort instead since we want consistent sorting */
  129.         if (r == 0) return EngineNumberSorter(a, b);
  130. -       return _engine_sort_direction ? -r : r;
  131. +       return _engine_sort_direction != (r < 0);
  132.  }
  133.  
  134.  /**
  135. @@ -166,15 +164,14 @@ static int CDECL EngineNameSorter(const EngineID *a, const EngineID *b)
  136.   * @param *b second engine to compare
  137.   * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
  138.   */
  139. -static int CDECL EngineReliabilitySorter(const EngineID *a, const EngineID *b)
  140. +static bool CDECL EngineReliabilitySorter(const EngineID &a, const EngineID &b)
  141.  {
  142. -       const int va = Engine::Get(*a)->reliability;
  143. -       const int vb = Engine::Get(*b)->reliability;
  144. -       const int r = va - vb;
  145. +       const int va = Engine::Get(a)->reliability;
  146. +       const int vb = Engine::Get(b)->reliability;
  147.  
  148.         /* Use EngineID to sort instead since we want consistent sorting */
  149. -       if (r == 0) return EngineNumberSorter(a, b);
  150. -       return _engine_sort_direction ? -r : r;
  151. +       if (va == vb) return EngineNumberSorter(a, b);
  152. +       return _engine_sort_direction != (va < vb);
  153.  }
  154.  
  155.  /**
  156. @@ -183,15 +180,15 @@ static int CDECL EngineReliabilitySorter(const EngineID *a, const EngineID *b)
  157.   * @param *b second engine to compare
  158.   * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
  159.   */
  160. -static int CDECL EngineCostSorter(const EngineID *a, const EngineID *b)
  161. +static bool CDECL EngineCostSorter(const EngineID &a, const EngineID &b)
  162.  {
  163. -       Money va = Engine::Get(*a)->GetCost();
  164. -       Money vb = Engine::Get(*b)->GetCost();
  165. +       Money va = Engine::Get(a)->GetCost();
  166. +       Money vb = Engine::Get(b)->GetCost();
  167.         int r = ClampToI32(va - vb);
  168.  
  169.         /* Use EngineID to sort instead since we want consistent sorting */
  170.         if (r == 0) return EngineNumberSorter(a, b);
  171. -       return _engine_sort_direction ? -r : r;
  172. +       return _engine_sort_direction != (r < 0);
  173.  }
  174.  
  175.  /**
  176. @@ -200,15 +197,15 @@ static int CDECL EngineCostSorter(const EngineID *a, const EngineID *b)
  177.   * @param *b second engine to compare
  178.   * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
  179.   */
  180. -static int CDECL EngineSpeedSorter(const EngineID *a, const EngineID *b)
  181. +static bool CDECL EngineSpeedSorter(const EngineID &a, const EngineID &b)
  182.  {
  183. -       int va = Engine::Get(*a)->GetDisplayMaxSpeed();
  184. -       int vb = Engine::Get(*b)->GetDisplayMaxSpeed();
  185. +       int va = Engine::Get(a)->GetDisplayMaxSpeed();
  186. +       int vb = Engine::Get(b)->GetDisplayMaxSpeed();
  187.         int r = va - vb;
  188.  
  189.         /* Use EngineID to sort instead since we want consistent sorting */
  190.         if (r == 0) return EngineNumberSorter(a, b);
  191. -       return _engine_sort_direction ? -r : r;
  192. +       return _engine_sort_direction != (r < 0);
  193.  }
  194.  
  195.  /**
  196. @@ -217,15 +214,15 @@ static int CDECL EngineSpeedSorter(const EngineID *a, const EngineID *b)
  197.   * @param *b second engine to compare
  198.   * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
  199.   */
  200. -static int CDECL EnginePowerSorter(const EngineID *a, const EngineID *b)
  201. +static bool CDECL EnginePowerSorter(const EngineID &a, const EngineID &b)
  202.  {
  203. -       int va = Engine::Get(*a)->GetPower();
  204. -       int vb = Engine::Get(*b)->GetPower();
  205. +       int va = Engine::Get(a)->GetPower();
  206. +       int vb = Engine::Get(b)->GetPower();
  207.         int r = va - vb;
  208.  
  209.         /* Use EngineID to sort instead since we want consistent sorting */
  210.         if (r == 0) return EngineNumberSorter(a, b);
  211. -       return _engine_sort_direction ? -r : r;
  212. +       return _engine_sort_direction != (r < 0);
  213.  }
  214.  
  215.  /**
  216. @@ -234,15 +231,15 @@ static int CDECL EnginePowerSorter(const EngineID *a, const EngineID *b)
  217.   * @param *b second engine to compare
  218.   * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
  219.   */
  220. -static int CDECL EngineTractiveEffortSorter(const EngineID *a, const EngineID *b)
  221. +static bool CDECL EngineTractiveEffortSorter(const EngineID &a, const EngineID &b)
  222.  {
  223. -       int va = Engine::Get(*a)->GetDisplayMaxTractiveEffort();
  224. -       int vb = Engine::Get(*b)->GetDisplayMaxTractiveEffort();
  225. +       int va = Engine::Get(a)->GetDisplayMaxTractiveEffort();
  226. +       int vb = Engine::Get(b)->GetDisplayMaxTractiveEffort();
  227.         int r = va - vb;
  228.  
  229.         /* Use EngineID to sort instead since we want consistent sorting */
  230.         if (r == 0) return EngineNumberSorter(a, b);
  231. -       return _engine_sort_direction ? -r : r;
  232. +       return _engine_sort_direction != (r < 0);
  233.  }
  234.  
  235.  /**
  236. @@ -251,15 +248,15 @@ static int CDECL EngineTractiveEffortSorter(const EngineID *a, const EngineID *b
  237.   * @param *b second engine to compare
  238.   * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
  239.   */
  240. -static int CDECL EngineRunningCostSorter(const EngineID *a, const EngineID *b)
  241. +static bool CDECL EngineRunningCostSorter(const EngineID &a, const EngineID &b)
  242.  {
  243. -       Money va = Engine::Get(*a)->GetRunningCost();
  244. -       Money vb = Engine::Get(*b)->GetRunningCost();
  245. +       Money va = Engine::Get(a)->GetRunningCost();
  246. +       Money vb = Engine::Get(b)->GetRunningCost();
  247.         int r = ClampToI32(va - vb);
  248.  
  249.         /* Use EngineID to sort instead since we want consistent sorting */
  250.         if (r == 0) return EngineNumberSorter(a, b);
  251. -       return _engine_sort_direction ? -r : r;
  252. +       return _engine_sort_direction != (r < 0);
  253.  }
  254.  
  255.  /**
  256. @@ -268,10 +265,10 @@ static int CDECL EngineRunningCostSorter(const EngineID *a, const EngineID *b)
  257.   * @param *b second engine to compare
  258.   * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
  259.   */
  260. -static int CDECL EnginePowerVsRunningCostSorter(const EngineID *a, const EngineID *b)
  261. +static bool CDECL EnginePowerVsRunningCostSorter(const EngineID &a, const EngineID &b)
  262.  {
  263. -       const Engine *e_a = Engine::Get(*a);
  264. -       const Engine *e_b = Engine::Get(*b);
  265. +       const Engine *e_a = Engine::Get(a);
  266. +       const Engine *e_b = Engine::Get(b);
  267.  
  268.         /* Here we are using a few tricks to get the right sort.
  269.          * We want power/running cost, but since we usually got higher running cost than power and we store the result in an int,
  270. @@ -285,7 +282,7 @@ static int CDECL EnginePowerVsRunningCostSorter(const EngineID *a, const EngineI
  271.  
  272.         /* Use EngineID to sort instead since we want consistent sorting */
  273.         if (r == 0) return EngineNumberSorter(a, b);
  274. -       return _engine_sort_direction ? -r : r;
  275. +       return _engine_sort_direction != (r < 0);
  276.  }
  277.  
  278.  /* Train sorting functions */
  279. @@ -296,18 +293,18 @@ static int CDECL EnginePowerVsRunningCostSorter(const EngineID *a, const EngineI
  280.   * @param *b second engine to compare
  281.   * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
  282.   */
  283. -static int CDECL TrainEngineCapacitySorter(const EngineID *a, const EngineID *b)
  284. +static bool CDECL TrainEngineCapacitySorter(const EngineID &a, const EngineID &b)
  285.  {
  286. -       const RailVehicleInfo *rvi_a = RailVehInfo(*a);
  287. -       const RailVehicleInfo *rvi_b = RailVehInfo(*b);
  288. +       const RailVehicleInfo *rvi_a = RailVehInfo(a);
  289. +       const RailVehicleInfo *rvi_b = RailVehInfo(b);
  290.  
  291. -       int va = GetTotalCapacityOfArticulatedParts(*a) * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
  292. -       int vb = GetTotalCapacityOfArticulatedParts(*b) * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
  293. +       int va = GetTotalCapacityOfArticulatedParts(a) * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
  294. +       int vb = GetTotalCapacityOfArticulatedParts(b) * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
  295.         int r = va - vb;
  296.  
  297.         /* Use EngineID to sort instead since we want consistent sorting */
  298.         if (r == 0) return EngineNumberSorter(a, b);
  299. -       return _engine_sort_direction ? -r : r;
  300. +       return _engine_sort_direction != (r < 0);
  301.  }
  302.  
  303.  /**
  304. @@ -316,15 +313,15 @@ static int CDECL TrainEngineCapacitySorter(const EngineID *a, const EngineID *b)
  305.   * @param *b second engine to compare
  306.   * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
  307.   */
  308. -static int CDECL TrainEnginesThenWagonsSorter(const EngineID *a, const EngineID *b)
  309. +static bool CDECL TrainEnginesThenWagonsSorter(const EngineID &a, const EngineID &b)
  310.  {
  311. -       int val_a = (RailVehInfo(*a)->railveh_type == RAILVEH_WAGON ? 1 : 0);
  312. -       int val_b = (RailVehInfo(*b)->railveh_type == RAILVEH_WAGON ? 1 : 0);
  313. +       int val_a = (RailVehInfo(a)->railveh_type == RAILVEH_WAGON ? 1 : 0);
  314. +       int val_b = (RailVehInfo(b)->railveh_type == RAILVEH_WAGON ? 1 : 0);
  315.         int r = val_a - val_b;
  316.  
  317.         /* Use EngineID to sort instead since we want consistent sorting */
  318.         if (r == 0) return EngineNumberSorter(a, b);
  319. -       return _engine_sort_direction ? -r : r;
  320. +       return _engine_sort_direction != (r < 0);
  321.  }
  322.  
  323.  /* Road vehicle sorting functions */
  324. @@ -335,15 +332,15 @@ static int CDECL TrainEnginesThenWagonsSorter(const EngineID *a, const EngineID
  325.   * @param *b second engine to compare
  326.   * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
  327.   */
  328. -static int CDECL RoadVehEngineCapacitySorter(const EngineID *a, const EngineID *b)
  329. +static bool CDECL RoadVehEngineCapacitySorter(const EngineID &a, const EngineID &b)
  330.  {
  331. -       int va = GetTotalCapacityOfArticulatedParts(*a);
  332. -       int vb = GetTotalCapacityOfArticulatedParts(*b);
  333. +       int va = GetTotalCapacityOfArticulatedParts(a);
  334. +       int vb = GetTotalCapacityOfArticulatedParts(b);
  335.         int r = va - vb;
  336.  
  337.         /* Use EngineID to sort instead since we want consistent sorting */
  338.         if (r == 0) return EngineNumberSorter(a, b);
  339. -       return _engine_sort_direction ? -r : r;
  340. +       return _engine_sort_direction != (r < 0);
  341.  }
  342.  
  343.  /* Ship vehicle sorting functions */
  344. @@ -354,10 +351,10 @@ static int CDECL RoadVehEngineCapacitySorter(const EngineID *a, const EngineID *
  345.   * @param *b second engine to compare
  346.   * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
  347.   */
  348. -static int CDECL ShipEngineCapacitySorter(const EngineID *a, const EngineID *b)
  349. +static bool CDECL ShipEngineCapacitySorter(const EngineID &a, const EngineID &b)
  350.  {
  351. -       const Engine *e_a = Engine::Get(*a);
  352. -       const Engine *e_b = Engine::Get(*b);
  353. +       const Engine *e_a = Engine::Get(a);
  354. +       const Engine *e_b = Engine::Get(b);
  355.  
  356.         int va = e_a->GetDisplayDefaultCapacity();
  357.         int vb = e_b->GetDisplayDefaultCapacity();
  358. @@ -365,7 +362,7 @@ static int CDECL ShipEngineCapacitySorter(const EngineID *a, const EngineID *b)
  359.  
  360.         /* Use EngineID to sort instead since we want consistent sorting */
  361.         if (r == 0) return EngineNumberSorter(a, b);
  362. -       return _engine_sort_direction ? -r : r;
  363. +       return _engine_sort_direction != (r < 0);
  364.  }
  365.  
  366.  /* Aircraft sorting functions */
  367. @@ -376,10 +373,10 @@ static int CDECL ShipEngineCapacitySorter(const EngineID *a, const EngineID *b)
  368.   * @param *b second engine to compare
  369.   * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
  370.   */
  371. -static int CDECL AircraftEngineCargoSorter(const EngineID *a, const EngineID *b)
  372. +static bool CDECL AircraftEngineCargoSorter(const EngineID &a, const EngineID &b)
  373.  {
  374. -       const Engine *e_a = Engine::Get(*a);
  375. -       const Engine *e_b = Engine::Get(*b);
  376. +       const Engine *e_a = Engine::Get(a);
  377. +       const Engine *e_b = Engine::Get(b);
  378.  
  379.         uint16 mail_a, mail_b;
  380.         int va = e_a->GetDisplayDefaultCapacity(&mail_a);
  381. @@ -395,7 +392,7 @@ static int CDECL AircraftEngineCargoSorter(const EngineID *a, const EngineID *b)
  382.                         return EngineNumberSorter(a, b);
  383.                 }
  384.         }
  385. -       return _engine_sort_direction ? -r : r;
  386. +       return _engine_sort_direction != (r < 0);
  387.  }
  388.  
  389.  /**
  390. @@ -404,16 +401,16 @@ static int CDECL AircraftEngineCargoSorter(const EngineID *a, const EngineID *b)
  391.   * @param *b second engine to compare.
  392.   * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal.
  393.   */
  394. -static int CDECL AircraftRangeSorter(const EngineID *a, const EngineID *b)
  395. +static bool CDECL AircraftRangeSorter(const EngineID &a, const EngineID &b)
  396.  {
  397. -       uint16 r_a = Engine::Get(*a)->GetRange();
  398. -       uint16 r_b = Engine::Get(*b)->GetRange();
  399. +       uint16 r_a = Engine::Get(a)->GetRange();
  400. +       uint16 r_b = Engine::Get(b)->GetRange();
  401.  
  402.         int r = r_a - r_b;
  403.  
  404.         /* Use EngineID to sort instead since we want consistent sorting */
  405.         if (r == 0) return EngineNumberSorter(a, b);
  406. -       return _engine_sort_direction ? -r : r;
  407. +       return _engine_sort_direction != (r < 0);
  408.  }
  409.  
  410.  /** Sort functions for the vehicle sort criteria, for each vehicle type. */
  411. diff --git a/src/cargotype.cpp b/src/cargotype.cpp
  412. index 863c58561..ce7622798 100644
  413. --- a/src/cargotype.cpp
  414. +++ b/src/cargotype.cpp
  415. @@ -10,11 +10,13 @@
  416.  /** @file cargotype.cpp Implementation of cargoes. */
  417.  
  418.  #include "stdafx.h"
  419. +
  420. +#include <algorithm>
  421. +
  422.  #include "cargotype.h"
  423.  #include "newgrf_cargo.h"
  424.  #include "string_func.h"
  425.  #include "strings_func.h"
  426. -#include "core/sort_func.hpp"
  427.  
  428.  #include "table/sprites.h"
  429.  #include "table/strings.h"
  430. @@ -138,35 +140,28 @@ uint8 _sorted_standard_cargo_specs_size;         ///< Number of standard cargo s
  431.  
  432.  
  433.  /** Sort cargo specifications by their name. */
  434. -static int CDECL CargoSpecNameSorter(const CargoSpec * const *a, const CargoSpec * const *b)
  435. +static bool CDECL CargoSpecNameSorter(const CargoSpec * const &a, const CargoSpec * const &b)
  436.  {
  437.         static char a_name[64];
  438.         static char b_name[64];
  439.  
  440. -       GetString(a_name, (*a)->name, lastof(a_name));
  441. -       GetString(b_name, (*b)->name, lastof(b_name));
  442. +       GetString(a_name, a->name, lastof(a_name));
  443. +       GetString(b_name, b->name, lastof(b_name));
  444.  
  445.         int res = strnatcmp(a_name, b_name); // Sort by name (natural sorting).
  446.  
  447.         /* If the names are equal, sort by cargo bitnum. */
  448. -       return (res != 0) ? res : ((*a)->bitnum - (*b)->bitnum);
  449. +       return (res != 0) ? res < 0 : (a->bitnum < b->bitnum);
  450.  }
  451.  
  452.  /** Sort cargo specifications by their cargo class. */
  453. -static int CDECL CargoSpecClassSorter(const CargoSpec * const *a, const CargoSpec * const *b)
  454. +static bool CDECL CargoSpecClassSorter(const CargoSpec * const &a, const CargoSpec * const &b)
  455.  {
  456.         uint16 mail_a, mail_b;
  457.         int va = e_a->GetDisplayDefaultCapacity(&mail_a);
  458. @@ -395,7 +392,7 @@ static int CDECL AircraftEngineCargoSorter(const EngineID *a, const EngineID *b)
  459.                         return EngineNumberSorter(a, b);
  460.                 }
  461.         }
  462. -       return _engine_sort_direction ? -r : r;
  463. +       return _engine_sort_direction != (r < 0);
  464.  }
  465.  
  466.  /**
  467. @@ -404,16 +401,16 @@ static int CDECL AircraftEngineCargoSorter(const EngineID *a, const EngineID *b)
  468.   * @param *b second engine to compare.
  469.   * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal.
  470.   */
  471. -static int CDECL AircraftRangeSorter(const EngineID *a, const EngineID *b)
  472. +static bool CDECL AircraftRangeSorter(const EngineID &a, const EngineID &b)
  473.  {
  474. -       uint16 r_a = Engine::Get(*a)->GetRange();
  475. -       uint16 r_b = Engine::Get(*b)->GetRange();
  476. +       uint16 r_a = Engine::Get(a)->GetRange();
  477. +       uint16 r_b = Engine::Get(b)->GetRange();
  478.  
  479.         int r = r_a - r_b;
  480.  
  481.         /* Use EngineID to sort instead since we want consistent sorting */
  482.         if (r == 0) return EngineNumberSorter(a, b);
  483. -       return _engine_sort_direction ? -r : r;
  484. +       return _engine_sort_direction != (r < 0);
  485.  }
  486.  
  487.  /** Sort functions for the vehicle sort criteria, for each vehicle type. */
  488. diff --git a/src/cargotype.cpp b/src/cargotype.cpp
  489. index 863c58561..ce7622798 100644
  490. --- a/src/cargotype.cpp
  491. +++ b/src/cargotype.cpp
  492. @@ -10,11 +10,13 @@
  493.  /** @file cargotype.cpp Implementation of cargoes. */
  494.  
  495.  #include "stdafx.h"
  496. +
  497. +#include <algorithm>
  498. +
  499.  #include "cargotype.h"
  500.  #include "newgrf_cargo.h"
  501.  #include "string_func.h"
  502.  #include "strings_func.h"
  503. -#include "core/sort_func.hpp"
  504.  
  505.  #include "table/sprites.h"
  506.  #include "table/strings.h"
  507. @@ -138,35 +140,28 @@ uint8 _sorted_standard_cargo_specs_size;         ///< Number of standard cargo s
  508.  
  509.  
  510.  /** Sort cargo specifications by their name. */
  511. -static int CDECL CargoSpecNameSorter(const CargoSpec * const *a, const CargoSpec * const *b)
  512. +static bool CDECL CargoSpecNameSorter(const CargoSpec * const &a, const CargoSpec * const &b)
  513.  {
  514.         static char a_name[64];
  515.         static char b_name[64];
  516.  
  517. -       GetString(a_name, (*a)->name, lastof(a_name));
  518. -       GetString(b_name, (*b)->name, lastof(b_name));
  519. +       GetString(a_name, a->name, lastof(a_name));
  520. +       GetString(b_name, b->name, lastof(b_name));
  521.  
  522.         int res = strnatcmp(a_name, b_name); // Sort by name (natural sorting).
  523.  
  524.         /* If the names are equal, sort by cargo bitnum. */
  525. -       return (res != 0) ? res : ((*a)->bitnum - (*b)->bitnum);
  526. +       return (res != 0) ? res < 0 : (a->bitnum < b->bitnum);
  527.  }
  528.  
  529.  /** Sort cargo specifications by their cargo class. */
  530. -static int CDECL CargoSpecClassSorter(const CargoSpec * const *a, const CargoSpec * const *b)
  531. +static bool CDECL CargoSpecClassSorter(const CargoSpec * const &a, const CargoSpec * const &b)
  532.  {
  533. -       int res = ((*b)->classes & CC_PASSENGERS) - ((*a)->classes & CC_PASSENGERS);
  534. -       if (res == 0) {
  535. -               res = ((*b)->classes & CC_MAIL) - ((*a)->classes & CC_MAIL);
  536. -               if (res == 0) {
  537. -                       res = ((*a)->classes & CC_SPECIAL) - ((*b)->classes & CC_SPECIAL);
  538. -                       if (res == 0) {
  539. -                               return CargoSpecNameSorter(a, b);
  540. -                       }
  541. -               }
  542. -       }
  543. -
  544. -       return res;
  545. +       int r = (b->classes & CC_PASSENGERS) - (a->classes & CC_PASSENGERS);
  546. +       if (r == 0) r = (b->classes & CC_MAIL) - (a->classes & CC_MAIL);
  547. +       if (r == 0) r = (a->classes & CC_SPECIAL) - (b->classes & CC_SPECIAL);
  548. +       if (r == 0) return CargoSpecNameSorter(a, b);
  549. +       return r < 0;
  550.  }
  551.  
  552.  /** Initialize the list of sorted cargo specifications. */
  553. @@ -181,7 +176,7 @@ void InitializeSortedCargoSpecs()
  554.         }
  555.  
  556.         /* Sort cargo specifications by cargo class and name. */
  557. -       QSortT(_sorted_cargo_specs, _sorted_cargo_specs_size, &CargoSpecClassSorter);
  558. +       std::sort(_sorted_cargo_specs, _sorted_cargo_specs + _sorted_cargo_specs_size, &CargoSpecClassSorter);
  559.  
  560.         _standard_cargo_mask = 0;
  561.  
  562. diff --git a/src/core/smallmap_type.hpp b/src/core/smallmap_type.hpp
  563. index dda0fc2a1..49b5f3b34 100644
  564. --- a/src/core/smallmap_type.hpp
  565. +++ b/src/core/smallmap_type.hpp
  566. @@ -12,8 +12,9 @@
  567.  #ifndef SMALLMAP_TYPE_HPP
  568.  #define SMALLMAP_TYPE_HPP
  569.  
  570. +#include <algorithm>
  571. +
  572.  #include "smallvec_type.hpp"
  573. -#include "sort_func.hpp"
  574.  
  575.  /**
  576.   * Simple pair of data. Both types have to be POD ("Plain Old Data")!
  577. @@ -146,12 +147,12 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
  578.  
  579.         inline void SortByKey()
  580.         {
  581. -               QSortT(this->Begin(), this->items, KeySorter);
  582. +               std::sort(this->Begin(), this->End(), KeySorter);
  583.         }
  584.  
  585. -       static int CDECL KeySorter(const Pair *a, const Pair *b)
  586. +       static bool CDECL KeySorter(const Pair &a, const Pair &b)
  587.         {
  588. -               return a->first - b->first;
  589. +               return a->first < b->first;
  590.         }
  591.  };
  592.  
  593. diff --git a/src/core/sort_func.hpp b/src/core/sort_func.hpp
  594. deleted file mode 100644
  595. index 470a0ccf4..000000000
  596. --- a/src/core/sort_func.hpp
  597. +++ /dev/null
  598. @@ -1,89 +0,0 @@
  599. -/* $Id$ */
  600. -
  601. -/*
  602. - * This file is part of OpenTTD.
  603. - * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
  604. - * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  605. - * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
  606. - */
  607. -
  608. -/** @file sort_func.hpp Functions related to sorting operations. */
  609. -
  610. -#ifndef SORT_FUNC_HPP
  611. -#define SORT_FUNC_HPP
  612. -
  613. -#include "mem_func.hpp"
  614. -
  615. -/**
  616. - * Type safe qsort()
  617. - *
  618. - * @note Use this sort for irregular sorted data.
  619. - *
  620. - * @param base Pointer to the first element of the array to be sorted.
  621. - * @param num Number of elements in the array pointed by base.
  622. - * @param comparator Function that compares two elements.
  623. - * @param desc Sort descending.
  624. - */
  625. -template <typename T>
  626. -static inline void QSortT(T *base, uint num, int (CDECL *comparator)(const T*, const T*), bool desc = false)
  627. -{
  628. -       if (num < 2) return;
  629. -
  630. -       qsort(base, num, sizeof(T), (int (CDECL *)(const void *, const void *))comparator);
  631. -
  632. -       if (desc) MemReverseT(base, num);
  633. -}
  634. -
  635. -/**
  636. - * Type safe Gnome Sort.
  637. - *
  638. - * This is a slightly modified Gnome search. The basic
  639. - * Gnome search tries to sort already sorted list parts.
  640. - * The modification skips these.
  641. - *
  642. - * @note Use this sort for presorted / regular sorted data.
  643. - *
  644. - * @param base Pointer to the first element of the array to be sorted.
  645. - * @param num Number of elements in the array pointed by base.
  646. - * @param comparator Function that compares two elements.
  647. - * @param desc Sort descending.
  648. - */
  649. -template <typename T>
  650. -static inline void GSortT(T *base, uint num, int (CDECL *comparator)(const T*, const T*), bool desc = false)
  651. -{
  652. -       if (num < 2) return;
  653. -
  654. -       assert(base != NULL);
  655. -       assert(comparator != NULL);
  656. -
  657. -       T *a = base;
  658. -       T *b = base + 1;
  659. -       uint offset = 0;
  660. -
  661. -       while (num > 1) {
  662. -               const int diff = comparator(a, b);
  663. -               if ((!desc && diff <= 0) || (desc && diff >= 0)) {
  664. -                       if (offset != 0) {
  665. -                               /* Jump back to the last direction switch point */
  666. -                               a += offset;
  667. -                               b += offset;
  668. -                               offset = 0;
  669. -                               continue;
  670. -                       }
  671. -
  672. -                       a++;
  673. -                       b++;
  674. -                       num--;
  675. -               } else {
  676. -                       Swap(*a, *b);
  677. -
  678. -                       if (a == base) continue;
  679. -
  680. -                       a--;
  681. - * @param num Number of elements in the array pointed by base.
  682. - * @param comparator Function that compares two elements.
  683. - * @param desc Sort descending.
  684. - */
  685. -template <typename T>
  686. -static inline void QSortT(T *base, uint num, int (CDECL *comparator)(const T*, const T*), bool desc = false)
  687. -{
  688. -       if (num < 2) return;
  689. -
  690. -       qsort(base, num, sizeof(T), (int (CDECL *)(const void *, const void *))comparator);
  691. -
  692. -       if (desc) MemReverseT(base, num);
  693. -}
  694. -
  695. -/**
  696. - * Type safe Gnome Sort.
  697. - *
  698. - * This is a slightly modified Gnome search. The basic
  699. - * Gnome search tries to sort already sorted list parts.
  700. - * The modification skips these.
  701. - *
  702. - * @note Use this sort for presorted / regular sorted data.
  703. - *
  704. - * @param base Pointer to the first element of the array to be sorted.
  705. - * @param num Number of elements in the array pointed by base.
  706. - * @param comparator Function that compares two elements.
  707. - * @param desc Sort descending.
  708. - */
  709. -template <typename T>
  710. -static inline void GSortT(T *base, uint num, int (CDECL *comparator)(const T*, const T*), bool desc = false)
  711. -{
  712. -       if (num < 2) return;
  713. -
  714. -       assert(base != NULL);
  715. -       assert(comparator != NULL);
  716. -
  717. -       T *a = base;
  718. -       T *b = base + 1;
  719. -       uint offset = 0;
  720. -
  721. -       while (num > 1) {
  722. -               const int diff = comparator(a, b);
  723. -               if ((!desc && diff <= 0) || (desc && diff >= 0)) {
  724. -                       if (offset != 0) {
  725. -                               /* Jump back to the last direction switch point */
  726. -                               a += offset;
  727. -                               b += offset;
  728. -                               offset = 0;
  729. -                               continue;
  730. -                       }
  731. -
  732. -                       a++;
  733. -                       b++;
  734. -                       num--;
  735. -               } else {
  736. -                       Swap(*a, *b);
  737. -
  738. -                       if (a == base) continue;
  739. -
  740. -                       a--;
  741. -                       b--;
  742. -                       offset++;
  743. -               }
  744. -       }
  745. -}
  746. -
  747. -#endif /* SORT_FUNC_HPP */
  748. diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp
  749. index 070ad6727..e82fd7e4e 100644
  750. --- a/src/engine_gui.cpp
  751. +++ b/src/engine_gui.cpp
  752. @@ -329,7 +329,7 @@ void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
  753.         /* out-of-bounds access at the next line for size == 0 (even with operator[] at some systems)
  754.          * generally, do not sort if there are less than 2 items */
  755.         if (size < 2) return;
  756. -       QSortT(el->Begin(), size, compare);
  757. +       std::sort(el->Begin(), el->End(), compare);
  758.  }
  759.  
  760.  /**
  761. @@ -344,6 +344,6 @@ void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, ui
  762.         if (num_items < 2) return;
  763.         assert(begin < el->Length());
  764.         assert(begin + num_items <= el->Length());
  765. -       QSortT(el->Get(begin), num_items, compare);
  766. +       std::sort(el->Get(begin), el->Get(begin + num_items), compare);
  767.  }
  768.  
  769. diff --git a/src/engine_gui.h b/src/engine_gui.h
  770. index fc0b7ad7d..ac2ec718f 100644
  771. --- a/src/engine_gui.h
  772. +++ b/src/engine_gui.h
  773. @@ -19,7 +19,7 @@
  774.  
  775.  typedef GUIList<EngineID, CargoID> GUIEngineList;
  776.  
  777. -typedef int CDECL EngList_SortTypeFunction(const EngineID*, const EngineID*); ///< argument type for #EngList_Sort.
  778. +typedef bool CDECL EngList_SortTypeFunction(const EngineID&, const EngineID&); ///< argument type for #EngList_Sort.
  779.  void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare);
  780.  void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items);
  781.  
  782. diff --git a/src/fios.cpp b/src/fios.cpp
  783. index 8ed01152f..117667f90 100644
  784. --- a/src/fios.cpp
  785. +++ b/src/fios.cpp
  786. @@ -49,25 +49,19 @@ extern void GetOldSaveGameName(const char *file, char *title, const char *last);
  787.   * @param db A pointer to the second FiosItem to compare.
  788.   * @return -1, 0 or 1, depending on how the two items should be sorted.
  789.   */
  790. -int CDECL CompareFiosItems(const FiosItem *da, const FiosItem *db)
  791. +bool CDECL CompareFiosItems(const FiosItem &da, const FiosItem &db)
  792.  {
  793. -       int r = 0;
  794. -
  795. -       if ((_savegame_sort_order & SORT_BY_NAME) == 0 && da->mtime != db->mtime) {
  796. -               r = da->mtime < db->mtime ? -1 : 1;
  797. +       bool r;
  798. +       if ((_savegame_sort_order & SORT_BY_NAME) == 0 && da.mtime != db.mtime) {
  799. +               r = da.mtime < db.mtime;
  800.         } else {
  801. -               r = strcasecmp(da->title, db->title);
  802. +               r = strcasecmp(da.title, db.title) < 0;
  803.         }
  804.  
  805. -       if (_savegame_sort_order & SORT_DESCENDING) r = -r;
  806. +       if (_savegame_sort_order & SORT_DESCENDING) r = !r;
  807.         return r;
  808.  }
  809.  
  810. -FileList::~FileList()
  811. -{
  812. -       this->Clear();
  813. -}
  814. -
  815.  /**
  816.   * Construct a file list with the given kind of files, for the stated purpose.
  817.   * @param abstract_filetype Kind of files to collect.
  818. @@ -398,7 +392,7 @@ static void FiosGetFileList(SaveLoadOperation fop, fios_getlist_callback_proc *c
  819.         {
  820.                 SortingBits order = _savegame_sort_order;
  821.                 _savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
  822. -               QSortT(file_list.files.Begin(), file_list.files.Length(), CompareFiosItems);
  823. +               std::sort(file_list.Begin(), file_list.End(), CompareFiosItems);
  824.                 _savegame_sort_order = order;
  825.         }
  826.  
  827. @@ -413,7 +407,7 @@ static void FiosGetFileList(SaveLoadOperation fop, fios_getlist_callback_proc *c
  828.                 scanner.Scan(NULL, subdir, true, true);
  829.         }
  830.  
  831. -       QSortT(file_list.Get(sort_start), file_list.Length() - sort_start, CompareFiosItems);
  832. +       std::sort(file_list.Get(sort_start), file_list.End(), CompareFiosItems);
  833.  
  834.         /* Show drives */
  835.         FiosGetDrives(file_list);
  836. diff --git a/src/fios.h b/src/fios.h
  837. index 5e17e8ee1..40f4852fe 100644
  838. --- a/src/fios.h
  839. +++ b/src/fios.h
  840. @@ -103,94 +103,10 @@ struct FiosItem {
  841.  };
  842.  
  843.  /** List of file information. */
  844. -class FileList {
  845. +class FileList : public SmallVector<FiosItem, 32>  {
  846.  public:
  847. -       ~FileList();
  848. -
  849. -       /**
  850. -        * Construct a new entry in the file list.
  851. -        * @return Pointer to the new items to be initialized.
  852. -        */
  853. -       inline FiosItem *Append()
  854. -       {
  855. -               return this->files.Append();
  856. -       }
  857. -
  858. -       /**
  859. -        * Get the number of files in the list.
  860. -        * @return The number of files stored in the list.
  861. -        */
  862. -       inline uint Length() const
  863. -       {
  864. -               return this->files.Length();
  865. -       }
  866. -
  867. -       /**
  868. -        * Get a pointer to the first file information.
  869. -        * @return Address of the first file information.
  870. -        */
  871. -       inline const FiosItem *Begin() const
  872. -       {
  873. -               return this->files.Begin();
  874. -       }
  875. -
  876. -       /**
  877. -        * Get a pointer behind the last file information.
  878. -        * @return Address behind the last file information.
  879. -        */
  880. -       inline const FiosItem *End() const
  881. -       {
  882. -               return this->files.End();
  883. -       }
  884. -
  885. -       /**
  886. -        * Get a pointer to the indicated file information. File information must exist.
  887. -        * @return Address of the indicated existing file information.
  888. -        */
  889. -       inline const FiosItem *Get(uint index) const
  890. -       {
  891. -               return this->files.Get(index);
  892. -       }
  893. -
  894. -       /**
  895. -        * Get a pointer to the indicated file information. File information must exist.
  896. -        * @return Address of the indicated existing file information.
  897. -        */
  898. -       inline FiosItem *Get(uint index)
  899. -       {
  900. -               return this->files.Get(index);
  901. -       }
  902. -
  903. -       inline const FiosItem &operator[](uint index) const
  904. -       {
  905. -               return this->files[index];
  906. -       }
  907. -
  908. -       /**
  909.  
  910.         /* Show drives */
  911.         FiosGetDrives(file_list);
  912. diff --git a/src/fios.h b/src/fios.h
  913. index 5e17e8ee1..40f4852fe 100644
  914. --- a/src/fios.h
  915. +++ b/src/fios.h
  916. @@ -103,94 +103,10 @@ struct FiosItem {
  917.  };
  918.  
  919.  /** List of file information. */
  920. -class FileList {
  921. +class FileList : public SmallVector<FiosItem, 32>  {
  922.  public:
  923. -       ~FileList();
  924. -
  925. -       /**
  926. -        * Construct a new entry in the file list.
  927. -        * @return Pointer to the new items to be initialized.
  928. -        */
  929. -       inline FiosItem *Append()
  930. -       {
  931. -               return this->files.Append();
  932. -       }
  933. -
  934. -       /**
  935. -        * Get the number of files in the list.
  936. -        * @return The number of files stored in the list.
  937. -        */
  938. -       inline uint Length() const
  939. -       {
  940. -               return this->files.Length();
  941. -       }
  942. -
  943. -       /**
  944. -        * Get a pointer to the first file information.
  945. -        * @return Address of the first file information.
  946. -        */
  947. -       inline const FiosItem *Begin() const
  948. -       {
  949. -               return this->files.Begin();
  950. -       }
  951. -
  952. -       /**
  953. -        * Get a pointer behind the last file information.
  954. -        * @return Address behind the last file information.
  955. -        */
  956. -       inline const FiosItem *End() const
  957. -       {
  958. -               return this->files.End();
  959. -       }
  960. -
  961. -       /**
  962. -        * Get a pointer to the indicated file information. File information must exist.
  963. -        * @return Address of the indicated existing file information.
  964. -        */
  965. -       inline const FiosItem *Get(uint index) const
  966. -       {
  967. -               return this->files.Get(index);
  968. -       }
  969. -
  970. -       /**
  971. -        * Get a pointer to the indicated file information. File information must exist.
  972. -        * @return Address of the indicated existing file information.
  973. -        */
  974. -       inline FiosItem *Get(uint index)
  975. -       {
  976. -               return this->files.Get(index);
  977. -       }
  978. -
  979. -       inline const FiosItem &operator[](uint index) const
  980. -       {
  981. -               return this->files[index];
  982. -       }
  983. -
  984. -       /**
  985.  
  986.         /* Show drives */
  987.         FiosGetDrives(file_list);
  988. diff --git a/src/fios.h b/src/fios.h
  989. index 5e17e8ee1..40f4852fe 100644
  990. --- a/src/fios.h
  991. +++ b/src/fios.h
  992. @@ -103,94 +103,10 @@ struct FiosItem {
  993.  };
  994.  
  995.  /** List of file information. */
  996. -class FileList {
  997. +class FileList : public SmallVector<FiosItem, 32>  {
  998.  public:
  999. -       ~FileList();
  1000. -
  1001. -       /**
  1002. -        * Construct a new entry in the file list.
  1003. -        * @return Pointer to the new items to be initialized.
  1004. -        */
  1005. -       inline FiosItem *Append()
  1006. -       {
  1007. -               return this->files.Append();
  1008. -       }
  1009. -
  1010. -       /**
  1011. -        * Get the number of files in the list.
  1012. -        * @return The number of files stored in the list.
  1013. -        */
  1014. -       inline uint Length() const
  1015. -       {
  1016. -               return this->files.Length();
  1017. -       }
  1018. -
  1019. -       /**
  1020. -        * Get a pointer to the first file information.
  1021. -        * @return Address of the first file information.
  1022. -        */
  1023. -       inline const FiosItem *Begin() const
  1024. -       {
  1025. -               return this->files.Begin();
  1026. -       }
  1027. -
  1028. -       /**
  1029. -        * Get a pointer behind the last file information.
  1030. -        * @return Address behind the last file information.
  1031. -        */
  1032. -       inline const FiosItem *End() const
  1033. -       {
  1034. -               return this->files.End();
  1035. -       }
  1036. -
  1037. -       /**
  1038. -        * Get a pointer to the indicated file information. File information must exist.
  1039. -        * @return Address of the indicated existing file information.
  1040. -        */
  1041. -       inline const FiosItem *Get(uint index) const
  1042. -       {
  1043. -               return this->files.Get(index);
  1044. -       }
  1045. -
  1046. -       /**
  1047. -        * Get a pointer to the indicated file information. File information must exist.
  1048. -        * @return Address of the indicated existing file information.
  1049. -        */
  1050. -       inline FiosItem *Get(uint index)
  1051. -       {
  1052. -               return this->files.Get(index);
  1053. -       }
  1054. -
  1055. -       inline const FiosItem &operator[](uint index) const
  1056. -       {
  1057. -               return this->files[index];
  1058. -       }
  1059. -
  1060. -       /**
  1061. -        * Get a reference to the indicated file information. File information must exist.
  1062. -        * @return The requested file information.
  1063. -        */
  1064. -       inline FiosItem &operator[](uint index)
  1065. -       {
  1066. -               return this->files[index];
  1067. -       }
  1068. -
  1069. -       /** Remove all items from the list. */
  1070. -       inline void Clear()
  1071. -       {
  1072. -               this->files.Clear();
  1073. -       }
  1074. -
  1075. -       /** Compact the list down to the smallest block size boundary. */
  1076. -       inline void Compact()
  1077. -       {
  1078. -               this->files.Compact();
  1079. -       }
  1080. -
  1081.         void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop);
  1082.         const FiosItem *FindItem(const char *file);
  1083. -
  1084. -       SmallVector<FiosItem, 32> files; ///< The list of files.
  1085.  };
  1086.  
  1087.  enum SortingBits {
  1088. @@ -219,6 +135,6 @@ void FiosMakeSavegameName(char *buf, const char *name, const char *last);
  1089.  
  1090.  FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last);
  1091.  
  1092. -int CDECL CompareFiosItems(const FiosItem *a, const FiosItem *b);
  1093. +bool CDECL CompareFiosItems(const FiosItem &a, const FiosItem &b);
  1094.  
  1095.  #endif /* FIOS_H */
  1096. diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp
  1097. index e6cd9625c..64eac2a50 100644
  1098. --- a/src/fios_gui.cpp
  1099. +++ b/src/fios_gui.cpp
  1100. @@ -221,8 +221,7 @@ static void SortSaveGameList(FileList &file_list)
  1101.                 }
  1102.         }
  1103.  
  1104. -       uint s_amount = file_list.Length() - sort_start - sort_end;
  1105. -       QSortT(file_list.Get(sort_start), s_amount, CompareFiosItems);
  1106. +       std::sort(file_list.Get(sort_start), file_list.Get(sort_end), CompareFiosItems);
  1107.  }
  1108.  
  1109.  struct SaveLoadWindow : public Window {
  1110. diff --git a/src/gfx.cpp b/src/gfx.cpp
  1111. index 719505157..efe6e03eb 100644
  1112. --- a/src/gfx.cpp
  1113. +++ b/src/gfx.cpp
  1114. @@ -1699,14 +1699,12 @@ bool ToggleFullScreen(bool fs)
  1115.         return result;
  1116.  }
  1117.  
  1118. -static int CDECL compare_res(const Dimension *pa, const Dimension *pb)
  1119. +static bool CDECL compare_res(const Dimension &pa, const Dimension &pb)
  1120.  {
  1121. -       int x = pa->width - pb->width;
  1122. -       if (x != 0) return x;
  1123. -       return pa->height - pb->height;
  1124. +       return pa.width < pb.width || pa.height < pb.height;
  1125.  }
  1126.  
  1127.  void SortResolutions(int count)
  1128.  {
  1129. -       QSortT(_resolutions, count, &compare_res);
  1130. +       std::sort(_resolutions, _resolutions + count, &compare_res);
  1131.  }
  1132. diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp
  1133. index c12c6ace4..16fc1107a 100644
  1134. --- a/src/graph_gui.cpp
  1135. +++ b/src/graph_gui.cpp
  1136. @@ -1151,9 +1151,9 @@ private:
  1137.         }
  1138.  
  1139.         /** Sort the company league by performance history */
  1140. -       static int CDECL PerformanceSorter(const Company * const *c1, const Company * const *c2)
  1141. +       static bool CDECL PerformanceSorter(const Company * const &c1, const Company * const &c2)
  1142.         {
  1143. -               return (*c2)->old_economy[0].performance_history - (*c1)->old_economy[0].performance_history;
  1144. +               return c2->old_economy[0].performance_history < c1->old_economy[0].performance_history;
  1145.         }
  1146.  
  1147.  public:
  1148. diff --git a/src/group_gui.cpp b/src/group_gui.cpp
  1149. index d3e1eafbb..713b11cdb 100644
  1150. --- a/src/group_gui.cpp
  1151. +++ b/src/group_gui.cpp
  1152. @@ -134,26 +134,26 @@ private:
  1153.         }
  1154.  
  1155.         /** Sort the groups by their name */
  1156. -       static int CDECL GroupNameSorter(const Group * const *a, const Group * const *b)
  1157. +       static bool CDECL GroupNameSorter(const Group * const &a, const Group * const &b)
  1158.         {
  1159.                 static const Group *last_group[2] = { NULL, NULL };
  1160.                 static char         last_name[2][64] = { "", "" };
  1161.  
  1162. -               if (*a != last_group[0]) {
  1163. -                       last_group[0] = *a;
  1164. -                       SetDParam(0, (*a)->index);
  1165. +               if (a != last_group[0]) {
  1166. +                       last_group[0] = a;
  1167. +                       SetDParam(0, a->index);
  1168.                         GetString(last_name[0], STR_GROUP_NAME, lastof(last_name[0]));
  1169.                 }
  1170.  
  1171. -               if (*b != last_group[1]) {
  1172. -                       last_group[1] = *b;
  1173. -                       SetDParam(0, (*b)->index);
  1174. +               if (b != last_group[1]) {
  1175. +                       last_group[1] = b;
  1176. +                       SetDParam(0, b->index);
  1177.                         GetString(last_name[1], STR_GROUP_NAME, lastof(last_name[1]));
  1178.                 }
  1179.  
  1180.                 int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting).
  1181. -               if (r == 0) return (*a)->index - (*b)->index;
  1182. -               return r;
  1183. +               if (r == 0) return a->index < b->index;
  1184. +               return r < 0;
  1185.         }
  1186.  
  1187.         /**
  1188. diff --git a/src/highscore.cpp b/src/highscore.cpp
  1189. index 86e4f5ae8..57bb2e9f3 100644
  1190. --- a/src/highscore.cpp
  1191. +++ b/src/highscore.cpp
  1192. @@ -10,6 +10,9 @@
  1193.  /** @file highscore.cpp Definition of functions used for highscore handling */
  1194.  
  1195.  #include "stdafx.h"
  1196. +
  1197. +#include <algorithm>
  1198. +
  1199.  #include "highscore.h"
  1200.  #include "company_base.h"
  1201.  #include "company_func.h"
  1202. @@ -17,7 +20,6 @@
  1203.  #include "string_func.h"
  1204.  #include "strings_func.h"
  1205.  #include "table/strings.h"
  1206. -#include "core/sort_func.hpp"
  1207.  #include "debug.h"
  1208.  
  1209.  #include "safeguards.h"
  1210. @@ -79,9 +81,9 @@ int8 SaveHighScoreValue(const Company *c)
  1211.  }
  1212.  
  1213.  /** Sort all companies given their performance */
  1214. -static int CDECL HighScoreSorter(const Company * const *a, const Company * const *b)
  1215. +static bool CDECL HighScoreSorter(const Company * const &a, const Company * const &b)
  1216.  {
  1217. -       return (*b)->old_economy[0].performance_history - (*a)->old_economy[0].performance_history;
  1218. +       return b->old_economy[0].performance_history < a->old_economy[0].performance_history;
  1219.  }
  1220.  
  1221.  /**
  1222. @@ -98,7 +100,7 @@ int8 SaveHighScoreValueNetwork()
  1223.         /* Sort all active companies with the highest score first */
  1224.         FOR_ALL_COMPANIES(c) cl[count++] = c;
  1225.  
  1226. -       QSortT(cl, count, &HighScoreSorter);
  1227. +       std::sort(cl, cl + count, &HighScoreSorter);
  1228.  
  1229.         {
  1230.                 uint i;
  1231. diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
  1232. index b9077b9d7..9e152649b 100644
  1233. --- a/src/industry_gui.cpp
  1234. +++ b/src/industry_gui.cpp
  1235. @@ -160,20 +160,20 @@ static inline void GetAllCargoSuffixes(uint cb_offset, CargoSuffixType cst, cons
  1236.  IndustryType _sorted_industry_types[NUM_INDUSTRYTYPES]; ///< Industry types sorted by name.
  1237.  
  1238.  /** Sort industry types by their name. */
  1239. -static int CDECL IndustryTypeNameSorter(const IndustryType *a, const IndustryType *b)
  1240. +static bool CDECL IndustryTypeNameSorter(const IndustryType &a, const IndustryType &b)
  1241.  {
  1242.         static char industry_name[2][64];
  1243.  
  1244. -       const IndustrySpec *indsp1 = GetIndustrySpec(*a);
  1245. +       const IndustrySpec *indsp1 = GetIndustrySpec(a);
  1246.         GetString(industry_name[0], indsp1->name, lastof(industry_name[0]));
  1247.  
  1248. -       const IndustrySpec *indsp2 = GetIndustrySpec(*b);
  1249. +       const IndustrySpec *indsp2 = GetIndustrySpec(b);
  1250.         GetString(industry_name[1], indsp2->name, lastof(industry_name[1]));
  1251.  
  1252.         int r = strnatcmp(industry_name[0], industry_name[1]); // Sort by name (natural sorting).
  1253.  
  1254.         /* If the names are equal, sort by industry type. */
  1255. -       return (r != 0) ? r : (*a - *b);
  1256. +       return (r != 0) ? r < 0 : (a < b);
  1257.  }
  1258.  
  1259.  /**
  1260. @@ -187,7 +187,8 @@ void SortIndustryTypes()
  1261.         }
  1262.  
  1263.         /* Sort industry types by name. */
  1264. -       QSortT(_sorted_industry_types, NUM_INDUSTRYTYPES, &IndustryTypeNameSorter);
  1265. +
  1266. +       std::sort(std::begin(_sorted_industry_types), std::end(_sorted_industry_types), IndustryTypeNameSorter);
  1267.  }
  1268.  
  1269.  /**
  1270. @@ -1201,52 +1202,49 @@ protected:
  1271.         }
  1272.  
  1273.         /** Sort industries by name */
  1274. -       static int CDECL IndustryNameSorter(const Industry * const *a, const Industry * const *b)
  1275. +       static bool CDECL IndustryNameSorter(const Industry * const &a, const Industry * const &b)
  1276.         {
  1277.                 static char buf_cache[96];
  1278.                 static char buf[96];
  1279.  
  1280. -               SetDParam(0, (*a)->index);
  1281. +               SetDParam(0, a->index);
  1282.                 GetString(buf, STR_INDUSTRY_NAME, lastof(buf));
  1283.  
  1284. -               if (*b != last_industry) {
  1285. -                       last_industry = *b;
  1286. -                       SetDParam(0, (*b)->index);
  1287. +               if (b != last_industry) {
  1288. +                       last_industry = b;
  1289. +                       SetDParam(0, b->index);
  1290.                         GetString(buf_cache, STR_INDUSTRY_NAME, lastof(buf_cache));
  1291.                 }
  1292.  
  1293. -               return strnatcmp(buf, buf_cache); // Sort by name (natural sorting).
  1294. +               return strnatcmp(buf, buf_cache) < 0; // Sort by name (natural sorting).
  1295.         }
  1296.  
  1297.         /** Sort industries by type and name */
  1298. -       static int CDECL IndustryTypeSorter(const Industry * const *a, const Industry * const *b)
  1299. +       static bool CDECL IndustryTypeSorter(const Industry * const &a, const Industry * const &b)
  1300.         {
  1301.                 int it_a = 0;
  1302. -               while (it_a != NUM_INDUSTRYTYPES && (*a)->type != _sorted_industry_types[it_a]) it_a++;
  1303. +               while (it_a != NUM_INDUSTRYTYPES && a->type != _sorted_industry_types[it_a]) it_a++;
  1304.                 int it_b = 0;
  1305. -               while (it_b != NUM_INDUSTRYTYPES && (*b)->type != _sorted_industry_types[it_b]) it_b++;
  1306. -               int r = it_a - it_b;
  1307. -               return (r == 0) ? IndustryNameSorter(a, b) : r;
  1308. +               while (it_b != NUM_INDUSTRYTYPES && b->type != _sorted_industry_types[it_b]) it_b++;
  1309. +               return (it_a == it_b) ? IndustryNameSorter(a, b) : it_a < it_b;
  1310.         }
  1311.  
  1312.         /** Sort industries by production and name */
  1313. -       static int CDECL IndustryProductionSorter(const Industry * const *a, const Industry * const *b)
  1314. +       static bool CDECL IndustryProductionSorter(const Industry * const &a, const Industry * const &b)
  1315.         {
  1316.                 uint prod_a = 0, prod_b = 0;
  1317. -               for (uint i = 0; i < lengthof((*a)->produced_cargo); i++) {
  1318. -                       if ((*a)->produced_cargo[i] != CT_INVALID) prod_a += (*a)->last_month_production[i];
  1319. -                       if ((*b)->produced_cargo[i] != CT_INVALID) prod_b += (*b)->last_month_production[i];
  1320. +               for (uint i = 0; i < lengthof(a->produced_cargo); i++) {
  1321. +                       if (a->produced_cargo[i] != CT_INVALID) prod_a += a->last_month_production[i];
  1322. +                       if (b->produced_cargo[i] != CT_INVALID) prod_b += b->last_month_production[i];
  1323.                 }
  1324. -               int r = prod_a - prod_b;
  1325. -
  1326. -               return (r == 0) ? IndustryTypeSorter(a, b) : r;
  1327. +               return (prod_a == prod_b) ? IndustryTypeSorter(a, b) : prod_a < prod_b;
  1328.         }
  1329.  
  1330.         /** Sort industries by transported cargo and name */
  1331. -       static int CDECL IndustryTransportedCargoSorter(const Industry * const *a, const Industry * const *b)
  1332. +       static bool CDECL IndustryTransportedCargoSorter(const Industry * const &a, const Industry * const &b)
  1333.         {
  1334. -               int r = GetCargoTransportedSortValue(*a) - GetCargoTransportedSortValue(*b);
  1335. -               return (r == 0) ? IndustryNameSorter(a, b) : r;
  1336. +               int r = GetCargoTransportedSortValue(a) - GetCargoTransportedSortValue(b);
  1337. +               return (r == 0) ? IndustryNameSorter(a, b) : r < 0;
  1338.         }
  1339.  
  1340.         /**
  1341. diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp
  1342. index 1227d43db..a152d447c 100644
  1343. --- a/src/network/network_content_gui.cpp
  1344. +++ b/src/network/network_content_gui.cpp
  1345. @@ -407,28 +407,29 @@ class NetworkContentListWindow : public Window, ContentCallback {
  1346.         }
  1347.  
  1348.         /** Sort content by name. */
  1349. -       static int CDECL NameSorter(const ContentInfo * const *a, const ContentInfo * const *b)
  1350. +       static bool CDECL NameSorter(const ContentInfo * const &a, const ContentInfo * const &b)
  1351.         {
  1352. -               return strnatcmp((*a)->name, (*b)->name, true); // Sort by name (natural sorting).
  1353. +               return strnatcmp(a->name, b->name, true) < 0; // Sort by name (natural sorting).
  1354.         }
  1355.  
  1356.         /** Sort content by type. */
  1357. -       static int CDECL TypeSorter(const ContentInfo * const *a, const ContentInfo * const *b)
  1358. +       static bool CDECL TypeSorter(const ContentInfo * const &a, const ContentInfo * const &b)
  1359.         {
  1360.                 int r = 0;
  1361. -               if ((*a)->type != (*b)->type) {
  1362. -                       r = strnatcmp(content_type_strs[(*a)->type], content_type_strs[(*b)->type]);
  1363. +               if (a->type != b->type) {
  1364. +                       r = strnatcmp(content_type_strs[a->type], content_type_strs[b->type]);
  1365.                 }
  1366. -               if (r == 0) r = NameSorter(a, b);
  1367. -               return r;
  1368. +               if (r == 0) return NameSorter(a, b);
  1369. +               return r < 0;
  1370.         }
  1371.  
  1372.         /** Sort content by state. */
  1373. -       static int CDECL StateSorter(const ContentInfo * const *a, const ContentInfo * const *b)
  1374. +       static bool CDECL StateSorter(const ContentInfo * const &a, const ContentInfo * const &b)
  1375.         {
  1376. -               int r = (*a)->state - (*b)->state;
  1377. -               if (r == 0) r = TypeSorter(a, b);
  1378. -               return r;
  1379. +               if (a->state != b->state) {
  1380. +                       return a->state < b->state;
  1381. +               }
  1382. +               return TypeSorter(a, b);
  1383.         }
  1384.  
  1385.         /** Sort the content list */
  1386. diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
  1387. index 520c4f60a..ac8d7d950 100644
  1388. --- a/src/network/network_gui.cpp
  1389. +++ b/src/network/network_gui.cpp
  1390. @@ -74,7 +74,7 @@ void SortNetworkLanguages()
  1391.         }
  1392.  
  1393.         /* Sort the strings (we don't move 'any' and the 'invalid' one) */
  1394. -       QSortT(_language_dropdown + 1, NETLANG_COUNT - 1, &StringIDSorter);
  1395. +       std::sort(_language_dropdown + 1, _language_dropdown + NETLANG_COUNT - 1, &StringIDSorter);
  1396.  }
  1397.  
  1398.  /**
  1399. @@ -276,10 +276,10 @@ protected:
  1400.         }
  1401.  
  1402.         /** Sort servers by name. */
  1403. -       static int CDECL NGameNameSorter(NetworkGameList * const *a, NetworkGameList * const *b)
  1404. +       static bool CDECL NGameNameSorter(NetworkGameList * const &a, NetworkGameList * const &b)
  1405.         {
  1406. -               int r = strnatcmp((*a)->info.server_name, (*b)->info.server_name, true); // Sort by name (natural sorting).
  1407. -               return r == 0 ? (*a)->address.CompareTo((*b)->address) : r;
  1408. +               int r = strnatcmp(a->info.server_name, b->info.server_name, true); // Sort by name (natural sorting).
  1409. +               return r == 0 ? a->address.CompareTo(b->address) < 0 : r < 0;
  1410.         }
  1411.  
  1412.         /**
  1413. @@ -287,60 +287,60 @@ protected:
  1414.          * server. If the two servers have the same amount, the one with the
  1415.          * higher maximum is preferred.
  1416.          */
  1417. -       static int CDECL NGameClientSorter(NetworkGameList * const *a, NetworkGameList * const *b)
  1418. +       static bool CDECL NGameClientSorter(NetworkGameList * const &a, NetworkGameList * const &b)
  1419.         {
  1420.                 /* Reverse as per default we are interested in most-clients first */
  1421. -               int r = (*a)->info.clients_on - (*b)->info.clients_on;
  1422. +               int r = a->info.clients_on - b->info.clients_on;
  1423.  
  1424. -               if (r == 0) r = (*a)->info.clients_max - (*b)->info.clients_max;
  1425. -               if (r == 0) r = NGameNameSorter(a, b);
  1426. +               if (r == 0) r = a->info.clients_max - b->info.clients_max;
  1427. +               if (r == 0) return NGameNameSorter(a, b);
  1428.  
  1429. -               return r;
  1430. +               return r < 0;
  1431.         }
  1432.  
  1433.         /** Sort servers by map size */
  1434. -       static int CDECL NGameMapSizeSorter(NetworkGameList * const *a, NetworkGameList * const *b)
  1435. +       static bool CDECL NGameMapSizeSorter(NetworkGameList * const &a, NetworkGameList * const &b)
  1436.         {
  1437.                 /* Sort by the area of the map. */
  1438. -               int r = ((*a)->info.map_height) * ((*a)->info.map_width) - ((*b)->info.map_height) * ((*b)->info.map_width);
  1439. +               int r = (a->info.map_height) * (a->info.map_width) - (b->info.map_height) * (b->info.map_width);
  1440.  
  1441. -               if (r == 0) r = (*a)->info.map_width - (*b)->info.map_width;
  1442. -               return (r != 0) ? r : NGameClientSorter(a, b);
  1443. +               if (r == 0) r = a->info.map_width - b->info.map_width;
  1444. +               return (r != 0) ? r < 0 : NGameClientSorter(a, b);
  1445.         }
  1446.  
  1447.         /** Sort servers by current date */
  1448. -       static int CDECL NGameDateSorter(NetworkGameList * const *a, NetworkGameList * const *b)
  1449. +       static bool CDECL NGameDateSorter(NetworkGameList * const &a, NetworkGameList * const &b)
  1450.         {
  1451. -               int r = (*a)->info.game_date - (*b)->info.game_date;
  1452. -               return (r != 0) ? r : NGameClientSorter(a, b);
  1453. +               int r = a->info.game_date - b->info.game_date;
  1454. +               return (r != 0) ? r < 0 : NGameClientSorter(a, b);
  1455.         }
  1456.  
  1457.         /** Sort servers by the number of days the game is running */
  1458. -       static int CDECL NGameYearsSorter(NetworkGameList * const *a, NetworkGameList * const *b)
  1459. +       static bool CDECL NGameYearsSorter(NetworkGameList * const &a, NetworkGameList * const &b)
  1460.         {
  1461. -               int r = (*a)->info.game_date - (*a)->info.start_date - (*b)->info.game_date + (*b)->info.start_date;
  1462. -               return (r != 0) ? r : NGameDateSorter(a, b);
  1463. +               int r = a->info.game_date - a->info.start_date - b->info.game_date + b->info.start_date;
  1464. +               return (r != 0) ? r < 0 : NGameDateSorter(a, b);
  1465.         }
  1466.  
  1467.         /**
  1468.          * Sort servers by joinability. If both servers are the
  1469.          * same, prefer the non-passworded server first.
  1470.          */
  1471. -       static int CDECL NGameAllowedSorter(NetworkGameList * const *a, NetworkGameList * const *b)
  1472. +       static bool CDECL NGameAllowedSorter(NetworkGameList * const &a, NetworkGameList * const &b)
  1473.         {
  1474.                 /* The servers we do not know anything about (the ones that did not reply) should be at the bottom) */
  1475. -               int r = StrEmpty((*a)->info.server_revision) - StrEmpty((*b)->info.server_revision);
  1476. +               int r = StrEmpty(a->info.server_revision) - StrEmpty(b->info.server_revision);
  1477.  
  1478.                 /* Reverse default as we are interested in version-compatible clients first */
  1479. -               if (r == 0) r = (*b)->info.version_compatible - (*a)->info.version_compatible;
  1480. +               if (r == 0) r = b->info.version_compatible - a->info.version_compatible;
  1481.                 /* The version-compatible ones are then sorted with NewGRF compatible first, incompatible last */
  1482. -               if (r == 0) r = (*b)->info.compatible - (*a)->info.compatible;
  1483. +               if (r == 0) r = b->info.compatible - a->info.compatible;
  1484.                 /* Passworded servers should be below unpassworded servers */
  1485. -               if (r == 0) r = (*a)->info.use_password - (*b)->info.use_password;
  1486. +               if (r == 0) r = a->info.use_password - b->info.use_password;
  1487.                 /* Finally sort on the number of clients of the server */
  1488. -               if (r == 0) r = -NGameClientSorter(a, b);
  1489. +               if (r == 0) return !NGameClientSorter(a, b);
  1490.  
  1491. -               return r;
  1492. +               return r < 0;
  1493.         }
  1494.  
  1495.         /** Sort the server list */
  1496. diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
  1497. index 593851e28..beffb2ed8 100644
  1498. --- a/src/newgrf_config.cpp
  1499. +++ b/src/newgrf_config.cpp
  1500. @@ -10,6 +10,9 @@
  1501.  /** @file newgrf_config.cpp Finding NewGRFs and configuring them. */
  1502.  
  1503.  #include "stdafx.h"
  1504. +
  1505. +#include <algorithm>
  1506. +
  1507.  #include "debug.h"
  1508.  #include "3rdparty/md5/md5.h"
  1509.  #include "newgrf.h"
  1510. @@ -711,12 +714,9 @@ bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length, const
  1511.   * @param p2 the second GRFConfig *
  1512.   * @return the same strcmp would return for the name of the NewGRF.
  1513.   */
  1514. -static int CDECL GRFSorter(GRFConfig * const *p1, GRFConfig * const *p2)
  1515. +static bool CDECL GRFSorter(const GRFConfig * const p1, const GRFConfig * const p2)
  1516.  {
  1517. -               if (r == 0) r = (*a)->info.map_width - (*b)->info.map_width;
  1518. -               return (r != 0) ? r : NGameClientSorter(a, b);
  1519. +               if (r == 0) r = a->info.map_width - b->info.map_width;
  1520. +               return (r != 0) ? r < 0 : NGameClientSorter(a, b);
  1521.         }
  1522.  
  1523.         /** Sort servers by current date */
  1524. -       static int CDECL NGameDateSorter(NetworkGameList * const *a, NetworkGameList * const *b)
  1525. +       static bool CDECL NGameDateSorter(NetworkGameList * const &a, NetworkGameList * const &b)
  1526.         {
  1527. -               int r = (*a)->info.game_date - (*b)->info.game_date;
  1528. -               return (r != 0) ? r : NGameClientSorter(a, b);
  1529. +               int r = a->info.game_date - b->info.game_date;
  1530. +               return (r != 0) ? r < 0 : NGameClientSorter(a, b);
  1531.         }
  1532.  
  1533.         /** Sort servers by the number of days the game is running */
  1534. -       static int CDECL NGameYearsSorter(NetworkGameList * const *a, NetworkGameList * const *b)
  1535. +       static bool CDECL NGameYearsSorter(NetworkGameList * const &a, NetworkGameList * const &b)
  1536.         {
  1537. -               int r = (*a)->info.game_date - (*a)->info.start_date - (*b)->info.game_date + (*b)->info.start_date;
  1538. -               return (r != 0) ? r : NGameDateSorter(a, b);
  1539. +               int r = a->info.game_date - a->info.start_date - b->info.game_date + b->info.start_date;
  1540. +               return (r != 0) ? r < 0 : NGameDateSorter(a, b);
  1541.         }
  1542.  
  1543.         /**
  1544.          * Sort servers by joinability. If both servers are the
  1545.          * same, prefer the non-passworded server first.
  1546.          */
  1547. -       static int CDECL NGameAllowedSorter(NetworkGameList * const *a, NetworkGameList * const *b)
  1548. +       static bool CDECL NGameAllowedSorter(NetworkGameList * const &a, NetworkGameList * const &b)
  1549.         {
  1550.                 /* The servers we do not know anything about (the ones that did not reply) should be at the bottom) */
  1551. -               int r = StrEmpty((*a)->info.server_revision) - StrEmpty((*b)->info.server_revision);
  1552. +               int r = StrEmpty(a->info.server_revision) - StrEmpty(b->info.server_revision);
  1553.  
  1554.                 /* Reverse default as we are interested in version-compatible clients first */
  1555. -               if (r == 0) r = (*b)->info.version_compatible - (*a)->info.version_compatible;
  1556. +               if (r == 0) r = b->info.version_compatible - a->info.version_compatible;
  1557.                 /* The version-compatible ones are then sorted with NewGRF compatible first, incompatible last */
  1558. -               if (r == 0) r = (*b)->info.compatible - (*a)->info.compatible;
  1559. +               if (r == 0) r = b->info.compatible - a->info.compatible;
  1560.                 /* Passworded servers should be below unpassworded servers */
  1561. -               if (r == 0) r = (*a)->info.use_password - (*b)->info.use_password;
  1562. +               if (r == 0) r = a->info.use_password - b->info.use_password;
  1563.                 /* Finally sort on the number of clients of the server */
  1564. -               if (r == 0) r = -NGameClientSorter(a, b);
  1565. +               if (r == 0) return !NGameClientSorter(a, b);
  1566.  
  1567. -               return r;
  1568. +               return r < 0;
  1569.         }
  1570.  
  1571.         /** Sort the server list */
  1572. diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
  1573. index 593851e28..beffb2ed8 100644
  1574. --- a/src/newgrf_config.cpp
  1575. +++ b/src/newgrf_config.cpp
  1576. @@ -10,6 +10,9 @@
  1577.  /** @file newgrf_config.cpp Finding NewGRFs and configuring them. */
  1578.  
  1579.  #include "stdafx.h"
  1580. +
  1581. +#include <algorithm>
  1582. +
  1583.  #include "debug.h"
  1584.  #include "3rdparty/md5/md5.h"
  1585.  #include "newgrf.h"
  1586. @@ -711,12 +714,9 @@ bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length, const
  1587.   * @param p2 the second GRFConfig *
  1588.   * @return the same strcmp would return for the name of the NewGRF.
  1589.   */
  1590. -static int CDECL GRFSorter(GRFConfig * const *p1, GRFConfig * const *p2)
  1591. +static bool CDECL GRFSorter(const GRFConfig * const p1, const GRFConfig * const p2)
  1592.  {
  1593. -       const GRFConfig *c1 = *p1;
  1594. -       const GRFConfig *c2 = *p2;
  1595. -
  1596. -       return strnatcmp(c1->GetName(), c2->GetName());
  1597. +       return strnatcmp(p1->GetName(), p2->GetName()) < 0;
  1598.  }
  1599.  
  1600.  /**
  1601. @@ -747,7 +747,7 @@ void DoScanNewGRFFiles(void *callback)
  1602.                 /* Number of files is not necessarily right */
  1603.                 num = i;
  1604.  
  1605. -               QSortT(to_sort, num, &GRFSorter);
  1606. +               std::sort(to_sort, to_sort + num, GRFSorter);
  1607.  
  1608.                 for (i = 1; i < num; i++) {
  1609.                         to_sort[i - 1]->next = to_sort[i];
  1610. diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
  1611. index 8dd8d545a..e3e821f75 100644
  1612. --- a/src/newgrf_engine.cpp
  1613. +++ b/src/newgrf_engine.cpp
  1614. @@ -10,6 +10,9 @@
  1615.  /** @file newgrf_engine.cpp NewGRF handling of engines. */
  1616.  
  1617.  #include "stdafx.h"
  1618. +
  1619. +#include <algorithm>
  1620. +
  1621.  #include "debug.h"
  1622.  #include "train.h"
  1623.  #include "roadveh.h"
  1624. @@ -1232,19 +1235,19 @@ void AlterVehicleListOrder(EngineID engine, uint target)
  1625.   * @param b right side
  1626.   * @return comparison result
  1627.   */
  1628. -static int CDECL EnginePreSort(const EngineID *a, const EngineID *b)
  1629. +static bool CDECL EnginePreSort(const EngineID a, const EngineID b)
  1630.  {
  1631. -       const EngineIDMapping *id_a = _engine_mngr.Get(*a);
  1632. -       const EngineIDMapping *id_b = _engine_mngr.Get(*b);
  1633. +       const EngineIDMapping *id_a = _engine_mngr.Get(a);
  1634. +       const EngineIDMapping *id_b = _engine_mngr.Get(b);
  1635.  
  1636.         /* 1. Sort by engine type */
  1637. -       if (id_a->type != id_b->type) return (int)id_a->type - (int)id_b->type;
  1638. +       if (id_a->type != id_b->type) return id_a->type < id_b->type;
  1639.  
  1640.         /* 2. Sort by scope-GRFID */
  1641. -       if (id_a->grfid != id_b->grfid) return id_a->grfid < id_b->grfid ? -1 : 1;
  1642. +       if (id_a->grfid != id_b->grfid) return id_a->grfid < id_b->grfid;
  1643.  
  1644.         /* 3. Sort by local ID */
  1645. -       return (int)id_a->internal_id - (int)id_b->internal_id;
  1646. +       return id_a->internal_id < id_b->internal_id;
  1647.  }
  1648.  
  1649.  /**
  1650. @@ -1258,7 +1261,7 @@ void CommitVehicleListOrderChanges()
  1651.         FOR_ALL_ENGINES(e) {
  1652.                 *ordering.Append() = e->index;
  1653.         }
  1654. -       QSortT(ordering.Begin(), ordering.Length(), EnginePreSort);
  1655. +       std::sort(ordering.Begin(), ordering.End(), EnginePreSort);
  1656.  
  1657.         /* Apply Insertion-Sort operations */
  1658.         const ListOrderChange *end = _list_order_changes.End();
  1659. diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp
  1660. index c3007ac42..ff93986ed 100644
  1661. --- a/src/newgrf_gui.cpp
  1662. +++ b/src/newgrf_gui.cpp
  1663. @@ -1434,15 +1434,12 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
  1664.  
  1665.  private:
  1666.         /** Sort grfs by name. */
  1667. -       static int CDECL NameSorter(const GRFConfig * const *a, const GRFConfig * const *b)
  1668. +       static bool CDECL NameSorter(const GRFConfig * const &a, const GRFConfig * const &b)
  1669.         {
  1670. -               int i = strnatcmp((*a)->GetName(), (*b)->GetName(), true); // Sort by name (natural sorting).
  1671. -               if (i != 0) return i;
  1672. +               int i = strnatcmp(a->GetName(), b->GetName(), true); // Sort by name (natural sorting).
  1673. +               if (i == 0) i = a->version - b->version;
  1674.  
  1675. -               i = (*a)->version - (*b)->version;
  1676. -               if (i != 0) return i;
  1677. -
  1678. -               return memcmp((*a)->ident.md5sum, (*b)->ident.md5sum, lengthof((*b)->ident.md5sum));
  1679. +               return i == 0 ? memcmp(a->ident.md5sum, b->ident.md5sum, lengthof(b->ident.md5sum)) < 0 : i < 0;
  1680.         }
  1681.  
  1682.         /** Filter grfs by tags/name */
  1683. diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
  1684. index 5582666b1..f01adda78 100644
  1685. --- a/src/rail_cmd.cpp
  1686. +++ b/src/rail_cmd.cpp
  1687. @@ -127,9 +127,9 @@ void ResolveRailTypeGUISprites(RailtypeInfo *rti)
  1688.   * @param second The railtype to compare.
  1689.   * @return True iff the first should be sorted before the second.
  1690.   */
  1691. -static int CDECL CompareRailTypes(const RailType *first, const RailType *second)
  1692. +static bool CDECL CompareRailTypes(const RailType &first, const RailType &second)
  1693.  {
  1694. -       return GetRailTypeInfo(*first)->sorting_order - GetRailTypeInfo(*second)->sorting_order;
  1695. +       return GetRailTypeInfo(first)->sorting_order < GetRailTypeInfo(second)->sorting_order;
  1696.  }
  1697.  
  1698.  /**
  1699. @@ -148,7 +148,7 @@ void InitRailTypes()
  1700.                         _sorted_railtypes[_sorted_railtypes_size++] = rt;
  1701.                 }
  1702.         }
  1703. -       QSortT(_sorted_railtypes, _sorted_railtypes_size, CompareRailTypes);
  1704. +       std::sort(_sorted_railtypes, _sorted_railtypes + _sorted_railtypes_size, CompareRailTypes);
  1705.  }
  1706.  
  1707.  /**
  1708. diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp
  1709. index 6cde709b0..4465a5ae7 100644
  1710. --- a/src/settings_gui.cpp
  1711. +++ b/src/settings_gui.cpp
  1712. @@ -203,7 +203,7 @@ struct GameOptionsWindow : Window {
  1713.                                         if (i == CURRENCY_CUSTOM) continue;
  1714.                                         *list->Append() = new DropDownListStringItem(*items, i, HasBit(disabled, i));
  1715.                                 }
  1716. -                               QSortT(list->Begin(), list->Length(), DropDownListStringItem::NatSortFunc);
  1717. +                               std::sort(list->Begin(), list->End(), DropDownListStringItem::NatSortFunc);
  1718.  
  1719.                                 /* Append custom currency at the end */
  1720.                                 *list->Append() = new DropDownListItem(-1, false); // separator line
  1721. @@ -241,7 +241,7 @@ struct GameOptionsWindow : Window {
  1722.                                         int result = _nb_orig_names + i;
  1723.                                         *list->Append() = new DropDownListStringItem(_grf_names[i], result, enabled_item != result && enabled_item >= 0);
  1724.                                 }
  1725. -                               QSortT(list->Begin(), list->Length(), DropDownListStringItem::NatSortFunc);
  1726. +                               std::sort(list->Begin(), list->End(), DropDownListStringItem::NatSortFunc);
  1727.  
  1728.                                 int newgrf_size = list->Length();
  1729.                                 /* Insert newgrf_names at the top of the list */
  1730. @@ -254,7 +254,7 @@ struct GameOptionsWindow : Window {
  1731.                                 for (int i = 0; i < _nb_orig_names; i++) {
  1732.                                         *list->Append() = new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + i, i, enabled_item != i && enabled_item >= 0);
  1733.                                 }
  1734. -                               QSortT(list->Begin() + newgrf_size, list->Length() - newgrf_size, DropDownListStringItem::NatSortFunc);
  1735. +                               std::sort(list->Begin() + newgrf_size, list->End(), DropDownListStringItem::NatSortFunc);
  1736.                                 break;
  1737.                         }
  1738.  
  1739. @@ -274,7 +274,7 @@ struct GameOptionsWindow : Window {
  1740.                                         if (&_languages[i] == _current_language) *selected_index = i;
  1741.                                         *list->Append() = new DropDownListStringItem(SPECSTR_LANGUAGE_START + i, i, false);
  1742.                                 }
  1743. -                               QSortT(list->Begin(), list->Length(), DropDownListStringItem::NatSortFunc);
  1744. +                               std::sort(list->Begin(), list->End(), DropDownListStringItem::NatSortFunc);
  1745.                                 break;
  1746.                         }
  1747.  
  1748. diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp
  1749. index 020ee1b6e..d7b396624 100644
  1750. --- a/src/signs_gui.cpp
  1751. +++ b/src/signs_gui.cpp
  1752. @@ -72,23 +72,22 @@ struct SignList {
  1753.         }
  1754.  
  1755.         /** Sort signs by their name */
  1756. -       static int CDECL SignNameSorter(const Sign * const *a, const Sign * const *b)
  1757. +       static bool CDECL SignNameSorter(const Sign * const &a, const Sign * const &b)
  1758.         {
  1759.                 static char buf_cache[64];
  1760.                 char buf[64];
  1761.  
  1762. -               SetDParam(0, (*a)->index);
  1763. +               SetDParam(0, a->index);
  1764.                 GetString(buf, STR_SIGN_NAME, lastof(buf));
  1765.  
  1766. -               if (*b != last_sign) {
  1767. -                       last_sign = *b;
  1768. -                       SetDParam(0, (*b)->index);
  1769. +               if (b != last_sign) {
  1770. +                       last_sign = b;
  1771. +                       SetDParam(0, b->index);
  1772.                         GetString(buf_cache, STR_SIGN_NAME, lastof(buf_cache));
  1773.                 }
  1774.  
  1775.                 int r = strnatcmp(buf, buf_cache); // Sort by name (natural sorting).
  1776. -
  1777. -               return r != 0 ? r : ((*a)->index - (*b)->index);
  1778. +               return r != 0 ? r < 0 : (a->index < b->index);
  1779.         }
  1780.  
  1781.         void SortSignsList()
  1782. diff --git a/src/sortlist_type.h b/src/sortlist_type.h
  1783. index 1a30c3b1a..68924f446 100644
  1784. --- a/src/sortlist_type.h
  1785. +++ b/src/sortlist_type.h
  1786. @@ -12,9 +12,11 @@
  1787.  #ifndef SORTLIST_TYPE_H
  1788.  #define SORTLIST_TYPE_H
  1789.  
  1790. +#include <algorithm>
  1791. +#include <functional>
  1792. +
  1793.  #include "core/enum_type.hpp"
  1794.  #include "core/bitmath_func.hpp"
  1795. -#include "core/sort_func.hpp"
  1796.  #include "core/smallvec_type.hpp"
  1797.  #include "date_type.h"
  1798.  
  1799. @@ -41,6 +43,19 @@ struct Filtering {
  1800.         byte criteria; ///< Filtering criteria
  1801.  };
  1802.  
  1803. +template <typename F, typename T>
  1804. +struct BinNegator {
  1805. +       F *f;
  1806. +       BinNegator(F *f) : f(f) {}
  1807. +
  1808. +       bool operator()(const T &a, const T &b) { return !f(a, b); };
  1809. +
  1810. +       static BinNegator<F, T> Make(F *f)
  1811. +       {
  1812. +               return BinNegator<F, T>(f);
  1813. +       }
  1814. +};
  1815. +
  1816.  /**
  1817.   * List template of 'things' \p T to sort in a GUI.
  1818.   * @tparam T Type of data stored in the list to represent each item.
  1819. @@ -49,8 +64,8 @@ struct Filtering {
  1820.  template <typename T, typename F = const char*>
  1821.  class GUIList : public SmallVector<T, 32> {
  1822.  public:
  1823. -       typedef int CDECL SortFunction(const T*, const T*); ///< Signature of sort function.
  1824. -       typedef bool CDECL FilterFunction(const T*, F);     ///< Signature of filter function.
  1825. +       typedef bool CDECL SortFunction(const T&, const T&); ///< Signature of sort function.
  1826. +       typedef bool CDECL FilterFunction(const T*, F);      ///< Signature of filter function.
  1827.  
  1828.  protected:
  1829.         SortFunction * const *sort_func_list;     ///< the sort criteria functions
  1830. @@ -265,16 +280,12 @@ public:
  1831.                 /* Do not sort when the list is not sortable */
  1832.                 if (!this->IsSortable()) return false;
  1833.  
  1834. -               const bool desc = (this->flags & VL_DESC) != 0;
  1835. -
  1836.                 if (this->flags & VL_FIRST_SORT) {
  1837.                         CLRBITS(this->flags, VL_FIRST_SORT);
  1838. -
  1839. -                       QSortT(this->data, this->items, compare, desc);
  1840. -                       return true;
  1841.                 }
  1842.  
  1843. -               GSortT(this->data, this->items, compare, desc);
  1844. +               const bool desc = (this->flags & VL_DESC) != 0;
  1845. +               std::sort(this->Begin(), this->End(), desc ? BinNegator<SortFunction, T>::Make(compare) : compare);
  1846.                 return true;
  1847.         }
  1848.  
  1849. diff --git a/src/station_gui.cpp b/src/station_gui.cpp
  1850. index 7399fe006..5df763ee4 100644
  1851. --- a/src/station_gui.cpp
  1852. +++ b/src/station_gui.cpp
  1853. @@ -209,85 +209,80 @@ protected:
  1854.         }
  1855.  
  1856.         /** Sort stations by their name */
  1857. -       static int CDECL StationNameSorter(const Station * const *a, const Station * const *b)
  1858. +       static bool CDECL StationNameSorter(const Station * const &a, const Station * const &b)
  1859.         {
  1860.                 static char buf_cache[64];
  1861.                 char buf[64];
  1862.  
  1863. -               SetDParam(0, (*a)->index);
  1864. +               SetDParam(0, a->index);
  1865.                 GetString(buf, STR_STATION_NAME, lastof(buf));
  1866.  
  1867. -               if (*b != last_station) {
  1868. -                       last_station = *b;
  1869. -                       SetDParam(0, (*b)->index);
  1870. +               if (b != last_station) {
  1871. +                       last_station = b;
  1872. +                       SetDParam(0, b->index);
  1873.                         GetString(buf_cache, STR_STATION_NAME, lastof(buf_cache));
  1874.                 }
  1875.  
  1876.                 int r = strnatcmp(buf, buf_cache); // Sort by name (natural sorting).
  1877. -               if (r == 0) return (*a)->index - (*b)->index;
  1878. -               return r;
  1879. +               return r == 0 ? a->index < b->index : r < 0;
  1880.         }
  1881.  
  1882.         /** Sort stations by their type */
  1883. -       static int CDECL StationTypeSorter(const Station * const *a, const Station * const *b)
  1884. +       static bool CDECL StationTypeSorter(const Station * const &a, const Station * const &b)
  1885.         {
  1886. -               return (*a)->facilities - (*b)->facilities;
  1887. +               return a->facilities - b->facilities;
  1888.         }
  1889.  
  1890.         /** Sort stations by their waiting cargo */
  1891. -       static int CDECL StationWaitingTotalSorter(const Station * const *a, const Station * const *b)
  1892. +       static bool CDECL StationWaitingTotalSorter(const Station * const &a, const Station * const &b)
  1893.         {
  1894.                 int diff = 0;
  1895.  
  1896.                 CargoID j;
  1897.                 FOR_EACH_SET_CARGO_ID(j, cargo_filter) {
  1898. -                       diff += (*a)->goods[j].cargo.TotalCount() - (*b)->goods[j].cargo.TotalCount();
  1899. +                       diff += a->goods[j].cargo.TotalCount() - b->goods[j].cargo.TotalCount();
  1900.                 }
  1901. -
  1902. -               return diff;
  1903. +               return diff < 0;
  1904.         }
  1905.  
  1906.         /** Sort stations by their available waiting cargo */
  1907. -       static int CDECL StationWaitingAvailableSorter(const Station * const *a, const Station * const *b)
  1908. +       static bool CDECL StationWaitingAvailableSorter(const Station * const &a, const Station * const &b)
  1909.         {
  1910.                 int diff = 0;
  1911.  
  1912.                 CargoID j;
  1913.                 FOR_EACH_SET_CARGO_ID(j, cargo_filter) {
  1914. -                       diff += (*a)->goods[j].cargo.AvailableCount() - (*b)->goods[j].cargo.AvailableCount();
  1915. +                       diff += a->goods[j].cargo.AvailableCount() - b->goods[j].cargo.AvailableCount();
  1916.                 }
  1917. -
  1918. -               return diff;
  1919. +               return diff < 0;
  1920.         }
  1921.  
  1922.         /** Sort stations by their rating */
  1923. -       static int CDECL StationRatingMaxSorter(const Station * const *a, const Station * const *b)
  1924. +       static bool CDECL StationRatingMaxSorter(const Station * const &a, const Station * const &b)
  1925.         {
  1926.                 byte maxr1 = 0;
  1927.                 byte maxr2 = 0;
  1928.  
  1929.                 CargoID j;
  1930.                 FOR_EACH_SET_CARGO_ID(j, cargo_filter) {
  1931. -                       if ((*a)->goods[j].HasRating()) maxr1 = max(maxr1, (*a)->goods[j].rating);
  1932. -                       if ((*b)->goods[j].HasRating()) maxr2 = max(maxr2, (*b)->goods[j].rating);
  1933. +                       if (a->goods[j].HasRating()) maxr1 = max(maxr1, a->goods[j].rating);
  1934. +                       if (b->goods[j].HasRating()) maxr2 = max(maxr2, b->goods[j].rating);
  1935.                 }
  1936. -
  1937. -               return maxr1 - maxr2;
  1938. +               return maxr1 < maxr2;
  1939.         }
  1940.  
  1941.         /** Sort stations by their rating */
  1942. -       static int CDECL StationRatingMinSorter(const Station * const *a, const Station * const *b)
  1943. +       static bool CDECL StationRatingMinSorter(const Station * const &a, const Station * const &b)
  1944.         {
  1945.                 byte minr1 = 255;
  1946.                 byte minr2 = 255;
  1947.  
  1948.                 for (CargoID j = 0; j < NUM_CARGO; j++) {
  1949.                         if (!HasBit(cargo_filter, j)) continue;
  1950. -                       if ((*a)->goods[j].HasRating()) minr1 = min(minr1, (*a)->goods[j].rating);
  1951. -                       if ((*b)->goods[j].HasRating()) minr2 = min(minr2, (*b)->goods[j].rating);
  1952. +                       if (a->goods[j].HasRating()) minr1 = min(minr1, a->goods[j].rating);
  1953. +                       if (b->goods[j].HasRating()) minr2 = min(minr2, b->goods[j].rating);
  1954.                 }
  1955. -
  1956. -               return -(minr1 - minr2);
  1957. +               return !(minr1 < minr2);
  1958.         }
  1959.  
  1960.         /** Sort the stations list */
  1961. diff --git a/src/story_gui.cpp b/src/story_gui.cpp
  1962. index 003843310..2ee00225c 100644
  1963. --- a/src/story_gui.cpp
  1964. +++ b/src/story_gui.cpp
  1965. @@ -69,9 +69,9 @@ protected:
  1966.         }
  1967.  
  1968.         /** Sort story pages by order value. */
  1969. -       static int CDECL PageOrderSorter(const StoryPage * const *a, const StoryPage * const *b)
  1970. +       static bool CDECL PageOrderSorter(const StoryPage * const &a, const StoryPage * const &b)
  1971.         {
  1972. -               return (*a)->sort_value - (*b)->sort_value;
  1973. +               return a->sort_value < b->sort_value;
  1974.         }
  1975.  
  1976.         /** (Re)Build story page element list. */
  1977. @@ -98,9 +98,9 @@ protected:
  1978.         }
  1979.  
  1980.         /** Sort story page elements by order value. */
  1981. -       static int CDECL PageElementOrderSorter(const StoryPageElement * const *a, const StoryPageElement * const *b)
  1982. +       static bool CDECL PageElementOrderSorter(const StoryPageElement * const &a, const StoryPageElement * const &b)
  1983.         {
  1984. -               return (*a)->sort_value - (*b)->sort_value;
  1985. +               return a->sort_value < b->sort_value;
  1986.         }
  1987.  
  1988.         /*
  1989. diff --git a/src/strings.cpp b/src/strings.cpp
  1990. index 1c539d934..476a9095d 100644
  1991. --- a/src/strings.cpp
  1992. +++ b/src/strings.cpp
  1993. @@ -1857,14 +1857,14 @@ const char *GetCurrentLocale(const char *param)
  1994.  const char *GetCurrentLocale(const char *param);
  1995.  #endif /* !(defined(WIN32) || defined(__APPLE__)) */
  1996.  
  1997. -int CDECL StringIDSorter(const StringID *a, const StringID *b)
  1998. +bool CDECL StringIDSorter(const StringID &a, const StringID &b)
  1999.  {
  2000.         char stra[512];
  2001.         char strb[512];
  2002. -       GetString(stra, *a, lastof(stra));
  2003. -       GetString(strb, *b, lastof(strb));
  2004. +       GetString(stra, a, lastof(stra));
  2005. +       GetString(strb, b, lastof(strb));
  2006.  
  2007. -       return strnatcmp(stra, strb);
  2008. +       return strnatcmp(stra, strb) < 0;
  2009.  }
  2010.  
  2011.  /**
  2012. diff --git a/src/strings_func.h b/src/strings_func.h
  2013. index 0da711bc4..4d17a5462 100644
  2014. --- a/src/strings_func.h
  2015. +++ b/src/strings_func.h
  2016. @@ -238,7 +238,7 @@ extern TextDirection _current_text_dir; ///< Text direction of the currently sel
  2017.  void InitializeLanguagePacks();
  2018.  const char *GetCurrentLanguageIsoCode();
  2019.  
  2020. -int CDECL StringIDSorter(const StringID *a, const StringID *b);
  2021. +bool CDECL StringIDSorter(const StringID &a, const StringID &b);
  2022.  
  2023.  /**
  2024.   * A searcher for missing glyphs.
  2025. diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp
  2026. index 29986c353..274d4a68e 100644
  2027. --- a/src/timetable_cmd.cpp
  2028. +++ b/src/timetable_cmd.cpp
  2029. @@ -16,7 +16,6 @@
  2030.  #include "window_func.h"
  2031.  #include "vehicle_base.h"
  2032.  #include "cmd_helper.h"
  2033. -#include "core/sort_func.hpp"
  2034.  
  2035.  #include "table/strings.h"
  2036.  
  2037. @@ -220,11 +219,8 @@ CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1,
  2038.   * @param bp Second Vehicle pointer.
  2039.   * @return Comparison value.
  2040.   */
  2041. -static int CDECL VehicleTimetableSorter(Vehicle * const *ap, Vehicle * const *bp)
  2042. +static bool CDECL VehicleTimetableSorter(Vehicle * const &a, Vehicle * const &b)
  2043.  {
  2044. -       const Vehicle *a = *ap;
  2045. -       const Vehicle *b = *bp;
  2046. -
  2047.         VehicleOrderID a_order = a->cur_real_order_index;
  2048.         VehicleOrderID b_order = b->cur_real_order_index;
  2049.         int j = (int)b_order - (int)a_order;
  2050. @@ -242,15 +238,15 @@ static int CDECL VehicleTimetableSorter(Vehicle * const *ap, Vehicle * const *bp
  2051.  
  2052.         /* First check the order index that accounted for loading, then just the raw one. */
  2053.         int i = (int)b_order - (int)a_order;
  2054. -       if (i != 0) return i;
  2055. -       if (j != 0) return j;
  2056. +       if (i != 0) return i < 0;
  2057. +       if (j != 0) return j < 0;
  2058.  
  2059.         /* Look at the time we spent in this order; the higher, the closer to its destination. */
  2060.         i = b->current_order_time - a->current_order_time;
  2061. -       if (i != 0) return i;
  2062. +       if (i != 0) return i < 0;
  2063.  
  2064.         /* If all else is equal, use some unique index to sort it the same way. */
  2065. -       return b->unitnumber - a->unitnumber;
  2066. +       return b->unitnumber < a->unitnumber;
  2067.  }
  2068.  
  2069.  /**
  2070. @@ -295,7 +291,7 @@ CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1,
  2071.                 int num_vehs = vehs.Length();
  2072.  
  2073.                 if (num_vehs >= 2) {
  2074. -                       QSortT(vehs.Begin(), vehs.Length(), &VehicleTimetableSorter);
  2075. +                       std::sort(vehs.Begin(), vehs.End(), &VehicleTimetableSorter);
  2076.                 }
  2077.  
  2078.                 int base = vehs.FindIndex(v);
  2079. diff --git a/src/town_gui.cpp b/src/town_gui.cpp
  2080. index 142966b69..e7c82be53 100644
  2081. --- a/src/town_gui.cpp
  2082. +++ b/src/town_gui.cpp
  2083. @@ -666,11 +666,11 @@ private:
  2084.         }
  2085.  
  2086.         /** Sort by town name */
  2087. -       static int CDECL TownNameSorter(const Town * const *a, const Town * const *b)
  2088. +       static bool CDECL TownNameSorter(const Town * const &a, const Town * const &b)
  2089.         {
  2090.                 static char buf_cache[64];
  2091. -               const Town *ta = *a;
  2092. -               const Town *tb = *b;
  2093. +               const Town *ta = a;
  2094. +               const Town *tb = b;
  2095.                 char buf[64];
  2096.  
  2097.                 SetDParam(0, ta->index);
  2098. @@ -685,35 +685,35 @@ private:
  2099.                         GetString(buf_cache, STR_TOWN_NAME, lastof(buf_cache));
  2100.                 }
  2101.  
  2102. -               return strnatcmp(buf, buf_cache); // Sort by name (natural sorting).
  2103. +               return strnatcmp(buf, buf_cache) < 0; // Sort by name (natural sorting).
  2104.         }
  2105.  
  2106.         /** Sort by population (default descending, as big towns are of the most interest). */
  2107. -       static int CDECL TownPopulationSorter(const Town * const *a, const Town * const *b)
  2108. +       static bool CDECL TownPopulationSorter(const Town * const &a, const Town * const &b)
  2109.         {
  2110. -               uint32 a_population = (*a)->cache.population;
  2111. -               uint32 b_population = (*b)->cache.population;
  2112. +               uint32 a_population = a->cache.population;
  2113. +               uint32 b_population = b->cache.population;
  2114.                 if (a_population == b_population) return TownDirectoryWindow::TownNameSorter(a, b);
  2115. -               return (a_population < b_population) ? -1 : 1;
  2116. +               return a_population < b_population;
  2117.         }
  2118.  
  2119.         /** Sort by town rating */
  2120. -       static int CDECL TownRatingSorter(const Town * const *a, const Town * const *b)
  2121. +       static bool CDECL TownRatingSorter(const Town * const &a, const Town * const &b)
  2122.         {
  2123. -               int before = TownDirectoryWindow::last_sorting.order ? 1 : -1; // Value to get 'a' before 'b'.
  2124. +               bool before = !TownDirectoryWindow::last_sorting.order; // Value to get 'a' before 'b'.
  2125.  
  2126.                 /* Towns without rating are always after towns with rating. */
  2127. -               if (HasBit((*a)->have_ratings, _local_company)) {
  2128. -                       if (HasBit((*b)->have_ratings, _local_company)) {
  2129. -                               int16 a_rating = (*a)->ratings[_local_company];
  2130. -                               int16 b_rating = (*b)->ratings[_local_company];
  2131. +               if (HasBit(a->have_ratings, _local_company)) {
  2132. +                       if (HasBit(b->have_ratings, _local_company)) {
  2133. +                               int16 a_rating = a->ratings[_local_company];
  2134. +                               int16 b_rating = b->ratings[_local_company];
  2135.                                 if (a_rating == b_rating) return TownDirectoryWindow::TownNameSorter(a, b);
  2136. -                               return (a_rating < b_rating) ? -1 : 1;
  2137. +                               return a_rating < b_rating;
  2138.                         }
  2139.                         return before;
  2140.                 }
  2141. -               if (HasBit((*b)->have_ratings, _local_company)) return -before;
  2142. -               return -before * TownDirectoryWindow::TownNameSorter(a, b); // Sort unrated towns always on ascending town name.
  2143. +               if (HasBit(b->have_ratings, _local_company)) return !before;
  2144. +               return !before && TownDirectoryWindow::TownNameSorter(a, b); // Sort unrated towns always on ascending town name.
  2145.         }
  2146.  
  2147.  public:
  2148. diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
  2149. index b9c24ddd0..9d2fe7b54 100644
  2150. --- a/src/vehicle_gui.cpp
  2151. +++ b/src/vehicle_gui.cpp
  2152. @@ -194,7 +194,7 @@ void BaseVehicleListWindow::SortVehicleList()
  2153.  void DepotSortList(VehicleList *list)
  2154.  {
  2155.         if (list->Length() < 2) return;
  2156. -       QSortT(list->Begin(), list->Length(), &VehicleNumberSorter);
  2157. +       std::sort(list->Begin(), list->End(), &VehicleNumberSorter);
  2158.  }
  2159.  
  2160.  /** draw the vehicle profit button in the vehicle list window. */
  2161. @@ -1085,62 +1085,61 @@ StringID GetCargoSubtypeText(const Vehicle *v)
  2162.  }
  2163.  
  2164.  /** Sort vehicles by their number */
  2165. -static int CDECL VehicleNumberSorter(const Vehicle * const *a, const Vehicle * const *b)
  2166. +static bool CDECL VehicleNumberSorter(const Vehicle * const &a, const Vehicle * const &b)
  2167.  {
  2168. -       return (*a)->unitnumber - (*b)->unitnumber;
  2169. +       return a->unitnumber < b->unitnumber;
  2170.  }
  2171.  
  2172.  /** Sort vehicles by their name */
  2173. -static int CDECL VehicleNameSorter(const Vehicle * const *a, const Vehicle * const *b)
  2174. +static bool CDECL VehicleNameSorter(const Vehicle * const &a, const Vehicle * const &b)
  2175.  {
  2176.         static char last_name[2][64];
  2177.  
  2178. -       if (*a != _last_vehicle[0]) {
  2179. -               _last_vehicle[0] = *a;
  2180. -               SetDParam(0, (*a)->index);
  2181. +       if (a != _last_vehicle[0]) {
  2182. +               _last_vehicle[0] = a;
  2183. +               SetDParam(0, a->index);
  2184.                 GetString(last_name[0], STR_VEHICLE_NAME, lastof(last_name[0]));
  2185.         }
  2186.  
  2187. -       if (*b != _last_vehicle[1]) {
  2188. -               _last_vehicle[1] = *b;
  2189. -               SetDParam(0, (*b)->index);
  2190. +       if (b != _last_vehicle[1]) {
  2191. +               _last_vehicle[1] = b;
  2192. +               SetDParam(0, b->index);
  2193.                 GetString(last_name[1], STR_VEHICLE_NAME, lastof(last_name[1]));
  2194.         }
  2195.  
  2196.         int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting).
  2197. -       return (r != 0) ? r : VehicleNumberSorter(a, b);
  2198. +       return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
  2199.  }
  2200.  
  2201.  /** Sort vehicles by their age */
  2202. -static int CDECL VehicleAgeSorter(const Vehicle * const *a, const Vehicle * const *b)
  2203. +static bool CDECL VehicleAgeSorter(const Vehicle * const &a, const Vehicle * const &b)
  2204.  {
  2205. -       int r = (*a)->age - (*b)->age;
  2206. -       return (r != 0) ? r : VehicleNumberSorter(a, b);
  2207. +       return a->age != b->age ? a->age < b->age : VehicleNumberSorter(a, b);
  2208.  }
  2209.  
  2210.  /** Sort vehicles by this year profit */
  2211. -static int CDECL VehicleProfitThisYearSorter(const Vehicle * const *a, const Vehicle * const *b)
  2212. +static bool CDECL VehicleProfitThisYearSorter(const Vehicle * const &a, const Vehicle * const &b)
  2213.  {
  2214. -       int r = ClampToI32((*a)->GetDisplayProfitThisYear() - (*b)->GetDisplayProfitThisYear());
  2215. -       return (r != 0) ? r : VehicleNumberSorter(a, b);
  2216. +       int r = ClampToI32(a->GetDisplayProfitThisYear() - b->GetDisplayProfitThisYear());
  2217. +       return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
  2218.  }
  2219.  
  2220.  /** Sort vehicles by last year profit */
  2221. -static int CDECL VehicleProfitLastYearSorter(const Vehicle * const *a, const Vehicle * const *b)
  2222. +static bool CDECL VehicleProfitLastYearSorter(const Vehicle * const &a, const Vehicle * const &b)
  2223.  {
  2224. -       int r = ClampToI32((*a)->GetDisplayProfitLastYear() - (*b)->GetDisplayProfitLastYear());
  2225. -       return (r != 0) ? r : VehicleNumberSorter(a, b);
  2226. +       int r = ClampToI32(a->GetDisplayProfitLastYear() - b->GetDisplayProfitLastYear());
  2227. +       return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
  2228.  }
  2229.  
  2230.  /** Sort vehicles by their cargo */
  2231. -static int CDECL VehicleCargoSorter(const Vehicle * const *a, const Vehicle * const *b)
  2232. +static bool CDECL VehicleCargoSorter(const Vehicle * const &a, const Vehicle * const &b)
  2233.  {
  2234.         const Vehicle *v;
  2235.         CargoArray diff;
  2236.  
  2237.         /* Append the cargo of the connected waggons */
  2238. -       for (v = *a; v != NULL; v = v->Next()) diff[v->cargo_type] += v->cargo_cap;
  2239. -       for (v = *b; v != NULL; v = v->Next()) diff[v->cargo_type] -= v->cargo_cap;
  2240. +       for (v = a; v != NULL; v = v->Next()) diff[v->cargo_type] += v->cargo_cap;
  2241. +       for (v = b; v != NULL; v = v->Next()) diff[v->cargo_type] -= v->cargo_cap;
  2242.  
  2243.         int r = 0;
  2244.         for (CargoID i = 0; i < NUM_CARGO; i++) {
  2245. @@ -1148,62 +1147,62 @@ static int CDECL VehicleCargoSorter(const Vehicle * const *a, const Vehicle * co
  2246.                 if (r != 0) break;
  2247.         }
  2248.  
  2249. -       return (r != 0) ? r : VehicleNumberSorter(a, b);
  2250. +       return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
  2251.  }
  2252.  
  2253.  /** Sort vehicles by their reliability */
  2254. -static int CDECL VehicleReliabilitySorter(const Vehicle * const *a, const Vehicle * const *b)
  2255. +static bool CDECL VehicleReliabilitySorter(const Vehicle * const &a, const Vehicle * const &b)
  2256.  {
  2257. -       int r = (*a)->reliability - (*b)->reliability;
  2258. -       return (r != 0) ? r : VehicleNumberSorter(a, b);
  2259. +       int r = a->reliability - b->reliability;
  2260. +       return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
  2261.  }
  2262.  
  2263.  /** Sort vehicles by their max speed */
  2264. -static int CDECL VehicleMaxSpeedSorter(const Vehicle * const *a, const Vehicle * const *b)
  2265. +static bool CDECL VehicleMaxSpeedSorter(const Vehicle * const &a, const Vehicle * const &b)
  2266.  {
  2267. -       int r = (*a)->vcache.cached_max_speed - (*b)->vcache.cached_max_speed;
  2268. -       return (r != 0) ? r : VehicleNumberSorter(a, b);
  2269. +       int r = a->vcache.cached_max_speed - b->vcache.cached_max_speed;
  2270. +       return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
  2271.  }
  2272.  
  2273.  /** Sort vehicles by model */
  2274. -static int CDECL VehicleModelSorter(const Vehicle * const *a, const Vehicle * const *b)
  2275. +static bool CDECL VehicleModelSorter(const Vehicle * const &a, const Vehicle * const &b)
  2276.  {
  2277. -       int r = (*a)->engine_type - (*b)->engine_type;
  2278. -       return (r != 0) ? r : VehicleNumberSorter(a, b);
  2279. +       int r = a->engine_type - b->engine_type;
  2280. +       return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
  2281.  }
  2282.  
  2283.  /** Sort vehicles by their value */
  2284. -static int CDECL VehicleValueSorter(const Vehicle * const *a, const Vehicle * const *b)
  2285. +static bool CDECL VehicleValueSorter(const Vehicle * const &a, const Vehicle * const &b)
  2286.  {
  2287.         const Vehicle *u;
  2288.         Money diff = 0;
  2289.  
  2290. -       for (u = *a; u != NULL; u = u->Next()) diff += u->value;
  2291. -       for (u = *b; u != NULL; u = u->Next()) diff -= u->value;
  2292. +       for (u = a; u != NULL; u = u->Next()) diff += u->value;
  2293. +       for (u = b; u != NULL; u = u->Next()) diff -= u->value;
  2294.  
  2295.         int r = ClampToI32(diff);
  2296. -       return (r != 0) ? r : VehicleNumberSorter(a, b);
  2297. +       return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
  2298.  }
  2299.  
  2300.  /** Sort vehicles by their length */
  2301. -static int CDECL VehicleLengthSorter(const Vehicle * const *a, const Vehicle * const *b)
  2302. +static bool CDECL VehicleLengthSorter(const Vehicle * const &a, const Vehicle * const &b)
  2303.  {
  2304. -       int r = (*a)->GetGroundVehicleCache()->cached_total_length - (*b)->GetGroundVehicleCache()->cached_total_length;
  2305. -       return (r != 0) ? r : VehicleNumberSorter(a, b);
  2306. +       int r = a->GetGroundVehicleCache()->cached_total_length - b->GetGroundVehicleCache()->cached_total_length;
  2307. +       return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
  2308.  }
  2309.  
  2310.  /** Sort vehicles by the time they can still live */
  2311. -static int CDECL VehicleTimeToLiveSorter(const Vehicle * const *a, const Vehicle * const *b)
  2312. +static bool CDECL VehicleTimeToLiveSorter(const Vehicle * const &a, const Vehicle * const &b)
  2313.  {
  2314. -       int r = ClampToI32(((*a)->max_age - (*a)->age) - ((*b)->max_age - (*b)->age));
  2315. -       return (r != 0) ? r : VehicleNumberSorter(a, b);
  2316. +       int r = ClampToI32((a->max_age - a->age) - (b->max_age - b->age));
  2317. +       return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
  2318.  }
  2319.  
  2320.  /** Sort vehicles by the timetable delay */
  2321. -static int CDECL VehicleTimetableDelaySorter(const Vehicle * const *a, const Vehicle * const *b)
  2322. +static bool CDECL VehicleTimetableDelaySorter(const Vehicle * const &a, const Vehicle * const &b)
  2323.  {
  2324. -       int r = (*a)->lateness_counter - (*b)->lateness_counter;
  2325. -       return (r != 0) ? r : VehicleNumberSorter(a, b);
  2326. +       int r = a->lateness_counter - b->lateness_counter;
  2327. +       return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
  2328.  }
  2329.  
  2330.  void InitializeGUI()
  2331. diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm
  2332. index 4df7cb003..4618a45b2 100644
  2333. --- a/src/video/cocoa/cocoa_v.mm
  2334. +++ b/src/video/cocoa/cocoa_v.mm
  2335. @@ -36,6 +36,7 @@
  2336.  #include "../../window_func.h"
  2337.  #include "../../window_gui.h"
  2338.  
  2339. +#import <sort>
  2340.  #import <sys/param.h> /* for MAXPATHLEN */
  2341.  
  2342.  /**
  2343. @@ -278,7 +279,7 @@ uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_i
  2344.         }
  2345.  
  2346.         /* Sort list smallest to largest */
  2347. -       QSortT(modes, count, &ModeSorter);
  2348. +       std::sort(modes, modes + count, &ModeSorter);
  2349.  
  2350.         return count;
  2351.  }
  2352. diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp
  2353. index d4c229cb1..7f5fce130 100644
  2354. --- a/src/widgets/dropdown.cpp
  2355. +++ b/src/widgets/dropdown.cpp
  2356. @@ -50,12 +50,12 @@ void DropDownListStringItem::Draw(int left, int right, int top, int bottom, bool
  2357.   * @return true if \a first precedes \a second.
  2358.   * @warning All items in the list need to be derivates of DropDownListStringItem.
  2359.   */
  2360. -/* static */ int DropDownListStringItem::NatSortFunc(const DropDownListItem * const *first, const DropDownListItem * const * second)
  2361. +/* static */ bool DropDownListStringItem::NatSortFunc(const DropDownListItem * const &first, const DropDownListItem * const &second)
  2362.  {
  2363.         char buffer1[512], buffer2[512];
  2364. -       GetString(buffer1, static_cast<const DropDownListStringItem*>(*first)->String(), lastof(buffer1));
  2365. -       GetString(buffer2, static_cast<const DropDownListStringItem*>(*second)->String(), lastof(buffer2));
  2366. -       return strnatcmp(buffer1, buffer2);
  2367. +       GetString(buffer1, static_cast<const DropDownListStringItem*>(first)->String(), lastof(buffer1));
  2368. +       GetString(buffer2, static_cast<const DropDownListStringItem*>(second)->String(), lastof(buffer2));
  2369. +       return strnatcmp(buffer1, buffer2) < 0;
  2370.  }
  2371.  
  2372.  StringID DropDownListParamStringItem::String() const
  2373. diff --git a/src/widgets/dropdown_type.h b/src/widgets/dropdown_type.h
  2374. index b65d4557b..e87ea1e85 100644
  2375. --- a/src/widgets/dropdown_type.h
  2376. +++ b/src/widgets/dropdown_type.h
  2377. @@ -50,7 +50,7 @@ public:
  2378.         virtual void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const;
  2379.         virtual StringID String() const { return this->string; }
  2380.  
  2381. -       static int CDECL NatSortFunc(const DropDownListItem * const *first, const DropDownListItem * const *second);
  2382. +       static bool CDECL NatSortFunc(const DropDownListItem * const &first, const DropDownListItem * const &second);
  2383.  };
  2384.  
  2385.  /**
  2386. diff --git a/src/window.cpp b/src/window.cpp
  2387. index 8378f60f7..b901abc77 100644
  2388. --- a/src/window.cpp
  2389. +++ b/src/window.cpp
  2390. @@ -150,10 +150,10 @@ void WindowDesc::LoadFromConfig()
  2391.  /**
  2392.   * Sort WindowDesc by ini_key.
  2393.   */
  2394. -static int CDECL DescSorter(WindowDesc * const *a, WindowDesc * const *b)
  2395. +static bool CDECL DescSorter(WindowDesc * const &a, WindowDesc * const &b)
  2396.  {
  2397. -       if ((*a)->ini_key != NULL && (*b)->ini_key != NULL) return strcmp((*a)->ini_key, (*b)->ini_key);
  2398. -       return ((*b)->ini_key != NULL ? 1 : 0) - ((*a)->ini_key != NULL ? 1 : 0);
  2399. +       if (a->ini_key != NULL && b->ini_key != NULL) return strcmp(a->ini_key, b->ini_key) < 0;
  2400. +       return a->ini_key != NULL;
  2401.  }
  2402.  
  2403.  /**
  2404. @@ -162,7 +162,7 @@ static int CDECL DescSorter(WindowDesc * const *a, WindowDesc * const *b)
  2405.  void WindowDesc::SaveToConfig()
  2406.  {
  2407.         /* Sort the stuff to get a nice ini file on first write */
  2408. -       QSortT(_window_descs->Begin(), _window_descs->Length(), DescSorter);
  2409. +       std::sort(_window_descs->Begin(), _window_descs->End(), &DescSorter);
  2410.  
  2411.         IniFile *ini = new IniFile();
  2412.         ini->LoadFromDisk(_windows_file, NO_DIRECTORY);

Version history

Revision # Author Created at
pfskzrsgp Anonymous 17 Jun 2017, 09:07:48 UTC Diff

Comments