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);
}
// 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
template<typename T>
struct ContainerType
@@ -226,10 +219,10 @@ template<template<typename> class T_Container, typename T_Type>
struct ContainerType<T_Container<T_Type>>
{
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>
using ResultOfTransformPMF = T_Container<decay_t<R>>;
using ResultOfTransformPMF = T_Container<std::decay_t<R>>;
};
// specialization for QStringList
@@ -314,10 +307,10 @@ template<template<typename> class C, // result container type
typename S>
Q_REQUIRED_RESULT
auto transform(const SC &container, R (S::*p)() const)
-> C<decay_t<R>>
-> C<std::decay_t<R>>
{
return TransformImpl<
C<decay_t<R>>,
C<std::decay_t<R>>,
SC
>::call(container, p);
}

View File

@@ -52,7 +52,7 @@ class MapReduceBase : public MapReduceObject
protected:
static const int MAX_PROGRESS = 1000000;
// 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:
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,
std::forward<ReduceFunction>(reduce), option, size);
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);
}
@@ -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
template <typename State>
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)) { }
StateResult operator()()
{
@@ -333,7 +333,7 @@ struct StateWrapper {
// copies or moves reduce function to member, calls the reduce function with state and mapped value
template <typename StateResult, typename MapResult, typename ReduceFunction>
struct ReduceWrapper {
using Reduce = typename std::decay<ReduceFunction>::type;
using Reduce = std::decay_t<ReduceFunction>;
ReduceWrapper(ReduceFunction &&reduce) : m_reduce(std::forward<ReduceFunction>(reduce)) { }
void operator()(QFutureInterface<StateResult> &, StateResult &state, const MapResult &mapResult)
{
@@ -376,11 +376,11 @@ mapReduce(ForwardIterator begin, ForwardIterator end, InitFunction &&init, MapFu
return runAsync(priority,
Internal::blockingIteratorMapReduce<
ForwardIterator,
typename std::decay<InitFunction>::type,
typename std::decay<MapFunction>::type,
typename std::decay<ReduceResult>::type,
typename std::decay<ReduceFunction>::type,
typename std::decay<CleanUpFunction>::type>,
std::decay_t<InitFunction>,
std::decay_t<MapFunction>,
std::decay_t<ReduceResult>,
std::decay_t<ReduceFunction>,
std::decay_t<CleanUpFunction>>,
begin, end, std::forward<InitFunction>(init), std::forward<MapFunction>(map),
std::forward<ReduceFunction>(reduce), std::forward<CleanUpFunction>(cleanup),
option, size);
@@ -446,11 +446,12 @@ mapReduce(Container &&container, InitFunction &&init, MapFunction &&map,
{
return runAsync(priority,
Internal::blockingContainerMapReduce<
typename std::decay<Container>::type,
typename std::decay<InitFunction>::type,
typename std::decay<MapFunction>::type,
typename std::decay<ReduceResult>::type, typename std::decay<ReduceFunction>::type,
typename std::decay<CleanUpFunction>::type>,
std::decay_t<Container>,
std::decay_t<InitFunction>,
std::decay_t<MapFunction>,
std::decay_t<ReduceResult>,
std::decay_t<ReduceFunction>,
std::decay_t<CleanUpFunction>>,
std::forward<Container>(container),
std::forward<InitFunction>(init), std::forward<MapFunction>(map),
std::forward<ReduceFunction>(reduce), std::forward<CleanUpFunction>(cleanup),
@@ -469,11 +470,11 @@ mapReduce(std::reference_wrapper<Container> containerWrapper, InitFunction &&ini
return runAsync(priority,
Internal::blockingContainerRefMapReduce<
Container,
typename std::decay<InitFunction>::type,
typename std::decay<MapFunction>::type,
typename std::decay<ReduceResult>::type,
typename std::decay<ReduceFunction>::type,
typename std::decay<CleanUpFunction>::type>,
std::decay_t<InitFunction>,
std::decay_t<MapFunction>,
std::decay_t<ReduceResult>,
std::decay_t<ReduceFunction>,
std::decay_t<CleanUpFunction>>,
containerWrapper,
std::forward<InitFunction>(init), std::forward<MapFunction>(map),
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,
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>
QFuture<StateResult>
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,
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>
QFuture<StateResult>
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,
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>
Q_REQUIRED_RESULT
StateResult
@@ -528,7 +529,7 @@ mappedReduced(ForwardIterator begin, ForwardIterator end, MapFunction &&map, Sta
}
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>
Q_REQUIRED_RESULT
StateResult

View File

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

View File

@@ -107,7 +107,7 @@ public:
}
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(characterPointer, std::strlen(characterPointer))
@@ -120,15 +120,15 @@ public:
{}
template<typename Type,
typename = typename std::enable_if<
std::is_same<typename std::decay<Type>::type, std::string>::value>::type>
typename = std::enable_if_t<std::is_same<std::decay_t<Type>, std::string>::value>
>
BasicSmallString(Type &&string)
: BasicSmallString(string.data(), string.size())
{}
template<typename BeginIterator,
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(&(*begin), size_type(end - begin))
@@ -560,7 +560,7 @@ unitttest_public:
}
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
{
@@ -568,7 +568,7 @@ unitttest_public:
}
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
{
@@ -620,7 +620,7 @@ unitttest_public:
}
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
{
@@ -628,7 +628,7 @@ unitttest_public:
}
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
{

View File

@@ -50,7 +50,7 @@ public:
}
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
: m_pointer(characterPointer),