QFutureInterface: Extract Method reportAndEmplaceResult() from reportAndMoveResult()
This will be the building block for emplacement support in QPromise. Task-number: QTBUG-112270 Change-Id: Ie267e76fe078a8f7b3ef8c7e0d2abfcd22062ff2 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>bb10
parent
3087aa55dc
commit
d25337a631
|
|
@ -236,6 +236,8 @@ public:
|
|||
|
||||
inline QFuture<T> future(); // implemented in qfuture.h
|
||||
|
||||
template <typename...Args, std::enable_if_t<std::is_constructible_v<T, Args...>, bool> = true>
|
||||
inline bool reportAndEmplaceResult(int index, Args&&...args);
|
||||
inline bool reportResult(const T *result, int index = -1);
|
||||
inline bool reportAndMoveResult(T &&result, int index = -1);
|
||||
inline bool reportResult(T &&result, int index = -1);
|
||||
|
|
@ -301,7 +303,8 @@ inline bool QFutureInterface<T>::reportResult(const T *result, int index)
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
bool QFutureInterface<T>::reportAndMoveResult(T &&result, int index)
|
||||
template<typename...Args, std::enable_if_t<std::is_constructible_v<T, Args...>, bool>>
|
||||
bool QFutureInterface<T>::reportAndEmplaceResult(int index, Args&&...args)
|
||||
{
|
||||
QMutexLocker<QMutex> locker{&mutex()};
|
||||
if (queryState(Canceled) || queryState(Finished))
|
||||
|
|
@ -311,13 +314,19 @@ bool QFutureInterface<T>::reportAndMoveResult(T &&result, int index)
|
|||
QtPrivate::ResultStoreBase &store = resultStoreBase();
|
||||
|
||||
const int oldResultCount = store.count();
|
||||
const int insertIndex = store.moveResult(index, std::move(result));
|
||||
const int insertIndex = store.emplaceResult<T>(index, std::forward<Args>(args)...);
|
||||
// Let's make sure it's not in pending results.
|
||||
if (insertIndex != -1 && (!store.filterMode() || oldResultCount < store.count()))
|
||||
reportResultsReady(insertIndex, store.count());
|
||||
return insertIndex != -1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool QFutureInterface<T>::reportAndMoveResult(T &&result, int index)
|
||||
{
|
||||
return reportAndEmplaceResult(index, std::move(result));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool QFutureInterface<T>::reportResult(T &&result, int index)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue