types: move compare_unsigned() to bytes.hh

compare_unsigned() is a general utility function that compares two
bytes_view byte-by-byte. There is no need to include whole type.hh in
order to make it available.
This commit is contained in:
Paweł Dziepak
2018-04-09 11:09:16 +02:00
parent c6c5accd19
commit f9940f620a
2 changed files with 8 additions and 8 deletions

View File

@@ -78,3 +78,11 @@ struct appending_hash<bytes_view> {
h.update(reinterpret_cast<const char*>(v.begin()), v.size() * sizeof(bytes_view::value_type));
}
};
inline int32_t compare_unsigned(bytes_view v1, bytes_view v2) {
auto n = memcmp(v1.begin(), v2.begin(), std::min(v1.size(), v2.size()));
if (n) {
return n;
}
return (int32_t) (v1.size() - v2.size());
}

View File

@@ -223,14 +223,6 @@ public:
virtual const char* what() const noexcept override { return _why.c_str(); }
};
inline int32_t compare_unsigned(bytes_view v1, bytes_view v2) {
auto n = memcmp(v1.begin(), v2.begin(), std::min(v1.size(), v2.size()));
if (n) {
return n;
}
return (int32_t) (v1.size() - v2.size());
}
struct empty_t {};
class empty_value_exception : public std::exception {