Use _t versions of various type traits

Available now after switching to C++14 and GCC>=4.9

Change-Id: I44e9859a6abe66db16d77b228466b65eadced8ae
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Eike Ziller
2017-01-11 17:04:23 +01:00
parent b299ff19ec
commit 63f66f28ac
5 changed files with 51 additions and 61 deletions

View File

@@ -207,13 +207,6 @@ inserter(QSet<X> &container)
return QSetInsertIterator<QSet<X>>(container); return QSetInsertIterator<QSet<X>>(container);
} }
// decay_t is C++14, so provide it here, remove once we require C++14
template<typename T>
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
@@ -226,10 +219,10 @@ template<template<typename> class T_Container, typename T_Type>
struct ContainerType<T_Container<T_Type>> struct ContainerType<T_Container<T_Type>>
{ {
template<class F, template<typename> class C = T_Container> template<class F, template<typename> class C = T_Container>
using ResultOfTransform = C<decay_t<result_of_t<F (T_Type)>>>; using ResultOfTransform = C<std::decay_t<std::result_of_t<F (T_Type)>>>;
template<class R> template<class R>
using ResultOfTransformPMF = T_Container<decay_t<R>>; using ResultOfTransformPMF = T_Container<std::decay_t<R>>;
}; };
// specialization for QStringList // specialization for QStringList
@@ -314,10 +307,10 @@ template<template<typename> class C, // result container type
typename S> typename S>
Q_REQUIRED_RESULT Q_REQUIRED_RESULT
auto transform(const SC &container, R (S::*p)() const) auto transform(const SC &container, R (S::*p)() const)
-> C<decay_t<R>> -> C<std::decay_t<R>>
{ {
return TransformImpl< return TransformImpl<
C<decay_t<R>>, C<std::decay_t<R>>,
SC SC
>::call(container, p); >::call(container, p);
} }

View File

