diff --git a/generator/cells_merger.cpp b/generator/cells_merger.cpp index e5ab8f5ed8..e2327fb493 100644 --- a/generator/cells_merger.cpp +++ b/generator/cells_merger.cpp @@ -1,6 +1,7 @@ #include "generator/cells_merger.hpp" #include "base/logging.hpp" +#include "base/stl_helpers.hpp" #include @@ -161,7 +162,7 @@ std::optional CellsMerger::FindDirection(m2::PointI const & startXy) { std::array, 4> directionsWithWeight; std::array const directions{{{1, 1}, {-1, 1}, {1, -1}, {-1, -1}}}; - std::transform(std::begin(directions), std::end(directions), std::begin(directionsWithWeight), + base::Transform(directions, std::begin(directionsWithWeight), [&](auto const & direction) { return std::make_pair( TryGet(startXy.x + direction.x, startXy.y).GetSum() + diff --git a/generator/filter_collection.cpp b/generator/filter_collection.cpp index 620c292ab0..3263113814 100644 --- a/generator/filter_collection.cpp +++ b/generator/filter_collection.cpp @@ -1,6 +1,7 @@ #include "generator/filter_collection.hpp" -#include +#include "base/stl_helpers.hpp" + using namespace feature; @@ -16,15 +17,11 @@ std::shared_ptr FilterCollection::Clone() const bool FilterCollection::IsAccepted(OsmElement const & element) { - return std::all_of(std::begin(m_collection), std::end(m_collection), [&] (auto & filter) { - return filter->IsAccepted(element); - }); + return base::AllOf(m_collection, [&] (auto & filter) { return filter->IsAccepted(element); }); } bool FilterCollection::IsAccepted(FeatureBuilder const & feature) { - return std::all_of(std::begin(m_collection), std::end(m_collection), [&] (auto & filter) { - return filter->IsAccepted(feature); - }); + return base::AllOf(m_collection, [&] (auto & filter) { return filter->IsAccepted(feature); }); } } // namespace generator diff --git a/generator/filter_elements.cpp b/generator/filter_elements.cpp index de7affe135..fcf47b2b22 100644 --- a/generator/filter_elements.cpp +++ b/generator/filter_elements.cpp @@ -1,6 +1,7 @@ #include "generator/filter_elements.hpp" #include "base/logging.hpp" +#include "base/stl_helpers.hpp" #include #include @@ -38,11 +39,11 @@ bool FilterData::IsMatch(Tags const & elementTags, Tags const & tags) auto const fn = [&](OsmElement::Tag const & t) { auto const pred = [&](OsmElement::Tag const & tag) { return tag.m_key == t.m_key; }; - auto const it = std::find_if(std::begin(elementTags), std::end(elementTags), pred); + auto const it = base::FindIf(elementTags, pred); return it == std::end(elementTags) ? false : t.m_value == "*" || it->m_value == t.m_value; }; - return std::all_of(std::begin(tags), std::end(tags), fn); + return base::AllOf(tags, fn); } void FilterData::AddSkippedId(uint64_t id) diff --git a/generator/final_processor_intermediate_mwm.cpp b/generator/final_processor_intermediate_mwm.cpp index 6f0e90ec8d..1fd4133802 100644 --- a/generator/final_processor_intermediate_mwm.cpp +++ b/generator/final_processor_intermediate_mwm.cpp @@ -216,8 +216,7 @@ public: std::vector fbs; fbs.reserve(fbsWithIds.size()); - std::transform(std::cbegin(fbsWithIds), std::cend(fbsWithIds), std::back_inserter(fbs), - base::RetrieveFirst()); + base::Transform(fbsWithIds, std::back_inserter(fbs), base::RetrieveFirst()); auto const affiliations = GetAffiliations(fbs, m_affiliation, m_threadsCount); AppendToCountries(fbs, affiliations, m_temporaryMwmPath, m_threadsCount); } diff --git a/generator/generator_tests/collector_city_area_tests.cpp b/generator/generator_tests/collector_city_area_tests.cpp index e8dd1904a1..29cbc9f24f 100644 --- a/generator/generator_tests/collector_city_area_tests.cpp +++ b/generator/generator_tests/collector_city_area_tests.cpp @@ -14,6 +14,7 @@ #include "base/geo_object_id.hpp" #include "base/scope_guard.hpp" +#include "base/stl_helpers.hpp" #include #include @@ -35,7 +36,7 @@ feature::FeatureBuilder MakeFbForTest(OsmElement element) } bool HasRelationWithId(std::vector const & fbs, uint64_t id) { - return std::find_if(std::begin(fbs), std::end(fbs), [&](auto const & fb) { + return base::FindIf(fbs, [&](auto const & fb) { return fb.GetMostGenericOsmId() == base::MakeOsmRelation(id); }) != std::end(fbs); }; diff --git a/generator/generator_tests/descriptions_section_builder_tests.cpp b/generator/generator_tests/descriptions_section_builder_tests.cpp index f63936752f..87cefb42cd 100644 --- a/generator/generator_tests/descriptions_section_builder_tests.cpp +++ b/generator/generator_tests/descriptions_section_builder_tests.cpp @@ -14,8 +14,9 @@ #include "platform/platform.hpp" #include "platform/platform_tests_support/scoped_mwm.hpp" -#include "base/file_name_utils.hpp" #include "base/assert.hpp" +#include "base/file_name_utils.hpp" +#include "base/stl_helpers.hpp" #include #include @@ -157,8 +158,7 @@ public: StringUtf8Multilang str; // This is a private function and should take the right path fullPath. auto const size = DescriptionsCollectionBuilder::FillStringFromFile(fullPath, langIndex, str); - auto const it = std::find_if(std::begin(first.m_pages), std::end(first.m_pages), - [&](auto const & p) { return p.first == lang; }); + auto const it = base::FindIf(first.m_pages, [&](auto const & p) { return p.first == lang; }); CHECK(it != std::end(first.m_pages), ()); TEST_EQUAL(size, it->second.size(), ()); TEST(CheckLangs(str, first.m_pages), ()); @@ -253,11 +253,7 @@ private: for (auto const & m : kWikiData) { auto const & pages = m.m_pages; - auto const exists = std::any_of(std::begin(pages), std::end(pages), [](auto const & d) { - return IsSupportedLang(d.first); - }); - - if (exists) + if (base::AnyOf(pages, [](auto const & d) { return IsSupportedLang(d.first); })) ++size; } @@ -331,7 +327,7 @@ private: { bool result = true; str.ForEach([&](auto code, auto const &) { - auto const it = std::find_if(std::begin(p), std::end(p), [&](auto const & p) { + auto const it = base::FindIf(p, [&](auto const & p) { return StringUtf8Multilang::GetLangIndex(p.first) == code; }); diff --git a/generator/generator_tests_support/test_with_custom_mwms.hpp b/generator/generator_tests_support/test_with_custom_mwms.hpp index 6c5d589cd6..24ef23e038 100644 --- a/generator/generator_tests_support/test_with_custom_mwms.hpp +++ b/generator/generator_tests_support/test_with_custom_mwms.hpp @@ -14,6 +14,7 @@ #include "platform/platform.hpp" #include "base/assert.hpp" +#include "base/stl_helpers.hpp" #include #include @@ -62,9 +63,10 @@ public: void DeregisterMap(std::string const & name) { auto const file = platform::CountryFile(name); - auto it = find_if( - m_files.begin(), m_files.end(), - [&file](platform::LocalCountryFile const & f) { return f.GetCountryFile() == file; }); + auto it = base::FindIf(m_files, [&file](platform::LocalCountryFile const & f) { + return f.GetCountryFile() == file; + }); + if (it == m_files.end()) return; diff --git a/generator/hierarchy.cpp b/generator/hierarchy.cpp index d4ebd4404e..e7546a5480 100644 --- a/generator/hierarchy.cpp +++ b/generator/hierarchy.cpp @@ -6,6 +6,7 @@ #include "geometry/rect2d.hpp" #include "base/assert.hpp" +#include "base/stl_helpers.hpp" #include #include @@ -274,8 +275,9 @@ HierarchyLinker::Node::Ptrs BuildHierarchy(std::vector base::EraseIf(fbs, [&](auto const & fb) { return !filter->IsAccepted(fb); }); HierarchyLinker::Node::Ptrs places; places.reserve(fbs.size()); - std::transform(std::cbegin(fbs), std::cend(fbs), std::back_inserter(places), - [](auto const & fb) { return tree_node::MakeTreeNode(HierarchyPlace(fb)); }); + base::Transform(fbs, std::back_inserter(places), [](auto const & fb) { + return tree_node::MakeTreeNode(HierarchyPlace(fb)); + }); auto nodes = HierarchyLinker(std::move(places)).Link(); // We leave only the trees. base::EraseIf(nodes, [](auto const & node) { diff --git a/generator/mini_roundabout_transformer.cpp b/generator/mini_roundabout_transformer.cpp index 357e4f7d1c..784c3eca3f 100644 --- a/generator/mini_roundabout_transformer.cpp +++ b/generator/mini_roundabout_transformer.cpp @@ -6,6 +6,7 @@ #include "base/assert.hpp" #include "base/logging.hpp" +#include "base/stl_helpers.hpp" #include #include @@ -51,7 +52,7 @@ void UpdateFeatureGeometry(feature::FeatureBuilder::PointSeq const & seq, feature::FeatureBuilder::PointSeq::iterator GetIterOnRoad(m2::PointD const & point, feature::FeatureBuilder::PointSeq & road) { - return std::find_if(road.begin(), road.end(), [&point](m2::PointD const & pointOnRoad) { + return base::FindIf(road, [&point](m2::PointD const & pointOnRoad) { return base::AlmostEqualAbs(pointOnRoad, point, kMwmPointAccuracy); }); } diff --git a/generator/osm_element.cpp b/generator/osm_element.cpp index b90ca75144..177a050973 100644 --- a/generator/osm_element.cpp +++ b/generator/osm_element.cpp @@ -1,9 +1,10 @@ #include "generator/osm_element.hpp" -#include "base/string_utils.hpp" #include "coding/parse_xml.hpp" -#include +#include "base/string_utils.hpp" +#include "base/stl_helpers.hpp" + #include #include #include @@ -81,21 +82,17 @@ void OsmElement::AddTag(std::string const & key, std::string const & value) bool OsmElement::HasTag(std::string const & key) const { - return std::any_of(m_tags.begin(), m_tags.end(), [&](auto const & t) { - return t.m_key == key; - }); + return base::AnyOf(m_tags, [&](auto const & t) { return t.m_key == key; }); } bool OsmElement::HasTag(std::string const & key, std::string const & value) const { - return std::any_of(m_tags.begin(), m_tags.end(), [&](auto const & t) { - return t.m_key == key && t.m_value == value; - }); + return base::AnyOf(m_tags, [&](auto const & t) { return t.m_key == key && t.m_value == value; }); } bool OsmElement::HasAnyTag(std::unordered_multimap const & tags) const { - return std::any_of(std::begin(m_tags), std::end(m_tags), [&](auto const & t) { + return base::AnyOf(m_tags, [&](auto const & t) { auto beginEnd = tags.equal_range(t.m_key); for (auto it = beginEnd.first; it != beginEnd.second; ++it) { @@ -164,18 +161,14 @@ std::string OsmElement::ToString(std::string const & shift) const std::string OsmElement::GetTag(std::string const & key) const { - auto const it = std::find_if(m_tags.cbegin(), m_tags.cend(), - [&key](Tag const & tag) { return tag.m_key == key; }); - + auto const it = base::FindIf(m_tags, [&key](Tag const & tag) { return tag.m_key == key; }); return it == m_tags.cend() ? std::string() : it->m_value; } std::string OsmElement::GetTagValue(std::string const & key, std::string const & defaultValue) const { - auto const it = std::find_if(m_tags.cbegin(), m_tags.cend(), - [&key](Tag const & tag) { return tag.m_key == key; }); - + auto const it = base::FindIf(m_tags, [&key](Tag const & tag) { return tag.m_key == key; }); return it != m_tags.cend() ? it->m_value : defaultValue; } diff --git a/generator/osm_element_helpers.cpp b/generator/osm_element_helpers.cpp index 1cddbb6a71..4a17183548 100644 --- a/generator/osm_element_helpers.cpp +++ b/generator/osm_element_helpers.cpp @@ -9,38 +9,6 @@ namespace generator { namespace osm_element { -bool IsPoi(OsmElement const & osmElement) -{ - auto const & tags = osmElement.Tags(); - return std::any_of(std::cbegin(tags), std::cend(tags), [](OsmElement::Tag const & t) { - return ftypes::IsPoiChecker::kPoiTypes.find(t.m_key) != std::end(ftypes::IsPoiChecker::kPoiTypes); - }); -} - -bool IsBuilding(OsmElement const & osmElement) -{ - auto const & tags = osmElement.Tags(); - return std::any_of(std::cbegin(tags), std::cend(tags), [](OsmElement::Tag const & t) { - return t.m_key == "building"; - }); -} - -bool HasHouse(OsmElement const & osmElement) -{ - auto const & tags = osmElement.Tags(); - return std::any_of(std::cbegin(tags), std::cend(tags), [](OsmElement::Tag const & t) { - return t.m_key == "addr:housenumber" || t.m_key == "addr:housename"; - }); -} - -bool HasStreet(OsmElement const & osmElement) -{ - auto const & tags = osmElement.Tags(); - return std::any_of(std::cbegin(tags), std::cend(tags), [](OsmElement::Tag const & t) { - return t.m_key == "addr:street"; - }); -} - uint64_t GetPopulation(std::string const & populationStr) { std::string number; diff --git a/generator/osm_element_helpers.hpp b/generator/osm_element_helpers.hpp index 33a2959a66..1eba5c326a 100644 --- a/generator/osm_element_helpers.hpp +++ b/generator/osm_element_helpers.hpp @@ -8,15 +8,6 @@ namespace generator { namespace osm_element { -bool IsPoi(OsmElement const & osmElement); - -bool IsBuilding(OsmElement const & osmElement); - -// Has house name or house number. -bool HasHouse(OsmElement const & osmElement); - -bool HasStreet(OsmElement const & osmElement); - uint64_t GetPopulation(std::string const & populationStr); uint64_t GetPopulation(OsmElement const & osmElement); } // namespace osm_element diff --git a/generator/place_processor.cpp b/generator/place_processor.cpp index 6daf0df621..ffb1f0e724 100644 --- a/generator/place_processor.cpp +++ b/generator/place_processor.cpp @@ -7,6 +7,7 @@ #include "indexer/ftypes_matcher.hpp" #include "base/assert.hpp" +#include "base/stl_helpers.hpp" #include #include @@ -201,8 +202,9 @@ std::vector PlaceProcessor::ProcessPlaces() } std::vector ids; ids.reserve(cluster.size()); - std::transform(std::cbegin(cluster), std::cend(cluster), std::back_inserter(ids), - [](auto const & place) { return place.GetMostGenericOsmId(); }); + base::Transform(cluster, std::back_inserter(ids), [](auto const & place) { + return place.GetMostGenericOsmId(); + }); finalPlaces.emplace_back(std::move(bestFb), std::move(ids)); if (m_boundariesTable) FillTable(std::cbegin(cluster), std::cend(cluster), best); diff --git a/generator/relation_tags.cpp b/generator/relation_tags.cpp index a9ed22b969..cdf3186bd5 100644 --- a/generator/relation_tags.cpp +++ b/generator/relation_tags.cpp @@ -2,6 +2,8 @@ #include "generator/osm_element.hpp" +#include "base/stl_helpers.hpp" + namespace generator { RelationTagsBase::RelationTagsBase() : m_cache(14 /* logCacheSize */) {} @@ -21,9 +23,7 @@ bool RelationTagsBase::IsSkipRelation(std::string const & type) bool RelationTagsBase::IsKeyTagExists(std::string const & key) const { auto const & tags = m_current->m_tags; - return std::any_of(std::begin(tags), std::end(tags), [&](OsmElement::Tag const & p) { - return p.m_key == key; - }); + return base::AnyOf(tags, [&](OsmElement::Tag const & p) { return p.m_key == key; }); } void RelationTagsBase::AddCustomTag(std::pair const & p) diff --git a/generator/restriction_writer.cpp b/generator/restriction_writer.cpp index d75f6bc7cf..4bf20bc9fe 100644 --- a/generator/restriction_writer.cpp +++ b/generator/restriction_writer.cpp @@ -14,6 +14,7 @@ #include "base/assert.hpp" #include "base/geo_object_id.hpp" #include "base/logging.hpp" +#include "base/stl_helpers.hpp" #include #include @@ -42,8 +43,8 @@ std::vector> const kRestrictionTypes = /// \returns true if conversion was successful and false otherwise. bool TagToType(std::string const & tag, Restriction::Type & type) { - auto const it = std::find_if(kRestrictionTypes.cbegin(), kRestrictionTypes.cend(), - [&tag](std::pair const & v) { + auto const it = base::FindIf(kRestrictionTypes, + [&tag](std::pair const & v) { return v.first == tag; }); if (it == kRestrictionTypes.cend()) @@ -143,12 +144,9 @@ bool ValidateOsmRestriction(std::vector & from, // https://wiki.openstreetmap.org/wiki/Relation:restriction#Members if (via.size() != 1) { - bool const allMembersAreWays = - std::all_of(via.begin(), via.end(), - [&](auto const & member) - { - return GetType(relationElement, member.first) == OsmElement::EntityType::Way; - }); + bool const allMembersAreWays = base::AllOf(via, [&](auto const & member) { + return GetType(relationElement, member.first) == OsmElement::EntityType::Way; + }); if (!allMembersAreWays) return false; diff --git a/generator/translator_collection.cpp b/generator/translator_collection.cpp index 7592688dc8..01f051a7bb 100644 --- a/generator/translator_collection.cpp +++ b/generator/translator_collection.cpp @@ -2,8 +2,7 @@ #include "generator/osm_element.hpp" -#include -#include +#include "base/stl_helpers.hpp" namespace generator { @@ -32,8 +31,7 @@ void TranslatorCollection::Finish() bool TranslatorCollection::Save() { - return std::all_of(std::begin(m_collection), std::end(m_collection), - [](auto & t) { return t->Save(); }); + return base::AllOf(m_collection, [](auto & t) { return t->Save(); }); } void TranslatorCollection::Merge(TranslatorInterface const & other) { other.MergeInto(*this); } diff --git a/generator/utils.cpp b/generator/utils.cpp index 30153e1f39..df21833bda 100644 --- a/generator/utils.cpp +++ b/generator/utils.cpp @@ -16,6 +16,7 @@ #include "base/cancellable.hpp" #include "base/exception.hpp" #include "base/logging.hpp" +#include "base/stl_helpers.hpp" #include #include @@ -145,25 +146,22 @@ bool MapcssRule::Matches(std::vector const & tags) const { for (auto const & tag : m_tags) { - if (!std::any_of(tags.begin(), tags.end(), [&](auto const & t) { return t == tag; })) + if (!base::AnyOf(tags, [&](auto const & t) { return t == tag; })) return false; } + for (auto const & key : m_mandatoryKeys) { - if (!std::any_of(tags.begin(), tags.end(), - [&](auto const & t) { return t.m_key == key && t.m_value != "no"; })) - { + if (!base::AnyOf(tags, [&](auto const & t) { return t.m_key == key && t.m_value != "no"; })) return false; - } } + for (auto const & key : m_forbiddenKeys) { - if (!std::all_of(tags.begin(), tags.end(), - [&](auto const & t) { return t.m_key != key || t.m_value == "no"; })) - { + if (!base::AllOf(tags, [&](auto const & t) { return t.m_key != key || t.m_value == "no"; })) return false; - } } + return true; }