mirror of
https://git.suyu.dev/suyu/dynarmic.git
synced 2026-03-08 01:46:28 +00:00
lut_from_list: Reduce number of required template arguments
This commit is contained in:
@@ -6,17 +6,33 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <initializer_list>
|
||||
#include <map>
|
||||
#include <type_traits>
|
||||
|
||||
#include <mp/metafunction/apply.h>
|
||||
#include <mp/traits/is_instance_of_template.h>
|
||||
#include <mp/typelist/list.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <mp/typelist/head.h>
|
||||
#endif
|
||||
|
||||
namespace Dynarmic::Common {
|
||||
|
||||
template <typename KeyT, typename ValueT, typename Function, typename ...Values>
|
||||
template <typename Function, typename ...Values>
|
||||
inline auto GenerateLookupTableFromList(Function f, mp::list<Values...>) {
|
||||
static const std::array<std::pair<KeyT, ValueT>, sizeof...(Values)> pair_array{f(Values{})...};
|
||||
return std::map<KeyT, ValueT>(pair_array.begin(), pair_array.end());
|
||||
#ifdef _MSC_VER
|
||||
using PairT = std::invoke_result_t<Function, mp::head<mp::list<Values...>>>;
|
||||
#else
|
||||
using PairT = std::common_type_t<std::invoke_result_t<Function, Values>...>;
|
||||
#endif
|
||||
using MapT = mp::apply<std::map, PairT>;
|
||||
|
||||
static_assert(mp::is_instance_of_template_v<std::pair, PairT>);
|
||||
|
||||
const std::initializer_list<PairT> pair_array{f(Values{})...};
|
||||
return MapT(pair_array.begin(), pair_array.end());
|
||||
}
|
||||
|
||||
} // namespace Dynarmic::Common
|
||||
|
||||
Reference in New Issue
Block a user