From 6d2d3ab54d298ebe8d3844ecfc6db19a817d2e62 Mon Sep 17 00:00:00 2001 From: Daniel Teske Date: Mon, 16 Jun 2014 10:24:55 -0400 Subject: ProjectExplorer: Fix comparing priorities Makes test_modelmanager_extraeditorsupport_uiFiles pass again. Before, a "CMake Wizard" dialog blocked the auto test due to the wrong comparisons. The std::max_element function takes a less predicate. Thus the right way to find e.g. highest int in a vector is: std::max_element(..., std::less<>) or std::min_element(..., std::greater<>) Both variants are confussing to read. Instead of provinding Utils::maxElementOr provide a bestElementOr which leads to this code: bestElementOr(..., std::greater<>). Change-Id: Ic30f0d742c03170b28227f60d3a5ae00e40fdf5a Reviewed-by: Daniel Teske --- src/libs/utils/algorithm.h | 4 ++-- src/plugins/projectexplorer/buildconfiguration.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/utils/algorithm.h b/src/libs/utils/algorithm.h index e4de304743..a7ed90e15d 100644 --- a/src/libs/utils/algorithm.h +++ b/src/libs/utils/algorithm.h @@ -79,12 +79,12 @@ typename T::value_type findOr(const T &container, typename T::value_type other, } template -typename T::value_type maxElementOr(const T &container, typename T::value_type other, F function) +typename T::value_type bestElementOr(const T &container, typename T::value_type other, F function) { typename T::const_iterator end = container.end(); typename T::const_iterator begin = container.begin(); - typename T::const_iterator it = std::max_element(begin, end, function); + typename T::const_iterator it = std::min_element(begin, end, function); if (it == end) return other; return *it; diff --git a/src/plugins/projectexplorer/buildconfiguration.cpp b/src/plugins/projectexplorer/buildconfiguration.cpp index 2e16db3081..0b217f7cfe 100644 --- a/src/plugins/projectexplorer/buildconfiguration.cpp +++ b/src/plugins/projectexplorer/buildconfiguration.cpp @@ -345,7 +345,7 @@ IBuildConfigurationFactory *IBuildConfigurationFactory::find(Kit *k, const QStri QList factories = ExtensionSystem::PluginManager::instance()->getObjects(); - return Utils::maxElementOr(factories, 0, + return Utils::bestElementOr(factories, 0, [&k, &projectPath](IBuildConfigurationFactory *a, IBuildConfigurationFactory *b) { return a->priority(k, projectPath) > b->priority(k, projectPath); }); @@ -357,7 +357,7 @@ IBuildConfigurationFactory * IBuildConfigurationFactory::find(Target *parent) QList factories = ExtensionSystem::PluginManager::getObjects(); - return Utils::maxElementOr(factories, 0, + return Utils::bestElementOr(factories, 0, [&parent](IBuildConfigurationFactory *a, IBuildConfigurationFactory *b) { return a->priority(parent) > b->priority(parent); }); -- cgit v1.2.1