From c34035b9491c201eca226a2e065fd9753d706433 Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 15 Oct 2023 00:07:24 +0800 Subject: Improve bitmask. Bool conversion -> explicit std::hash support --- include/cru/common/Bitmask.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'include/cru/common/Bitmask.h') diff --git a/include/cru/common/Bitmask.h b/include/cru/common/Bitmask.h index bd6a8309..b1e8495e 100644 --- a/include/cru/common/Bitmask.h +++ b/include/cru/common/Bitmask.h @@ -1,6 +1,8 @@ #pragma once #include "Base.h" +#include + namespace cru { template struct Bitmask final { @@ -35,8 +37,19 @@ struct Bitmask final { bool operator!=(Bitmask rhs) const { return this->value != rhs.value; } explicit operator TUnderlying() const { return value; } - operator bool() const { return value != 0; } + explicit operator bool() const { return value != 0; } TUnderlying value; }; } // namespace cru + +namespace std { +template +struct hash> { + using Bitmask = cru::Bitmask; + + std::size_t operator()(Bitmask bitmask) const { + return std::hash{}(bitmask.value); + } +}; +} // namespace std -- cgit v1.2.3