Permalink
Browse files

Common: Add variant utilities

  • Loading branch information...
MerryMage committed Oct 15, 2018
1 parent cb576bf commit 2dce7e6e21a05c45a4784e3c93d555ec88bc3745
Showing with 27 additions and 0 deletions.
  1. +1 −0 Source/Core/Common/Common.vcxproj
  2. +26 −0 Source/Core/Common/VariantUtil.h
@@ -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};
}

0 comments on commit 2dce7e6

Please sign in to comment.