#ifndef OPENMW_COMPONENTS_ESMLOADER_RECORD_H #define OPENMW_COMPONENTS_ESMLOADER_RECORD_H #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); records.erase(std::unique(records.begin(), records.end(), equalByKey), records.end()); std::reverse(records.begin(), records.end()); std::vector result; for (Record& v : records) if (!v.mDeleted) result.emplace_back(std::move(v.mValue)); return result; } } #endif