add optional header and hashlib implementation for optional

This commit is contained in:
Emily Schmidt 2024-07-25 12:25:19 +01:00
parent 850b3a6c29
commit fbee31080e
2 changed files with 13 additions and 0 deletions

View File

@ -205,6 +205,18 @@ template<typename... T> struct hash_ops<std::variant<T...>> {
}
};
template<typename T> struct hash_ops<std::optional<T>> {
static inline bool cmp(std::optional<T> a, std::optional<T> b) {
return a == b;
}
static inline unsigned int hash(std::optional<T> a) {
if(a.has_value())
return mkhash(*a);
else
return 0;
}
};
inline int hashtable_size(int min_size)
{
// Primes as generated by https://oeis.org/A175953

View File

@ -31,6 +31,7 @@
#include <unordered_set>
#include <initializer_list>
#include <variant>
#include <optional>
#include <stdexcept>
#include <memory>
#include <cmath>