From c75500670d6d074edfc7e5aeb4fbac72d0f3b79b Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 16 May 2019 16:25:53 +0800 Subject: [PATCH] Use forwarding reference when passing function objects So instead of passing every function objects by value (a copy is made), now function objects will be handled properly by reference (for lvalues) or by value (for rvalues). --- src/base/algorithm.h | 4 ++-- src/base/settingvalue.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/base/algorithm.h b/src/base/algorithm.h index 01aa39324..6eb9089b6 100644 --- a/src/base/algorithm.h +++ b/src/base/algorithm.h @@ -50,7 +50,7 @@ namespace Algorithm // To be used with associative array types, such as QMap, QHash and it's variants template ::value, int> = 0> - void removeIf(T &dict, BinaryPredicate p) + void removeIf(T &dict, BinaryPredicate &&p) { auto it = dict.begin(); while (it != dict.end()) @@ -60,7 +60,7 @@ namespace Algorithm // To be used with set types, such as QSet, std::set template ::value, int> = 0> - void removeIf(T &set, UnaryPredicate p) + void removeIf(T &set, UnaryPredicate &&p) { auto it = set.begin(); while (it != set.end()) diff --git a/src/base/settingvalue.h b/src/base/settingvalue.h index b2d13b353..64998e2d4 100644 --- a/src/base/settingvalue.h +++ b/src/base/settingvalue.h @@ -50,7 +50,7 @@ public: // T proxyFunc(const T &a); template explicit CachedSettingValue(const char *keyName, const T &defaultValue - , ProxyFunc proxyFunc) + , ProxyFunc &&proxyFunc) : m_keyName(QLatin1String(keyName)) , m_value(proxyFunc(loadValue(defaultValue))) {