commit 1a7ce14b60f20ed9ac8fe9bd3b702dea6985154b
parent 5db9bc0d12ffae108f3f29af800bb9606410f84c
Author: Christos Margiolis <christos@margiolis.net>
Date: Thu, 4 Jun 2020 04:40:22 +0300
seperated lambda from std::remove_if
Diffstat:
2 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/assignment-2.4-inheritance/src/appsystem.cpp b/assignment-2.4-inheritance/src/appsystem.cpp
@@ -42,27 +42,29 @@ AppSystem::write_office_exts(const Office *of, std::ofstream& f)
}
void
-AppSystem::removebad(const Manufacturer *man)
+AppSystem::removebad(const Manufacturer *manf)
{
- apps.erase(std::remove_if(apps.begin(), apps.end(), [&](App *app)
- {
- Manufacturer m = app->get_manf();
- if (!std::strcmp(m.get_name(), man->get_name()))
- delete app;
- return !std::strcmp(m.get_name(), man->get_name());
- }), apps.end());
+ auto lambda = [&](App *app) -> bool
+ {
+ Manufacturer m = app->get_manf();
+ if (!std::strcmp(m.get_name(), manf->get_name()))
+ delete app;
+ return !std::strcmp(m.get_name(), manf->get_name());
+ };
+ apps.erase(std::remove_if(apps.begin(), apps.end(), lambda), apps.end());
}
void
AppSystem::removebad(const char *manfname)
{
- apps.erase(std::remove_if(apps.begin(), apps.end(), [&](App *app)
- {
- Manufacturer m = app->get_manf();
- if (!std::strcmp(m.get_name(), manfname))
- delete app;
- return !std::strcmp(m.get_name(), manfname);
- }), apps.end());
+ auto lambda = [&](App *app) -> bool
+ {
+ Manufacturer m = app->get_manf();
+ if (!std::strcmp(m.get_name(), manfname))
+ delete app;
+ return !std::strcmp(m.get_name(), manfname);
+ };
+ apps.erase(std::remove_if(apps.begin(), apps.end(), lambda), apps.end());
}
const std::vector<Office *>
diff --git a/assignment-2.4-inheritance/src/appsystem.h b/assignment-2.4-inheritance/src/appsystem.h
@@ -32,7 +32,7 @@ class AppSystem
const std::string& appname,
const T element,
void (U::*func)(T));
- void removebad(const Manufacturer *man);
+ void removebad(const Manufacturer *manf);
void removebad(const char *manfname);
constexpr const std::vector<App *>& get_apps() const {return apps;}