Commit 6d2d3ab5 authored by Daniel Teske's avatar Daniel Teske

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: default avatarDaniel Teske <daniel.teske@digia.com>
parent e85c6f4b
......@@ -79,12 +79,12 @@ typename T::value_type findOr(const T &container, typename T::value_type other,
}
template<typename T, typename F>
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;
......
......@@ -345,7 +345,7 @@ IBuildConfigurationFactory *IBuildConfigurationFactory::find(Kit *k, const QStri
QList<IBuildConfigurationFactory *> factories
= ExtensionSystem::PluginManager::instance()->getObjects<IBuildConfigurationFactory>();
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<IBuildConfigurationFactory *> factories
= ExtensionSystem::PluginManager::getObjects<IBuildConfigurationFactory>();
return Utils::maxElementOr(factories, 0,
return Utils::bestElementOr(factories, 0,
[&parent](IBuildConfigurationFactory *a, IBuildConfigurationFactory *b) {
return a->priority(parent) > b->priority(parent);
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment