Simplify some implementations of operator< using lexicographical tuple comparison
Might do operator== later too.
This commit is contained in:
parent
a77652986a
commit
ccb5d8f795
8 changed files with 16 additions and 14 deletions
|
@ -19,6 +19,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
#include <SDL_ttf.h>
|
||||
|
||||
/***
|
||||
|
@ -42,7 +44,7 @@ struct font_id
|
|||
}
|
||||
bool operator<(const font_id& o) const
|
||||
{
|
||||
return subset < o.subset || (subset == o.subset && size < o.size) || (subset == o.subset && size == o.size && style < o.style);
|
||||
return std::tie(subset, size, style) < std::tie(o.subset, o.size, o.style);
|
||||
}
|
||||
|
||||
subset_id subset;
|
||||
|
|
|
@ -50,8 +50,9 @@ private:
|
|||
std::string level_type;
|
||||
std::string id;
|
||||
|
||||
friend bool operator<(const option_source& a, const option_source& b) {
|
||||
return a.level_type < b.level_type || (a.level_type == b.level_type && a.id < b.id);
|
||||
friend bool operator<(const option_source& a, const option_source& b)
|
||||
{
|
||||
return std::tie(a.level_type, a.id) < std::tie(b.level_type, b.id);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -89,10 +89,7 @@ struct key_type
|
|||
|
||||
static bool operator<(const key_type& lhs, const key_type& rhs)
|
||||
{
|
||||
return lhs.w < rhs.w
|
||||
|| (lhs.w == rhs.w
|
||||
&& (lhs.h < rhs.h
|
||||
|| (lhs.h == rhs.h && lhs.map_data < rhs.map_data)));
|
||||
return std::tie(lhs.w, lhs.h, lhs.map_data) < std::tie(rhs.w, rhs.h, rhs.map_data);
|
||||
}
|
||||
|
||||
/** Value type for the cache. */
|
||||
|
|
|
@ -24,6 +24,7 @@ class variable_set;
|
|||
#include <cstdlib>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
@ -81,7 +82,7 @@ struct map_location {
|
|||
bool matches_range(const std::string& xloc, const std::string& yloc) const;
|
||||
|
||||
// Inlining those for performance reasons
|
||||
bool operator<(const map_location& a) const { return x < a.x || (x == a.x && y < a.y); }
|
||||
bool operator<(const map_location& a) const { return std::tie(x, y) < std::tie(a.x, a.y); }
|
||||
bool operator==(const map_location& a) const { return x == a.x && y == a.y; }
|
||||
bool operator!=(const map_location& a) const { return !operator==(a); }
|
||||
|
||||
|
|
|
@ -180,9 +180,9 @@ namespace {
|
|||
{ }
|
||||
|
||||
// Compare these nodes based on movement consumed.
|
||||
bool operator<(const findroute_node& o) const {
|
||||
return turns_left > o.turns_left ||
|
||||
(turns_left == o.turns_left && moves_left > o.moves_left);
|
||||
bool operator<(const findroute_node& o) const
|
||||
{
|
||||
return std::tie(turns_left, moves_left) > std::tie(o.turns_left, o.moves_left);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <SDL_rect.h>
|
||||
|
||||
#include <iosfwd>
|
||||
#include <tuple>
|
||||
|
||||
/** Holds a 2D point. */
|
||||
struct point
|
||||
|
@ -60,7 +61,7 @@ struct point
|
|||
|
||||
bool operator<(const point& point) const
|
||||
{
|
||||
return x < point.x || (x == point.x && y < point.y);
|
||||
return std::tie(x, y) < std::tie(point.x, point.y);
|
||||
}
|
||||
|
||||
bool operator<=(const point& point) const
|
||||
|
|
|
@ -353,7 +353,7 @@ public:
|
|||
/** sort by layer first then by basey */
|
||||
bool operator<(const rule_image_rand& o) const
|
||||
{
|
||||
return ri->layer < o.ri->layer || (ri->layer == o.ri->layer && ri->basey < o.ri->basey);
|
||||
return std::tie(ri->layer, ri->basey) < std::tie(o.ri->layer, o.ri->basey);
|
||||
}
|
||||
|
||||
const rule_image* ri;
|
||||
|
|
|
@ -64,7 +64,7 @@ namespace t_translation {
|
|||
const terrain_code NONE_TERRAIN = terrain_code();
|
||||
|
||||
inline bool operator<(const terrain_code& a, const terrain_code& b)
|
||||
{ return a.base < b.base || (a.base == b.base && a.overlay < b.overlay); }
|
||||
{ return std::tie(a.base, a.overlay) < std::tie(b.base, b.overlay); };
|
||||
|
||||
inline bool operator==(const terrain_code& a, const terrain_code& b)
|
||||
{ return a.base == b.base && a.overlay == b.overlay; }
|
||||
|
|
Loading…
Add table
Reference in a new issue