YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
make.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
yaclib/algo/detail/result_core.hpp
>
4
#include <
yaclib/async/future.hpp
>
5
#include <
yaclib/fwd.hpp
>
6
#include <
yaclib/util/helper.hpp
>
7
#include <
yaclib/util/result.hpp
>
8
#include <
yaclib/util/type_traits.hpp
>
9
10
#include <type_traits>
11
#include <utility>
12
13
namespace
yaclib
{
14
15
/**
16
* Function for create Ready Future
17
*
18
* \tparam V if not default value, it's type of Future value
19
* \tparam E type of Future error, by default its
20
* \tparam Args if single, and V default, then used as type of Future value
21
* \param args for fulfill Future
22
* \return Ready Future
23
*/
24
template
<
typename
V =
Unit
,
typename
E
= StopError,
typename
...
Args
>
25
/*Future*/
auto
MakeFuture
(
Args
&&...
args
) {
26
if
constexpr
(
sizeof
...(Args) == 0) {
27
using
T = std::conditional_t<std::is_same_v<V, Unit>,
void
, V>;
28
return
Future
{
detail::ResultCorePtr<T, E>
{
MakeUnique<detail::ResultCore<T, E>
>(std::in_place)}};
29
}
else
if
constexpr
(std::is_same_v<V, Unit>) {
30
using
T0
= std::decay_t<
head_t
<
Args
&&...>>;
31
using
T = std::conditional_t<std::is_same_v<T0, Unit>,
void
,
T0
>;
32
return
Future
{
33
detail::ResultCorePtr<T, E>
{
MakeUnique<detail::ResultCore<T, E>
>(std::in_place, std::forward<Args>(
args
)...)}};
34
}
else
{
35
return
Future
{
detail::ResultCorePtr<V, E>
{
MakeUnique<detail::ResultCore<V, E>
>(std::forward<Args>(
args
)...)}};
36
}
37
}
38
39
}
// namespace yaclib
future.hpp
yaclib::Future
Provides a mechanism to access the result of async operations.
Definition
future.hpp:199
yaclib::IntrusivePtr
A intrusive pointer to objects with an embedded reference count.
Definition
intrusive_ptr.hpp:17
fwd.hpp
helper.hpp
yaclib
Definition
base_core.hpp:18
yaclib::head_t
typename detail::Head< Args... >::Type head_t
Definition
type_traits.hpp:13
yaclib::MakeFuture
auto MakeFuture(Args &&... args)
Function for create Ready Future.
Definition
make.hpp:25
yaclib::MakeContract
Contract< V, E > MakeContract()
Creates related future and promise.
Definition
contract.hpp:25
result.hpp
result_core.hpp
type_traits.hpp
include
yaclib
async
make.hpp
Generated by
1.9.8