xref: /openbmc/telemetry/src/utils/variant_utils.hpp (revision a8182beb1129b0608d2ddfb82895194ea3485288)
1*a8182bebSKrzysztof Grobelny #pragma once
2*a8182bebSKrzysztof Grobelny 
3*a8182bebSKrzysztof Grobelny #include <concepts>
4*a8182bebSKrzysztof Grobelny #include <variant>
5*a8182bebSKrzysztof Grobelny 
6*a8182bebSKrzysztof Grobelny namespace utils
7*a8182bebSKrzysztof Grobelny {
8*a8182bebSKrzysztof Grobelny namespace details
9*a8182bebSKrzysztof Grobelny {
10*a8182bebSKrzysztof Grobelny 
11*a8182bebSKrzysztof Grobelny template <class T, class... Args>
12*a8182bebSKrzysztof Grobelny auto removeMonostate(std::variant<T, Args...>) -> std::variant<T, Args...>;
13*a8182bebSKrzysztof Grobelny 
14*a8182bebSKrzysztof Grobelny template <class... Args>
15*a8182bebSKrzysztof Grobelny auto removeMonostate(std::variant<std::monostate, Args...>)
16*a8182bebSKrzysztof Grobelny     -> std::variant<Args...>;
17*a8182bebSKrzysztof Grobelny 
18*a8182bebSKrzysztof Grobelny template <class Variant>
19*a8182bebSKrzysztof Grobelny struct WithoutMonostate
20*a8182bebSKrzysztof Grobelny {
21*a8182bebSKrzysztof Grobelny   private:
22*a8182bebSKrzysztof Grobelny   public:
23*a8182bebSKrzysztof Grobelny     using type = decltype(removeMonostate(Variant{}));
24*a8182bebSKrzysztof Grobelny };
25*a8182bebSKrzysztof Grobelny 
26*a8182bebSKrzysztof Grobelny } // namespace details
27*a8182bebSKrzysztof Grobelny 
28*a8182bebSKrzysztof Grobelny template <class Variant>
29*a8182bebSKrzysztof Grobelny using WithoutMonostate = typename details::WithoutMonostate<Variant>::type;
30*a8182bebSKrzysztof Grobelny 
31*a8182bebSKrzysztof Grobelny } // namespace utils
32