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 T trait of the Future, by default \ref DefaultTrait
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 T = DefaultTrait, typename... Args>
25/*Future*/ auto MakeFuture(Args&&... args) {
26 if constexpr (sizeof...(Args) == 0) {
27 using Value = std::conditional_t<std::is_same_v<V, Unit>, void, V>;
29 } else if constexpr (std::is_same_v<V, Unit>) {
30 using Head = std::decay_t<head_t<Args&&...>>;
31 using Value = std::conditional_t<std::is_same_v<Head, Unit>, void, Head>;
33 MakeUnique<detail::UniqueCore<Value, T>>(std::in_place, std::forward<Args>(args)...)}};
34 } else {
35 return Future{
36 detail::UniqueCorePtr<V, T>{MakeUnique<detail::UniqueCore<V, T>>(std::in_place, std::forward<Args>(args)...)}};
37 }
38}
39
40} // namespace yaclib
Provides a mechanism to access the result of async operations.
Definition future.hpp:213
A intrusive pointer to objects with an embedded reference count.
Contract< V, T > MakeContract()
Creates related future and promise.
Definition contract.hpp:25
typename detail::Head< Args... >::Type head_t
auto MakeFuture(Args &&... args)
Function for create Ready Future.
Definition make.hpp:25