aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/variant.h
blob: 749fc75090891cc4973ec302bb47e9debb475395 (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;
    }
};