Fix the findById() and findReferenceByName() methods in ParseComponents.hpp since the filter function doesn't actually exist

This commit is contained in:
Username404 2021-09-12 16:45:12 +02:00
parent 2672f33959
commit 33ee011aed
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 10 additions and 10 deletions

View File

@ -59,21 +59,21 @@ public:
inline iterator end() const noexcept { return subComponents.end(); } inline iterator end() const noexcept { return subComponents.end(); }
inline const_iterator cend() const noexcept { return subComponents.cend(); } inline const_iterator cend() const noexcept { return subComponents.cend(); }
IS_PARSECOMPONENT IS_PARSECOMPONENT
auto findById() const { vector<T*> findById() const {
return subComponents | filter([](unique_ptr<ParseComponent>& it) -> bool { vector<T*> filteredComponents;
return it->getId() == typeid(T); for_each(cbegin(), cend(), [&filteredComponents](const unique_ptr<ParseComponent>& it) {
}) | transform([](unique_ptr<ParseComponent>& it) { if (it->getId() == typeid(T)) {
return reinterpret_cast<T*>(it.get()); filteredComponents.push_back(reinterpret_cast<T*>(it.get()));
}
}); });
return filteredComponents;
} }
IS(StandardComponents::NamedIdentifier) IS(StandardComponents::NamedIdentifier)
optional<reference_wrapper<T>> findReferenceByName(const string& name) const { optional<reference_wrapper<T>> findReferenceByName(const string& name) const {
auto identifiers = findById<T>() | transform([](T* it) { auto identifiers = findById<T>();
return ref(static_cast<T&>(*it));
});
for (const auto& identifier: identifiers) { for (const auto& identifier: identifiers) {
if (identifier.get().getId() == typeid(T) && identifier.get().name == name) { if (identifier->getId() == typeid(T) && identifier->name == name) {
return make_optional(identifier); return make_optional(ref(static_cast<T&>(*identifier)));
} }
} }
return optional<reference_wrapper<T>>(); return optional<reference_wrapper<T>>();