Portable concurrency  0.11.0
Classes | Functions | Variables
<portable_concurrency/future>

future API imlementation with continuations and executors support More...

Classes

class  future< T >
 The class template future provides a mechanism to access the result of asynchronous operations. More...
 
class  promise< T >
 The class template promise is a simpliest write end of a future. More...
 
class  shared_future< T >
 The class template shared_future provides a mechanism to access the result of asynchronous operations. More...
 
struct  when_any_result< Sequence >
 

Functions

template<typename E , typename F , typename... A>
future< std::result_of_t< F(A...)> > async (E &&exec, F &&func, A &&... a)
 Executor aware analog of the std::async. More...
 
template<typename... Futures>
future< std::tuple< Futures... > > when_all (Futures &&...)
 
template<typename InputIt >
future< std::vector< typename std::iterator_traits< InputIt >::value_type > > when_all (InputIt first, InputIt last)
 
template<typename Future , typename Alloc >
future< std::vector< Future, Alloc > > when_all (std::vector< Future, Alloc > futures)
 
template<typename... Futures>
future< when_any_result< std::tuple< Futures... > > > when_any (Futures &&...)
 
template<typename InputIt >
future< when_any_result< std::vector< typename std::iterator_traits< InputIt >::value_type > > > when_any (InputIt first, InputIt last)
 
template<typename Future , typename Alloc >
future< when_any_result< std::vector< Future, Alloc > > > when_any (std::vector< Future, Alloc > futures)
 

Variables

constexpr future_get_t future_get {}
 Unary operation which takes a future and returns value stored inside it. More...
 
constexpr future_ready_t future_ready {}
 Unary predicate which takes a future and returns if this future is ready. More...
 

Detailed Description

future API imlementation with continuations and executors support

Function Documentation

◆ async()

future<std::result_of_t<F(A...)> > portable_concurrency::cxx14_v1::async ( E &&  exec,
F &&  func,
A &&...  a 
)

Executor aware analog of the std::async.

Runs the function func with arguments a asynchronyously using executor exec and returns a future that will eventually hold the result of that function call. The func and a parameters are decay-copied before sending to executor.

If std::result_of_t<F(A...)> is either future<T> or shared_future<T> then unwrapped future<T> or shared_future<T> is returned.

The function participates in overload resolution only if is_executor<E>::value is true.

◆ when_all() [1/3]

future<std::tuple<Futures...> > portable_concurrency::cxx14_v1::when_all ( Futures &&  ...)

Create a future object that becomes ready when all of the input futures and shared_futures become ready. The behavior is undefined if any input future or shared_future is invalid. Ready future<std::tuple<>> immediatelly returned if input futures is empty.

This function template participates in overload resolution only if all of the arguments are either future<T> or shared_future<T>.

◆ when_all() [2/3]

future<std::vector<typename std::iterator_traits<InputIt>::value_type> > portable_concurrency::cxx14_v1::when_all ( InputIt  first,
InputIt  last 
)

Create a future object that becomes ready when all of the input futures and shared_futures become ready. The behavior is undefined if any input future or shared_future is invalid. Ready future<std::tuple<>> immediatelly returned if input futures is empty range (first == last). Every input future<T> object is moved into corresponding object of the returned future shared state, and every shared_future<T> object is copied. The order of the objects in the returned future object matches the order of arguments.

This function template participates in overload resolution only if value type of the InputIt is either future<T> or shared_future<T>.

◆ when_all() [3/3]

future<std::vector<Future, Alloc> > portable_concurrency::cxx14_v1::when_all ( std::vector< Future, Alloc >  futures)

Create a future object that becomes ready when all of the input futures and shared_futures become ready. The behavior is undefined if any input future or shared_future is invalid. Effectively equivalent to when_all(futures.begin(), futures.end()) but this overload reuses vector passed as argument instead of making new one saving one extra allocation, and supports vectors with user provided allocators.

This function template participates in overload resolution only if Future is either future<T> or shared_future<T>.

◆ when_any() [1/3]

future<when_any_result<std::tuple<Futures...> > > portable_concurrency::cxx14_v1::when_any ( Futures &&  ...)

Create a future object that becomes ready when at least one of the input futures and shared_futures become ready. The behavior is undefined if any input future or shared_future is invalid. Ready future<when_any_result<std::tuple<>>> immediatelly returned if input futures is empty and the index field is size_t(-1).

The returned future is always valid(), and it becomes ready when at least one of the input futures and shared_futures the call are ready. The index member of the when_any_result contains the position of the ready future or shared_future in the futures member.

This function template participates in overload resolution only if all of the arguments are either future<T> or shared_future<T>.

◆ when_any() [2/3]

future<when_any_result<std::vector<typename std::iterator_traits<InputIt>::value_type> > > portable_concurrency::cxx14_v1::when_any ( InputIt  first,
InputIt  last 
)

Create a future object that becomes ready when at least one of the input futures and shared_futures become ready. The behavior is undefined if any input future or shared_future is invalid. Ready future immediatelly returned if input futures is empty range (first == last) and the index field is size_t(-1). Every input future<T> object is moved into corresponding object of the returned future shared state, and every shared_future<T> object is copied. The order of the objects in the returned future object matches the order of arguments.

The returned future is always valid(), and it becomes ready when at least one of the input futures and shared_futures the call are ready. The index member of the when_any_result contains the position of the ready future or shared_future in the futures member.

This function template participates in overload resolution only if value type of the InputIt is either future<T> or shared_future<T>.

◆ when_any() [3/3]

future<when_any_result<std::vector<Future, Alloc> > > portable_concurrency::cxx14_v1::when_any ( std::vector< Future, Alloc >  futures)

Create a future object that becomes ready when at least one of the input futures and shared_futures become ready. The behavior is undefined if any input future or shared_future is invalid. Effectively equivalent to when_any(futures.begin(), futures.end()) but this overload reuses vector passed as argument instead of making new one saving one extra allocation, and supports vectors with user provided allocators.

This function template participates in overload resolution only if Future is either future<T> or shared_future<T>.

Variable Documentation

◆ future_get

constexpr future_get_t future_get {}
constexpr

Unary operation which takes a future and returns value stored inside it.

The main use case for this function object is to transform collection of futures into collection of values. For example:

auto tasks = run_many_tasks();
pc::future<std::vector<int>> = pc::when_all(tasks.begin(), tasks.end())
.next([](std::vector<pc::future<int>> futures){
std::vector<int> results;
results.reserve(futuers.size());
std::transform(futures.begin(), futures.end(), std::back_inserter(results), pc::future_get);
return results;
})

◆ future_ready

constexpr future_ready_t future_ready {}
constexpr

Unary predicate which takes a future and returns if this future is ready.

This predocate can be used with variaty of std algorithms including:

  • std::partition family
  • std::all_of, std::any_of, std::none_of
  • std::find_if
  • std::count_if
portable_concurrency::cxx14_v1::when_all
future< std::tuple< Futures... > > when_all(Futures &&...)
portable_concurrency::cxx14_v1::future
The class template future provides a mechanism to access the result of asynchronous operations.
Definition: future.h:25
portable_concurrency::cxx14_v1::future_get
constexpr future_get_t future_get
Unary operation which takes a future and returns value stored inside it.
Definition: algo_adapters.h:39