summaryrefslogtreecommitdiff
path: root/src/color.hh
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-12-16 18:57:19 +0000
committerMaxime Coste <frrrwww@gmail.com>2014-12-16 18:57:19 +0000
commitebecd60eb810246cfa682a1fbd72270aa9861f0b (patch)
tree0c5c707b68cb08fc93ace2433291deb8a52db5bc /src/color.hh
parentdbd7bd41bbf39d1fd5736997122a4652c78ddc50 (diff)
Rework hashing, use a more extensible framework similar to n3876 proposal
std::hash specialization is a pain to work with, stop using that, and just specialize a 'size_t hash_value(const T&)' free function.
Diffstat (limited to 'src/color.hh')
-rw-r--r--src/color.hh23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/color.hh b/src/color.hh
index 1de59fcd..1b3ba9c6 100644
--- a/src/color.hh
+++ b/src/color.hh
@@ -1,6 +1,8 @@
#ifndef color_hh_INCLUDED
#define color_hh_INCLUDED
+#include "hash.hh"
+
namespace Kakoune
{
@@ -32,13 +34,19 @@ struct Color
Color(Colors c) : color{c}, r{0}, g{0}, b{0} {}
Color(unsigned char r, unsigned char g, unsigned char b)
: color{Colors::RGB}, r{r}, g{g}, b{b} {}
-
- bool operator==(Color c) const
- { return color == c.color and r == c.r and g == c.g and b == c.b; }
- bool operator!=(Color c) const
- { return color != c.color or r != c.r or g != c.g or b != c.b; }
};
+inline bool operator==(Color lhs, Color rhs)
+{
+ return lhs.color == rhs.color and
+ lhs.r == rhs.r and lhs.g == rhs.g and lhs.b == rhs.b;
+}
+
+inline bool operator!=(Color lhs, Color rhs)
+{
+ return not (lhs == rhs);
+}
+
Color str_to_color(StringView color);
String color_to_str(Color color);
@@ -47,6 +55,11 @@ void option_from_string(StringView str, Color& color);
bool is_color_name(StringView color);
+inline size_t hash_value(const Color& val)
+{
+ return hash_values(val.color, val.r, val.g, val.b);
+}
+
}
#endif // color_hh_INCLUDED