forked from qt-creator/qt-creator
Utils::transform with using keyword
Change-Id: I98274bbd78a629854dd1774698158d9bdadc4096 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -211,6 +211,9 @@ inserter(QSet<X> &container)
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
using decay_t = typename std::decay<T>::type;
|
using decay_t = typename std::decay<T>::type;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
using result_of_t = typename std::result_of<T>::type;
|
||||||
|
|
||||||
// abstraction to treat Container<T> and QStringList similarly
|
// abstraction to treat Container<T> and QStringList similarly
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct ContainerType
|
struct ContainerType
|
||||||
@@ -220,26 +223,13 @@ struct ContainerType
|
|||||||
|
|
||||||
// specialization for qt container T_Container<T_Type>
|
// specialization for qt container T_Container<T_Type>
|
||||||
template<template<typename> class T_Container, typename T_Type>
|
template<template<typename> class T_Container, typename T_Type>
|
||||||
struct ContainerType<T_Container<T_Type>> {
|
struct ContainerType<T_Container<T_Type>>
|
||||||
typedef T_Type ElementType;
|
|
||||||
|
|
||||||
template<class NewElementType>
|
|
||||||
struct WithElementType
|
|
||||||
{
|
{
|
||||||
typedef T_Container<NewElementType> type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class F, template<typename> class C = T_Container>
|
template<class F, template<typename> class C = T_Container>
|
||||||
struct ResultOfTransform
|
using ResultOfTransform = C<decay_t<result_of_t<F (T_Type)>>>;
|
||||||
{
|
|
||||||
typedef C<decay_t<typename std::result_of<F (ElementType)>::type>> type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class R>
|
template<class R>
|
||||||
struct ResultOfTransformPMF
|
using ResultOfTransformPMF = T_Container<decay_t<R>>;
|
||||||
{
|
|
||||||
typedef typename WithElementType<decay_t<R>>::type type;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// specialization for QStringList
|
// specialization for QStringList
|
||||||
@@ -280,10 +270,10 @@ template<typename C, // container
|
|||||||
typename F>
|
typename F>
|
||||||
Q_REQUIRED_RESULT
|
Q_REQUIRED_RESULT
|
||||||
auto transform(const C &container, F function)
|
auto transform(const C &container, F function)
|
||||||
-> typename ContainerType<C>::template ResultOfTransform<F>::type
|
-> typename ContainerType<C>::template ResultOfTransform<F>
|
||||||
{
|
{
|
||||||
return TransformImpl<
|
return TransformImpl<
|
||||||
typename ContainerType<C>::template ResultOfTransform<F>::type,
|
typename ContainerType<C>::template ResultOfTransform<F>,
|
||||||
C
|
C
|
||||||
>::call(container, function);
|
>::call(container, function);
|
||||||
}
|
}
|
||||||
@@ -294,10 +284,10 @@ template<typename C,
|
|||||||
typename S>
|
typename S>
|
||||||
Q_REQUIRED_RESULT
|
Q_REQUIRED_RESULT
|
||||||
auto transform(const C &container, R (S::*p)() const)
|
auto transform(const C &container, R (S::*p)() const)
|
||||||
->typename ContainerType<C>::template ResultOfTransformPMF<R>::type
|
->typename ContainerType<C>::template ResultOfTransformPMF<R>
|
||||||
{
|
{
|
||||||
return TransformImpl<
|
return TransformImpl<
|
||||||
typename ContainerType<C>::template ResultOfTransformPMF<R>::type,
|
typename ContainerType<C>::template ResultOfTransformPMF<R>,
|
||||||
C
|
C
|
||||||
>::call(container, p);
|
>::call(container, p);
|
||||||
}
|
}
|
||||||
@@ -308,10 +298,10 @@ template<template<typename> class C, // result container type
|
|||||||
typename F> // function type
|
typename F> // function type
|
||||||
Q_REQUIRED_RESULT
|
Q_REQUIRED_RESULT
|
||||||
auto transform(const SC &container, F function)
|
auto transform(const SC &container, F function)
|
||||||
-> typename ContainerType<SC>::template ResultOfTransform<F, C>::type
|
-> typename ContainerType<SC>::template ResultOfTransform<F, C>
|
||||||
{
|
{
|
||||||
return TransformImpl<
|
return TransformImpl<
|
||||||
typename ContainerType<SC>::template ResultOfTransform<F, C>::type,
|
typename ContainerType<SC>::template ResultOfTransform<F, C>,
|
||||||
SC
|
SC
|
||||||
>::call(container, function);
|
>::call(container, function);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user