aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/algorithm.h
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2017-01-12 09:43:51 +0100
committerEike Ziller <eike.ziller@qt.io>2017-01-30 10:46:30 +0000
commitaf8812b2488af1c8a22679a16c793c91f03f6d3a (patch)
tree71c5cafa42559b85433782a4e187ca9d8d9082aa /src/libs/utils/algorithm.h
parent63f66f28ac43c2da3bb278e63ff7c49cde2c1d5c (diff)
Algorithm: Use decltype(auto)
Avoids some code duplication. Available with C++14 / GCC>=4.9. Change-Id: Iae90466ec9620ffc84b7a45a55490f5fbc8c5b74 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Diffstat (limited to 'src/libs/utils/algorithm.h')
-rw-r--r--src/libs/utils/algorithm.h18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/libs/utils/algorithm.h b/src/libs/utils/algorithm.h
index 909f32a609d..faa72a5ac02 100644
--- a/src/libs/utils/algorithm.h
+++ b/src/libs/utils/algorithm.h
@@ -140,8 +140,7 @@ typename T::value_type findOrDefault(const T &container, R (S::*function)() cons
// find helpers
//////////////////
template<typename R, typename S, typename T>
-auto equal(R (S::*function)() const, T value)
- -> decltype(std::bind<bool>(std::equal_to<T>(), value, std::bind(function, std::placeholders::_1)))
+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
@@ -149,8 +148,7 @@ auto equal(R (S::*function)() const, T value)
}
template<typename R, typename S, typename T>
-auto equal(R S::*member, T value)
- -> decltype(std::bind<bool>(std::equal_to<T>(), value, std::bind(member, std::placeholders::_1)))
+decltype(auto) equal(R S::*member, T value)
{
return std::bind<bool>(std::equal_to<T>(), value, std::bind(member, std::placeholders::_1));
}
@@ -262,8 +260,7 @@ struct TransformImpl {
template<typename C, // container
typename F>
Q_REQUIRED_RESULT
-auto transform(const C &container, F function)
--> typename ContainerType<C>::template ResultOfTransform<F>
+decltype(auto) transform(const C &container, F function)
{
return TransformImpl<
typename ContainerType<C>::template ResultOfTransform<F>,
@@ -276,8 +273,7 @@ template<typename C,
typename R,
typename S>
Q_REQUIRED_RESULT
-auto transform(const C &container, R (S::*p)() const)
- ->typename ContainerType<C>::template ResultOfTransformPMF<R>
+decltype(auto) transform(const C &container, R (S::*p)() const)
{
return TransformImpl<
typename ContainerType<C>::template ResultOfTransformPMF<R>,
@@ -290,8 +286,7 @@ template<template<typename> class C, // result container type
typename SC, // input container type
typename F> // function type
Q_REQUIRED_RESULT
-auto transform(const SC &container, F function)
- -> typename ContainerType<SC>::template ResultOfTransform<F, C>
+decltype(auto) transform(const SC &container, F function)
{
return TransformImpl<
typename ContainerType<SC>::template ResultOfTransform<F, C>,
@@ -306,8 +301,7 @@ template<template<typename> class C, // result container type
typename R,
typename S>
Q_REQUIRED_RESULT
-auto transform(const SC &container, R (S::*p)() const)
- -> C<std::decay_t<R>>
+decltype(auto) transform(const SC &container, R (S::*p)() const)
{
return TransformImpl<
C<std::decay_t<R>>,