diff options
author | Marco Bubke <marco.bubke@qt.io> | 2017-10-25 14:32:45 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2017-10-27 09:28:07 +0000 |
commit | 4911d5bea31bf6717c19472b7929b7820026a0a8 (patch) | |
tree | 50dfdbca31ebdcb8a08aa1439a10566b113788c5 /src/libs/utils/algorithm.h | |
parent | 2918cc59f83a2a35d87553d2946d500b0ba88f1d (diff) |
Utils: Add predicates for comparison to constant values
Many STL algorithms have value version. So you can only use a predicate:
std::stable_partition(std::begin(list), std::end(list), [](int entry) {
return entry < 20;
});
With this predicates you can write it in a shorter form:
std::stable_partition(std::begin(list), std::end(list), lessThan(20));
The find helpers are moved to predicates too.
Change-Id: I791b3105ca84ef7c5a519d22589a91b5548cf3e4
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'src/libs/utils/algorithm.h')
-rw-r--r-- | src/libs/utils/algorithm.h | 20 |
1 files changed, 2 insertions, 18 deletions
diff --git a/src/libs/utils/algorithm.h b/src/libs/utils/algorithm.h index 602d7465742..f24ad579770 100644 --- a/src/libs/utils/algorithm.h +++ b/src/libs/utils/algorithm.h @@ -25,10 +25,11 @@ #pragma once +#include "predicates.h" + #include <qcompilerdetection.h> // for Q_REQUIRED_RESULT #include <algorithm> -#include <functional> #include <tuple> #include <QStringList> @@ -137,23 +138,6 @@ typename T::value_type findOrDefault(const T &container, R (S::*function)() cons } ////////////////// -// find helpers -////////////////// -template<typename R, typename S, typename T> -decltype(auto) equal(R (S::*function)() const, T value) -{ - // This should use std::equal_to<> instead of std::eqaul_to<T>, - // but that's not supported everywhere yet, since it is C++14 - return std::bind<bool>(std::equal_to<T>(), value, std::bind(function, std::placeholders::_1)); -} - -template<typename R, typename S, typename T> -decltype(auto) equal(R S::*member, T value) -{ - return std::bind<bool>(std::equal_to<T>(), value, std::bind(member, std::placeholders::_1)); -} - -////////////////// // max element ////////////////// |