Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
struct Font
{
std::string name;
uint16_t size;
bool is_bold;
bool is_italic;
};
bool operator==(const Font& f1, const Font& f2)
{
return
f1.name == f2.name &&
f1.size == f2.size &&
f1.is_bold == f2.is_bold &&
f1.is_italic == f2.is_italic;
}
uint32_t djb2(const std::string& text) { return 0 /* TODO */; }
namespace std {
template <>
struct hash<Font>
{
std::size_t operator()(const Font& font) const
{
int64_t hash = djb2(font.name);
hash |= (static_cast<uint64_t>(font.size) << 32);
hash |= (static_cast<uint64_t>(font.is_bold)) << 48;
hash |= (static_cast<uint64_t>(font.is_bold)) << 56;
return static_cast<std::size_t>(hash);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.