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