Common: Add variant utilities
This commit is contained in:
parent
cb576bf382
commit
2dce7e6e21
|
@ -159,6 +159,7 @@
|
|||
<ClInclude Include="TraversalClient.h" />
|
||||
<ClInclude Include="TraversalProto.h" />
|
||||
<ClInclude Include="UPnP.h" />
|
||||
<ClInclude Include="VariantUtil.h" />
|
||||
<ClInclude Include="Version.h" />
|
||||
<ClInclude Include="WorkQueueThread.h" />
|
||||
<ClInclude Include="x64ABI.h" />
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright 2018 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <variant>
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <typename... From>
|
||||
struct VariantCastProxy
|
||||
{
|
||||
const std::variant<From...>& v;
|
||||
|
||||
template <typename... To>
|
||||
operator std::variant<To...>() const
|
||||
{
|
||||
return std::visit([](auto&& arg) { return std::variant<To...>{arg}; }, v);
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
template <typename... From>
|
||||
auto VariantCast(const std::variant<From...>& v)
|
||||
{
|
||||
return detail::VariantCastProxy<From...>{v};
|
||||
}
|
Loading…
Reference in New Issue