mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-05 15:55:45 +00:00
Use compile time generated indices for tuples types
This commit is contained in:
parent
8f7703d5c8
commit
c856095562
@ -316,13 +316,6 @@ void ESMStore::setIdType(const std::string& id, ESM::RecNameInts type)
|
||||
mStoreImp->mIds[id] = type;
|
||||
}
|
||||
|
||||
static std::size_t sTypeIndexCounter = 0;
|
||||
|
||||
std::size_t ESMStore::geNextTypeIndex()
|
||||
{
|
||||
return sTypeIndexCounter++;
|
||||
}
|
||||
|
||||
ESM::LuaScriptsCfg ESMStore::getLuaScriptsCfg() const
|
||||
{
|
||||
ESM::LuaScriptsCfg cfg;
|
||||
|
@ -126,14 +126,11 @@ namespace MWWorld
|
||||
// Special entry which is hardcoded and not loaded from an ESM
|
||||
Store<ESM::Attribute >>;
|
||||
|
||||
static std::size_t geNextTypeIndex();
|
||||
|
||||
template<typename T>
|
||||
static std::size_t getTypeIndex()
|
||||
static constexpr std::size_t getTypeIndex()
|
||||
{
|
||||
static_assert(Misc::TupleHasType<Store<T>, StoreTuple>::value);
|
||||
static std::size_t sIndex = geNextTypeIndex();
|
||||
return sIndex;
|
||||
return Misc::TupleTypeIndex<Store<T>, StoreTuple>::value;
|
||||
}
|
||||
|
||||
std::unique_ptr<ESMStoreImp> mStoreImp;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef OPENMW_COMPONENTS_MISC_META_H
|
||||
#define OPENMW_COMPONENTS_MISC_META_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
|
||||
@ -14,6 +15,21 @@ namespace Misc
|
||||
{
|
||||
static constexpr bool value = (std::is_same_v<T, Args> || ...);
|
||||
};
|
||||
|
||||
template <class T, class Tuple>
|
||||
struct TupleTypeIndex;
|
||||
|
||||
template <class T, class... Types>
|
||||
struct TupleTypeIndex<T, std::tuple<T, Types...>>
|
||||
{
|
||||
static constexpr std::size_t value = 0;
|
||||
};
|
||||
|
||||
template <class T, class U, class... Types>
|
||||
struct TupleTypeIndex<T, std::tuple<U, Types...>>
|
||||
{
|
||||
static constexpr std::size_t value = 1 + TupleTypeIndex<T, std::tuple<Types...>>::value;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user