From 2dce7e6e21a05c45a4784e3c93d555ec88bc3745 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Mon, 15 Oct 2018 21:00:44 +0100 Subject: [PATCH] Common: Add variant utilities --- Source/Core/Common/Common.vcxproj | 1 + Source/Core/Common/VariantUtil.h | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 Source/Core/Common/VariantUtil.h diff --git a/Source/Core/Common/Common.vcxproj b/Source/Core/Common/Common.vcxproj index 9939e0ccd3..a768f0c687 100644 --- a/Source/Core/Common/Common.vcxproj +++ b/Source/Core/Common/Common.vcxproj @@ -159,6 +159,7 @@ + diff --git a/Source/Core/Common/VariantUtil.h b/Source/Core/Common/VariantUtil.h new file mode 100644 index 0000000000..c865ad9681 --- /dev/null +++ b/Source/Core/Common/VariantUtil.h @@ -0,0 +1,26 @@ +// Copyright 2018 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include + +namespace detail +{ +template +struct VariantCastProxy +{ + const std::variant& v; + + template + operator std::variant() const + { + return std::visit([](auto&& arg) { return std::variant{arg}; }, v); + } +}; +} // namespace detail + +template +auto VariantCast(const std::variant& v) +{ + return detail::VariantCastProxy{v}; +}