forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -140,8 +140,7 @@ typename T::value_type findOrDefault(const T &container, R (S::*function)() cons
|
|||||||
// find helpers
|
// find helpers
|
||||||
//////////////////
|
//////////////////
|
||||||
template<typename R, typename S, typename T>
|
template<typename R, typename S, typename T>
|
||||||
auto equal(R (S::*function)() const, T value)
|
decltype(auto) equal(R (S::*function)() const, T value)
|
||||||
-> decltype(std::bind<bool>(std::equal_to<T>(), value, std::bind(function, std::placeholders::_1)))
|
|
||||||
{
|
{
|
||||||
// This should use std::equal_to<> instead of std::eqaul_to<T>,
|
// This should use std::equal_to<> instead of std::eqaul_to<T>,
|
||||||
// but that's not supported everywhere yet, since it is C++14
|
// 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>
|
template<typename R, typename S, typename T>
|
||||||
auto equal(R S::*member, T value)
|
decltype(auto) equal(R S::*member, T value)
|
||||||
-> decltype(std::bind<bool>(std::equal_to<T>(), value, std::bind(member, std::placeholders::_1)))
|
|
||||||
{
|
{
|
||||||
return std::bind<bool>(std::equal_to<T>(), value, std::bind(member, std::placeholders::_1));
|
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
|
template<typename C, // container
|
||||||
typename F>
|
typename F>
|
||||||
Q_REQUIRED_RESULT
|
Q_REQUIRED_RESULT
|
||||||
auto transform(const C &container, F function)
|
decltype(auto) transform(const C &container, F function)
|
||||||
-> typename ContainerType<C>::template ResultOfTransform<F>
|
|
||||||
{
|
{
|
||||||
return TransformImpl<
|
return TransformImpl<
|
||||||
typename ContainerType<C>::template ResultOfTransform<F>,
|
typename ContainerType<C>::template ResultOfTransform<F>,
|
||||||
@@ -276,8 +273,7 @@ template<typename C,
|
|||||||
typename R,
|
typename R,
|
||||||
typename S>
|
typename S>
|
||||||
Q_REQUIRED_RESULT
|
Q_REQUIRED_RESULT
|
||||||
auto transform(const C &container, R (S::*p)() const)
|
decltype(auto) transform(const C &container, R (S::*p)() const)
|
||||||
->typename ContainerType<C>::template ResultOfTransformPMF<R>
|
|
||||||
{
|
{
|
||||||
return TransformImpl<
|
return TransformImpl<
|
||||||
typename ContainerType<C>::template ResultOfTransformPMF<R>,
|
typename ContainerType<C>::template ResultOfTransformPMF<R>,
|
||||||
@@ -290,8 +286,7 @@ template<template<typename> class C, // result container type
|
|||||||
typename SC, // input container type
|
typename SC, // input container type
|
||||||
typename F> // function type
|
typename F> // function type
|
||||||
Q_REQUIRED_RESULT
|
Q_REQUIRED_RESULT
|
||||||
auto transform(const SC &container, F function)
|
decltype(auto) transform(const SC &container, F function)
|
||||||
-> typename ContainerType<SC>::template ResultOfTransform<F, C>
|
|
||||||
{
|
{
|
||||||
return TransformImpl<
|
return TransformImpl<
|
||||||
typename ContainerType<SC>::template ResultOfTransform<F, C>,
|
typename ContainerType<SC>::template ResultOfTransform<F, C>,
|
||||||
@@ -306,8 +301,7 @@ template<template<typename> class C, // result container type
|
|||||||
typename R,
|
typename R,
|
||||||
typename S>
|
typename S>
|
||||||
Q_REQUIRED_RESULT
|
Q_REQUIRED_RESULT
|
||||||
auto transform(const SC &container, R (S::*p)() const)
|
decltype(auto) transform(const SC &container, R (S::*p)() const)
|
||||||
-> C<std::decay_t<R>>
|
|
||||||
{
|
{
|
||||||
return TransformImpl<
|
return TransformImpl<
|
||||||
C<std::decay_t<R>>,
|
C<std::decay_t<R>>,
|
||||||
|
|||||||
Reference in New Issue
Block a user