YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
when_any.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
yaclib/async/when/any.hpp
>
4
#include <
yaclib/async/when/when.hpp
>
5
#include <yaclib/config.hpp>
6
#include <
yaclib/util/fail_policy.hpp
>
7
#include <
yaclib/util/type_traits.hpp
>
8
9
namespace
yaclib
{
10
11
template
<
FailPolicy
F =
FailPolicy::LastFail
,
typename
...
Futures
,
12
typename
= std::enable_if_t<(... &&
is_combinator_input_v<Futures>
)>>
13
YACLIB_INLINE
auto
WhenAny
(
Futures
...
futures
) {
14
when::CheckSameError
<
Futures
...>();
15
16
using
OutputValue =
typename
MaybeVariant
<
typename
Unique
<std::tuple<
typename
Futures::Core::Value...>>::Type>::Type;
17
using
OutputError
=
typename
head_t
<
Futures
...>::Core::Error;
18
19
return
when::When<when::Any, F, OutputValue, OutputError>(std::move(
futures
)...);
20
}
21
22
template <FailPolicy F = FailPolicy::LastFail, typename It, typename T = typename std::iterator_traits<It>::value_type
>
23
YACLIB_INLINE
auto
WhenAny
(
It
begin
, std::size_t count) {
24
if
constexpr
(
is_future_base_v<T>
) {
25
if
(count == 1) {
26
using
V =
async_value_t<T>
;
27
using
E
=
async_error_t<T>
;
28
return
Future<V, E>
{std::exchange(
begin
->GetCore(),
nullptr
)};
29
}
30
}
31
32
return
when::When<when::Any, F, typename T::Core::Value, typename T::Core::Error>(
begin
, count);
33
}
34
35
template <FailPolicy F = FailPolicy::LastFail, typename It, typename T = typename std::iterator_traits<It>::value_type
>
36
YACLIB_INLINE
auto
WhenAny
(
It
begin
,
It
end
) {
37
// We don't use std::distance because we want to alert the user to the fact that it can be expensive.
38
// Maybe the user has the size of the range, otherwise it is suggested to call WhenAny(begin, distance(begin, end))
39
return
WhenAny<F>
(
begin
,
static_cast<
std::size_t
>
(
end
-
begin
));
40
}
41
42
}
// namespace yaclib
any.hpp
yaclib::Future
Provides a mechanism to access the result of async operations.
Definition
future.hpp:211
fail_policy.hpp
yaclib::when::CheckSameError
YACLIB_INLINE void CheckSameError()
Definition
when.hpp:20
yaclib
Definition
base_core.hpp:15
yaclib::async_error_t
typename detail::AsyncTypes< T >::Error async_error_t
Definition
type_traits.hpp:73
yaclib::head_t
typename detail::Head< Args... >::Type head_t
Definition
type_traits.hpp:18
yaclib::async_value_t
typename detail::AsyncTypes< T >::Value async_value_t
Definition
type_traits.hpp:70
yaclib::FailPolicy
FailPolicy
This Policy describe how algorithm interpret if Future will be fulfilled by fail (exception or error)
Definition
fail_policy.hpp:12
yaclib::FailPolicy::LastFail
@ LastFail
yaclib::MakeContract
Contract< V, E > MakeContract()
Creates related future and promise.
Definition
contract.hpp:25
yaclib::WhenAny
YACLIB_INLINE auto WhenAny(Futures... futures)
Definition
when_any.hpp:13
yaclib::MaybeVariant
Definition
type_traits.hpp:162
yaclib::Unique
Definition
type_traits.hpp:132
type_traits.hpp
when.hpp
include
yaclib
async
when_any.hpp
Generated by
1.9.8