From 64e74fe2354b4638b62b1ffb569c02a547ca8fa6 Mon Sep 17 00:00:00 2001 From: Simon Haegler Date: Fri, 10 Jan 2020 17:36:08 +0100 Subject: [PATCH] #40: review 2: improve perfect forwarding in cache template --- src/serlio/util/Utilities.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/serlio/util/Utilities.h b/src/serlio/util/Utilities.h index fb783368..7f7226bc 100644 --- a/src/serlio/util/Utilities.h +++ b/src/serlio/util/Utilities.h @@ -248,12 +248,14 @@ std::basic_string join(Container const& container, const std::basic_string # define MAYBE_UNUSED // [[maybe_unused]] would require /std:c++latest i.e. C++17 #endif -template -auto getCachedValue(M& cache, const typename M::key_type& key, F valueFunc, ARGS&&... valueFuncArgs) { +template , typename M::key_type>::value>> +auto getCachedValue(M& cache, K&& key, F valueFunc, ARGS&&... valueFuncArgs) { auto p = cache.find(key); if (p == cache.end()) { - auto value = valueFunc(std::forward(valueFuncArgs)...); - p = cache.emplace(key, value).first; + auto&& value = valueFunc(std::forward(valueFuncArgs)...); + p = cache.emplace(std::forward(key), std::forward(value)).first; } return p->second; -} +} \ No newline at end of file