YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
make.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <yaclib/fwd.hpp>
9
10#include <type_traits>
11#include <utility>
12
13namespace 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 */
24template <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>;
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 {
36 }
37}
38
39} // namespace yaclib
Provides a mechanism to access the result of async operations.
Definition future.hpp:199
A intrusive pointer to objects with an embedded reference count.
typename detail::Head< Args... >::Type head_t
auto MakeFuture(Args &&... args)
Function for create Ready Future.
Definition make.hpp:25
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25