#ifndef OPENMW_COMPONENTS_ESMLOADER_RECORD_H #define OPENMW_COMPONENTS_ESMLOADER_RECORD_H #include #include #include #include #include namespace EsmLoader { template struct Record { bool mDeleted; T mValue; template explicit Record(bool deleted, Args&&... args) : mDeleted(deleted) , mValue(std::forward(args)...) { } }; template using Records = std::vector>; template inline std::vector prepareRecords(Records& records, const GetKey& getKey) { const auto greaterByKey = [&](const auto& l, const auto& r) { return getKey(r) < getKey(l); }; const auto equalByKey = [&](const auto& l, const auto& r) { return getKey(l) == getKey(r); }; std::stable_sort(records.begin(), records.end(), greaterByKey); std::vector result; Misc::forEachUnique(records.rbegin(), records.rend(), equalByKey, [&](const auto& v) { if (!v.mDeleted) result.emplace_back(std::move(v.mValue)); }); return result; } } #endif