@@ -52,7 +52,7 @@ class MapReduceBase : public MapReduceObject
protected: protected:
static const int MAX_PROGRESS = 1000000; static const int MAX_PROGRESS = 1000000;
// either const or non-const reference wrapper for items from the iterator // either const or non-const reference wrapper for items from the iterator
using ItemReferenceWrapper = std::reference_wrapper<typename std::remove_reference<typename ForwardIterator::reference>::type>; using ItemReferenceWrapper = std::reference_wrapper<std::remove_reference_t<typename ForwardIterator::reference>>;
public: public:
MapReduceBase(QFutureInterface<ReduceResult> futureInterface, ForwardIterator begin, ForwardIterator end, MapReduceBase(QFutureInterface<ReduceResult> futureInterface, ForwardIterator begin, ForwardIterator end,
@@ -281,7 +281,7 @@ void blockingIteratorMapReduce(QFutureInterface<ReduceResult> &futureInterface,
mr(futureInterface, begin, end, std::forward<MapFunction>(map), state, mr(futureInterface, begin, end, std::forward<MapFunction>(map), state,
std::forward<ReduceFunction>(reduce), option, size); std::forward<ReduceFunction>(reduce), option, size);
mr.exec(); mr.exec();
callWithMaybeFutureInterface<ReduceResult, CleanUpFunction, typename std::remove_reference<decltype(state)>::type&> callWithMaybeFutureInterface<ReduceResult, CleanUpFunction, std::remove_reference_t<decltype(state)>&>
(futureInterface, std::forward<CleanUpFunction>(cleanup), state); (futureInterface, std::forward<CleanUpFunction>(cleanup), state);
} }
@@ -320,7 +320,7 @@ static void *dummyInit() { return nullptr; }
// copies or moves state to member, and then moves it to the result of the call operator // copies or moves state to member, and then moves it to the result of the call operator
template <typename State> template <typename State>
struct StateWrapper { struct StateWrapper {
using StateResult = typename std::decay<State>::type; // State is const& or & for lvalues using StateResult = std::decay_t<State>; // State is const& or & for lvalues
StateWrapper(State &&state) : m_state(std::forward<State>(state)) { } StateWrapper(State &&state) : m_state(std::forward<State>(state)) { }
StateResult operator()() StateResult operator()()
{ {
@@ -333,7 +333,7 @@ struct StateWrapper {
// copies or moves reduce function to member, calls the reduce function with state and mapped value // copies or moves reduce function to member, calls the reduce function with state and mapped value
template <typename StateResult, typename MapResult, typename ReduceFunction> template <typename StateResult, typename MapResult, typename ReduceFunction>
struct ReduceWrapper { struct ReduceWrapper {
using Reduce = typename std::decay<ReduceFunction>::type; using Reduce = std::decay_t<ReduceFunction>;
ReduceWrapper(ReduceFunction &&reduce) : m_reduce(std::forward<ReduceFunction>(reduce)) { } ReduceWrapper(ReduceFunction &&reduce) : m_reduce(std::forward<ReduceFunction>(reduce)) { }
void operator()(QFutureInterface<StateResult> &, StateResult &state, const MapResult &mapResult) void operator()(QFutureInterface<StateResult> &, StateResult &state, const MapResult &mapResult)
{ {
@@ -376,11 +376,11 @@ mapReduce(ForwardIterator begin, ForwardIterator end, InitFunction &&init, MapFu
return runAsync(priority, return runAsync(priority,
Internal::blockingIteratorMapReduce< Internal::blockingIteratorMapReduce<
ForwardIterator, ForwardIterator,
typename std::decay<InitFunction>::type, std::decay_t<InitFunction>,
typename std::decay<MapFunction>::type, std::decay_t<MapFunction>,
typename std::decay<ReduceResult>::type, std::decay_t<ReduceResult>,
typename std::decay<ReduceFunction>::type, std::decay_t<ReduceFunction>,
typename std::decay<CleanUpFunction>::type>, std::decay_t<CleanUpFunction>>,
begin, end, std::forward<InitFunction>(init), std::forward<MapFunction>(map), begin, end, std::forward<InitFunction>(init), std::forward<MapFunction>(map),
std::forward<ReduceFunction>(reduce), std::forward<CleanUpFunction>(cleanup), std::forward<ReduceFunction>(reduce), std::forward<CleanUpFunction>(cleanup),
option, size); option, size);
@@ -446,11 +446,12 @@ mapReduce(Container &&container, InitFunction &&init, MapFunction &&map,
{ {
return runAsync(priority, return runAsync(priority,
Internal::blockingContainerMapReduce< Internal::blockingContainerMapReduce<
typename std::decay<Container>::type, std::decay_t<Container>,
typename std::decay<InitFunction>::type, std::decay_t<InitFunction>,
typename std::decay<MapFunction>::type, std::decay_t<MapFunction>,
typename std::decay<ReduceResult>::type, typename std::decay<ReduceFunction>::type, std::decay_t<ReduceResult>,
typename std::decay<CleanUpFunction>::type>, std::decay_t<ReduceFunction>,
std::decay_t<CleanUpFunction>>,
std::forward<Container>(container), std::forward<Container>(container),
std::forward<InitFunction>(init), std::forward<MapFunction>(map), std::forward<InitFunction>(init), std::forward<MapFunction>(map),
std::forward<ReduceFunction>(reduce), std::forward<CleanUpFunction>(cleanup), std::forward<ReduceFunction>(reduce), std::forward<CleanUpFunction>(cleanup),
@@ -469,11 +470,11 @@ mapReduce(std::reference_wrapper<Container> containerWrapper, InitFunction &&ini
return runAsync(priority, return runAsync(priority,
Internal::blockingContainerRefMapReduce< Internal::blockingContainerRefMapReduce<
Container, Container,
typename std::decay<InitFunction>::type, std::decay_t<InitFunction>,
typename std::decay<MapFunction>::type, std::decay_t<MapFunction>,
typename std::decay<ReduceResult>::type, std::decay_t<ReduceResult>,
typename std::decay<ReduceFunction>::type, std::decay_t<ReduceFunction>,
typename std::decay<CleanUpFunction>::type>, std::decay_t<CleanUpFunction>>,
containerWrapper, containerWrapper,
std::forward<InitFunction>(init), std::forward<MapFunction>(map), std::forward<InitFunction>(init), std::forward<MapFunction>(map),
std::forward<ReduceFunction>(reduce), std::forward<CleanUpFunction>(cleanup), std::forward<ReduceFunction>(reduce), std::forward<CleanUpFunction>(cleanup),
@@ -481,7 +482,7 @@ mapReduce(std::reference_wrapper<Container> containerWrapper, InitFunction &&ini
} }
template <typename ForwardIterator, typename MapFunction, typename State, typename ReduceFunction, template <typename ForwardIterator, typename MapFunction, typename State, typename ReduceFunction,
typename StateResult = typename std::decay<State>::type, // State = T& or const T& for lvalues, so decay that away typename StateResult = std::decay_t<State>, // State = T& or const T& for lvalues, so decay that away
typename MapResult = typename Internal::resultType<MapFunction>::type> typename MapResult = typename Internal::resultType<MapFunction>::type>
QFuture<StateResult> QFuture<StateResult>
mapReduce(ForwardIterator begin, ForwardIterator end, MapFunction &&map, State &&initialState, mapReduce(ForwardIterator begin, ForwardIterator end, MapFunction &&map, State &&initialState,
@@ -497,7 +498,7 @@ mapReduce(ForwardIterator begin, ForwardIterator end, MapFunction &&map, State &
} }
template <typename Container, typename MapFunction, typename State, typename ReduceFunction, template <typename Container, typename MapFunction, typename State, typename ReduceFunction,
typename StateResult = typename std::decay<State>::type, // State = T& or const T& for lvalues, so decay that away typename StateResult = std::decay_t<State>, // State = T& or const T& for lvalues, so decay that away
typename MapResult = typename Internal::resultType<MapFunction>::type> typename MapResult = typename Internal::resultType<MapFunction>::type>
QFuture<StateResult> QFuture<StateResult>
mapReduce(Container &&container, MapFunction &&map, State &&initialState, ReduceFunction &&reduce, mapReduce(Container &&container, MapFunction &&map, State &&initialState, ReduceFunction &&reduce,
@@ -513,7 +514,7 @@ mapReduce(Container &&container, MapFunction &&map, State &&initialState, Reduce
} }
template <typename ForwardIterator, typename MapFunction, typename State, typename ReduceFunction, template <typename ForwardIterator, typename MapFunction, typename State, typename ReduceFunction,
typename StateResult = typename std::decay<State>::type, // State = T& or const T& for lvalues, so decay that away typename StateResult = std::decay_t<State>, // State = T& or const T& for lvalues, so decay that away
typename MapResult = typename Internal::resultType<MapFunction>::type> typename MapResult = typename Internal::resultType<MapFunction>::type>
Q_REQUIRED_RESULT Q_REQUIRED_RESULT
StateResult StateResult
@@ -528,7 +529,7 @@ mappedReduced(ForwardIterator begin, ForwardIterator end, MapFunction &&map, Sta
} }
template <typename Container, typename MapFunction, typename State, typename ReduceFunction, template <typename Container, typename MapFunction, typename State, typename ReduceFunction,
typename StateResult = typename std::decay<State>::type, // State = T& or const T& for lvalues, so decay that away typename StateResult = std::decay_t<State>, // State = T& or const T& for lvalues, so decay that away
typename MapResult = typename Internal::resultType<MapFunction>::type> typename MapResult = typename Internal::resultType<MapFunction>::type>
Q_REQUIRED_RESULT Q_REQUIRED_RESULT
StateResult StateResult

View File

@@ -140,7 +140,7 @@ struct resultTypeIsFunctionLike<Function, false>
template <typename Function> template <typename Function>
struct resultTypeHasCallOperator<Function, false> struct resultTypeHasCallOperator<Function, false>
: public resultTypeIsFunctionLike<Function, std::is_function<typename std::remove_pointer<typename std::decay<Function>::type>::type>::value> : public resultTypeIsFunctionLike<Function, std::is_function<std::remove_pointer_t<std::decay_t<Function>>>::value>
{ {
}; };
@@ -257,15 +257,14 @@ void runAsyncQFutureInterfaceDispatch(std::true_type, QFutureInterface<ResultTyp
template <typename ResultType, typename Function, typename... Args> template <typename ResultType, typename Function, typename... Args>
void runAsyncQFutureInterfaceDispatch(std::false_type, QFutureInterface<ResultType> futureInterface, Function &&function, Args&&... args) void runAsyncQFutureInterfaceDispatch(std::false_type, QFutureInterface<ResultType> futureInterface, Function &&function, Args&&... args)
{ {
runAsyncReturnVoidDispatch(std::is_void<typename std::result_of<Function(Args...)>::type>(), runAsyncReturnVoidDispatch(std::is_void<std::result_of_t<Function(Args...)>>(),
futureInterface, std::forward<Function>(function), std::forward<Args>(args)...); futureInterface, std::forward<Function>(function), std::forward<Args>(args)...);
} }
// function, function pointer, or other callable object that is no member pointer // function, function pointer, or other callable object that is no member pointer
template <typename ResultType, typename Function, typename... Args, template <typename ResultType, typename Function, typename... Args,
typename = typename std::enable_if< typename = std::enable_if_t<!std::is_member_pointer<std::decay_t<Function>>::value>
!std::is_member_pointer<typename std::decay<Function>::type>::value >
>::type>
void runAsyncMemberDispatch(QFutureInterface<ResultType> futureInterface, Function &&function, Args&&... args) void runAsyncMemberDispatch(QFutureInterface<ResultType> futureInterface, Function &&function, Args&&... args)
{ {
runAsyncQFutureInterfaceDispatch(functionTakesArgument<Function, 0, QFutureInterface<ResultType>&>(), runAsyncQFutureInterfaceDispatch(functionTakesArgument<Function, 0, QFutureInterface<ResultType>&>(),
@@ -274,14 +273,13 @@ void runAsyncMemberDispatch(QFutureInterface<ResultType> futureInterface, Functi
// Function = member function // Function = member function
template <typename ResultType, typename Function, typename Obj, typename... Args, template <typename ResultType, typename Function, typename Obj, typename... Args,
typename = typename std::enable_if< typename = std::enable_if_t<std::is_member_pointer<std::decay_t<Function>>::value>
std::is_member_pointer<typename std::decay<Function>::type>::value >
>::type>
void runAsyncMemberDispatch(QFutureInterface<ResultType> futureInterface, Function &&function, Obj &&obj, Args&&... args) void runAsyncMemberDispatch(QFutureInterface<ResultType> futureInterface, Function &&function, Obj &&obj, Args&&... args)
{ {
// Wrap member function with object into callable // Wrap member function with object into callable
runAsyncImpl(futureInterface, runAsyncImpl(futureInterface,
MemberCallable<typename std::decay<Function>::type>(std::forward<Function>(function), std::forward<Obj>(obj)), MemberCallable<std::decay_t<Function>>(std::forward<Function>(function), std::forward<Obj>(obj)),
std::forward<Args>(args)...); std::forward<Args>(args)...);
} }
@@ -315,7 +313,7 @@ template <std::size_t... S>
struct makeIndexSequence<0, S...> { typedef indexSequence<S...> type; }; struct makeIndexSequence<0, S...> { typedef indexSequence<S...> type; };
template <class T> template <class T>
typename std::decay<T>::type std::decay_t<T>
decayCopy(T&& v) decayCopy(T&& v)
{ {
return std::forward<T>(v); return std::forward<T>(v);
@@ -369,7 +367,7 @@ public:
} }
private: private:
using Data = std::tuple<typename std::decay<Function>::type, typename std::decay<Args>::type...>; using Data = std::tuple<std::decay_t<Function>, std::decay_t<Args>...>;
template <std::size_t... index> template <std::size_t... index>
void runHelper(indexSequence<index...>) void runHelper(indexSequence<index...>)
@@ -464,10 +462,10 @@ runAsync(QThread::Priority priority, Function &&function, Args&&... args)
\sa QThread::Priority \sa QThread::Priority
*/ */
template <typename Function, typename... Args, template <typename Function, typename... Args,
typename = typename std::enable_if< typename = std::enable_if_t<
!std::is_same<typename std::decay<Function>::type, QThreadPool>::value !std::is_same<std::decay_t<Function>, QThreadPool>::value
&& !std::is_same<typename std::decay<Function>::type, QThread::Priority>::value && !std::is_same<std::decay_t<Function>, QThread::Priority>::value
>::type, >,
typename ResultType = typename Internal::resultType<Function>::type> typename ResultType = typename Internal::resultType<Function>::type>
QFuture<ResultType> QFuture<ResultType>
runAsync(Function &&function, Args&&... args) runAsync(Function &&function, Args&&... args)
@@ -483,9 +481,7 @@ runAsync(Function &&function, Args&&... args)
\sa QThread::Priority \sa QThread::Priority
*/ */
template <typename Function, typename... Args, template <typename Function, typename... Args,
typename = typename std::enable_if< typename = std::enable_if_t<!std::is_same<std::decay_t<Function>, QThread::Priority>::value>,
!std::is_same<typename std::decay<Function>::type, QThread::Priority>::value
>::type,
typename ResultType = typename Internal::resultType<Function>::type> typename ResultType = typename Internal::resultType<Function>::type>
QFuture<ResultType> QFuture<ResultType>
runAsync(QThreadPool *pool, Function &&function, Args&&... args) runAsync(QThreadPool *pool, Function &&function, Args&&... args)

View File

@@ -107,7 +107,7 @@ public:
} }
template<typename Type, template<typename Type,
typename = typename std::enable_if<std::is_pointer<Type>::value>::type typename = std::enable_if_t<std::is_pointer<Type>::value>
> >
BasicSmallString(Type characterPointer) BasicSmallString(Type characterPointer)
: BasicSmallString(characterPointer, std::strlen(characterPointer)) : BasicSmallString(characterPointer, std::strlen(characterPointer))
@@ -120,15 +120,15 @@ public:
{} {}
template<typename Type, template<typename Type,
typename = typename std::enable_if< typename = std::enable_if_t<std::is_same<std::decay_t<Type>, std::string>::value>
std::is_same<typename std::decay<Type>::type, std::string>::value>::type> >
BasicSmallString(Type &&string) BasicSmallString(Type &&string)
: BasicSmallString(string.data(), string.size()) : BasicSmallString(string.data(), string.size())
{} {}
template<typename BeginIterator, template<typename BeginIterator,
typename EndIterator, typename EndIterator,
typename = typename std::enable_if<std::is_same<BeginIterator, EndIterator>::value>::type typename = std::enable_if_t<std::is_same<BeginIterator, EndIterator>::value>
> >
BasicSmallString(BeginIterator begin, EndIterator end) BasicSmallString(BeginIterator begin, EndIterator end)
: BasicSmallString(&(*begin), size_type(end - begin)) : BasicSmallString(&(*begin), size_type(end - begin))
@@ -560,7 +560,7 @@ unitttest_public:
} }
template<typename Type, template<typename Type,
typename = typename std::enable_if<std::is_pointer<Type>::value>::type typename = std::enable_if_t<std::is_pointer<Type>::value>
> >
friend bool operator==(const BasicSmallString& first, Type second) noexcept friend bool operator==(const BasicSmallString& first, Type second) noexcept
{ {
@@ -568,7 +568,7 @@ unitttest_public:
} }
template<typename Type, template<typename Type,
typename = typename std::enable_if<std::is_pointer<Type>::value>::type typename = std::enable_if_t<std::is_pointer<Type>::value>
> >
friend bool operator==(Type first, const BasicSmallString& second) noexcept friend bool operator==(Type first, const BasicSmallString& second) noexcept
{ {
@@ -620,7 +620,7 @@ unitttest_public:
} }
template<typename Type, template<typename Type,
typename = typename std::enable_if<std::is_pointer<Type>::value>::type typename = std::enable_if_t<std::is_pointer<Type>::value>
> >
friend bool operator!=(const BasicSmallString& first, Type second) noexcept friend bool operator!=(const BasicSmallString& first, Type second) noexcept
{ {
@@ -628,7 +628,7 @@ unitttest_public:
} }
template<typename Type, template<typename Type,
typename = typename std::enable_if<std::is_pointer<Type>::value>::type typename = std::enable_if_t<std::is_pointer<Type>::value>
> >
friend bool operator!=(Type first, const BasicSmallString& second) noexcept friend bool operator!=(Type first, const BasicSmallString& second) noexcept
{ {

View File

@@ -50,7 +50,7 @@ public:
} }
template<typename Type, template<typename Type,
typename = typename std::enable_if<std::is_pointer<Type>::value>::type typename = std::enable_if_t<std::is_pointer<Type>::value>
> >
SmallStringView(Type characterPointer) noexcept SmallStringView(Type characterPointer) noexcept
: m_pointer(characterPointer), : m_pointer(characterPointer),