6.0.0-rc4Source

QtFuture Namespace

The QtFuture namespace holds helpers for QFuture, such as QtFuture::Launch. More…

Header#include <QtCore/qfuture.h>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes

Public Types

enumLaunch

Public Functions

QFuture<std::tuple<std::decay_t<Futures>...>>whenAll(Futures &&...futures)
autowhenAll(InputIt first, InputIt last) -> QFuture<QList<typename std::iterator_traits<InputIt>::value_type>>
QFuture<std::variant<std::decay_t<Futures>...>>whenAny(Futures &&...futures)
autowhenAny(InputIt first, InputIt last)
QFuture<std::decay_t<T>>makeReadyValueFuture(T &&value)
QFuture<void>makeReadyVoidFuture()
QFuture<typename std::decay_t<Container>::value_type>makeReadyRangeFuture(Container &&values)
QFuture<T>makeReadyRangeFuture(std::initializer_list<T> values)
QFuture<T>makeExceptionalFuture(std::exception_ptr exception)
QFuture<T>makeExceptionalFuture(const QException &exception)
autoconnect(const Sender *sender, Signal signal) -> QFuture<typename QtPrivate::SignalFuture<Signal>::Result>

Detailed Description

Besides the enumeration, it has the functions makeReadyValueFuture(), makeReadyVoidFuture(), makeReadyRangeFuture() and makeExceptionalFuture(), which return a future that is finished already, and connect(), which returns a future for the next emission of a signal.

Member Type Documentation

enum QtFuture::Launch

This enum describes where a continuation attached with QFuture::then() runs.

ConstantDescription
QtFuture::SyncThe continuation runs in the thread that finishes the previous future, or in the thread that calls then() if that future has finished already.
QtFuture::AsyncThe continuation runs in a thread of the global QThreadPool.
QtFuture::InheritThe continuation runs in the thread pool that the previous future runs in, as set with QFutureInterfaceBase::setThreadPool(), and as a Sync continuation if the future has none.

Function Documentation

template <typename Sender, typename Signal>auto QtFuture::connect(const Sender *sender, Signal signal) -> QFuture<typename QtPrivate::SignalFuture<Signal>::Result>

Returns a future that becomes finished the first time sender emits signal. The result is the argument of the signal, a std::tuple of its arguments if there are several, and there is none if it has none. The future is canceled if sender is destroyed first.

template <typename T = void>QFuture<T> QtFuture::makeExceptionalFuture(std::exception_ptr exception)

Returns a finished and canceled future that carries exception.

See also makeReadyValueFuture().

template <typename T = void>QFuture<T> QtFuture::makeExceptionalFuture(const QException &exception)

This is an overloaded function.

Returns a finished and canceled future that carries a copy of exception.

template <typename Container>QFuture<typename std::decay_t<Container>::value_type> QtFuture::makeReadyRangeFuture(Container &&values)

Returns a finished future with the elements of values as its results.

See also makeReadyValueFuture().

template <typename T>QFuture<T> QtFuture::makeReadyRangeFuture(std::initializer_list<T> values)

This is an overloaded function.

Returns a finished future with the elements of values as its results.

template <typename T>QFuture<std::decay_t<T>> QtFuture::makeReadyValueFuture(T &&value)

Returns a finished future with value as its only result.

See also makeReadyVoidFuture() and makeReadyRangeFuture().

QFuture<void> QtFuture::makeReadyVoidFuture()

Returns a finished QFuture<void>.

See also makeReadyValueFuture().

template <typename... Futures>QFuture<std::tuple<std::decay_t<Futures>...>> QtFuture::whenAll(Futures &&...futures)

Returns a future that finishes when all futures have finished. Its result is a tuple of them. A future takes one continuation, so the futures must not have one, and must not be given another afterwards.

See also whenAny().

template <typename InputIt, typename = typename std::iterator_traits<InputIt>::value_type>auto QtFuture::whenAll(InputIt first, InputIt last) -> QFuture<QList<typename std::iterator_traits<InputIt>::value_type>>

This is an overloaded function.

Returns a future that finishes when all the futures in the range from first to last have finished. Its result is a list of them.

template <typename... Futures>QFuture<std::variant<std::decay_t<Futures>...>> QtFuture::whenAny(Futures &&...futures)

Returns a future that finishes when the first of futures has finished. Its result is a std::variant that holds that future. A future takes one continuation, so the futures must not have one, and must not be given another afterwards.

See also whenAll().

template <typename InputIt, typename = typename std::iterator_traits<InputIt>::value_type>auto QtFuture::whenAny(InputIt first, InputIt last)

This is an overloaded function.

Returns a future that finishes when the first future in the range from first to last has finished. Its result is a WhenAnyResult. The range must not be empty.