diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0cb4ccd8..36435b0c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -48,6 +48,7 @@ set(HEADERS common/mp.h common/scope_exit.h common/string_util.h + common/variant_util.h frontend/arm/FPSCR.h frontend/arm/PSR.h frontend/arm/types.h diff --git a/src/common/variant_util.h b/src/common/variant_util.h new file mode 100644 index 00000000..1d7921de --- /dev/null +++ b/src/common/variant_util.h @@ -0,0 +1,33 @@ +/* This file is part of the dynarmic project. + * Copyright (c) 2016 MerryMage + * This software may be used and distributed according to the terms of the GNU + * General Public License version 2 or any later version. + */ + +#pragma once + +#include + +namespace Dynarmic { +namespace Common { + +namespace detail { + +template +struct VariantVisitor : boost::static_visitor, Lambda { + VariantVisitor(Lambda&& lambda) + : Lambda(std::move(lambda)) + {} + + using Lambda::operator(); +}; + +} // namespace detail + +template +inline ReturnT VisitVariant(Variant&& variant, Lambda&& lambda) { + return boost::apply_visitor(detail::VariantVisitor(std::move(lambda)), variant); +} + +} // namespace Common +} // namespace Dynarmic