Use std::filter and std::transform instead of the std::ranges library and make the destructor of the Target class virtual

This commit is contained in:
Username404 2021-09-12 12:00:21 +02:00
parent c0966f9650
commit 2b84262ea0
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
3 changed files with 6 additions and 5 deletions

View File

@ -8,7 +8,7 @@
#include <typeinfo> #include <typeinfo>
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <ranges> #include <algorithm>
using namespace std; using namespace std;
#include "../lex.hpp" #include "../lex.hpp"
@ -60,15 +60,15 @@ public:
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 { auto findById() const {
return subComponents | views::filter([](unique_ptr<ParseComponent>& it) { return subComponents | filter([](unique_ptr<ParseComponent>& it) -> bool {
return it->getId() == typeid(T); return it->getId() == typeid(T);
}) | views::transform([](unique_ptr<ParseComponent>& it) { }) | transform([](unique_ptr<ParseComponent>& it) {
return reinterpret_cast<T*>(it.get()); return reinterpret_cast<T*>(it.get());
}); });
} }
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>() | views::transform([](T* it) { auto identifiers = findById<T>() | transform([](T* it) {
return ref(static_cast<T&>(*it)); return ref(static_cast<T&>(*it));
}); });
for (const auto& identifier: identifiers) { for (const auto& identifier: identifiers) {

View File

@ -81,6 +81,7 @@ public:
#undef with #undef with
const bool newLines; const bool newLines;
explicit Target(const bool newLines): newLines(newLines) {}; explicit Target(const bool newLines): newLines(newLines) {};
virtual ~Target() = default;
}; };
#undef INCLUDECOMPONENT #undef INCLUDECOMPONENT

View File

@ -30,7 +30,7 @@ int main(int argc, char* argv[]) {
else if (currentArg == Argument("newlinesoff")) newLines = false; else if (currentArg == Argument("newlinesoff")) newLines = false;
else if (currentArg.ends_with(".ybcon")) files.push_back(currentArg); else if (currentArg.ends_with(".ybcon")) files.push_back(currentArg);
} }
const auto compile = [&target, &newLines](string_view name) { const auto compile = [&target, &newLines](string_view name) -> string {
string transpiledString = transpile(parseString(getFileContent(name.data())), target, newLines); string transpiledString = transpile(parseString(getFileContent(name.data())), target, newLines);
name.remove_suffix(6); name.remove_suffix(6);
string outputFile; string outputFile;