aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/variant.h
blob: 9c889696234edd35a2f589567d5a8faffbeafe6d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#pragma once

#include "hash.h"
 
#include <variant>
 
template <class... Ts> 
struct THash<std::variant<Ts...>> {
public: 
    size_t operator()(const std::variant<Ts...>& v) const noexcept {
        return CombineHashes(
            IntHash(v.index()),
            v.valueless_by_exception() ? 0 : std::visit([](const auto& value) { return ComputeHash(value); }, v));
    } 
}; 

template <>
struct THash<std::monostate> {
public:
    constexpr size_t operator()(std::monostate) const noexcept {
        return 1;
    }
};