cesium-native 0.43.0
Loading...
Searching...
No Matches
unwrapFuture.h
1#pragma once
2
3#include "ContinuationFutureType.h"
4#include "ContinuationReturnType.h"
5
6namespace CesiumAsync {
7namespace CesiumImpl {
8// Begin omitting doxgen warnings for Impl namespace
10
11struct IdentityUnwrapper {
12 template <typename Func> static Func unwrap(Func&& f) {
13 return std::forward<Func>(f);
14 }
15
16 template <typename Func> static Func unwrapShared(Func&& f) {
17 return std::forward<Func>(f);
18 }
19};
20
21template <typename T> struct ParameterizedTaskUnwrapper {
22 template <typename Func> static auto unwrap(Func&& f) {
23 return [f = std::forward<Func>(f)](T&& t) mutable {
24 return f(std::move(t))._task;
25 };
26 }
27
28 template <typename Func> static auto unwrapShared(Func&& f) {
29 return
30 [f = std::forward<Func>(f)](const T& t) mutable { return f(t)._task; };
31 }
32};
33
34struct TaskUnwrapper {
35 template <typename Func> static auto unwrap(Func&& f) {
36 return [f = std::forward<Func>(f)]() mutable { return f()._task; };
37 }
38};
39
40template <typename Func, typename T> auto unwrapFuture(Func&& f) {
41 return std::conditional<
42 std::is_same<
43 typename ContinuationReturnType<Func, T>::type,
44 typename RemoveFuture<
45 typename ContinuationFutureType<Func, T>::type>::type>::value,
46 IdentityUnwrapper,
47 ParameterizedTaskUnwrapper<T>>::type::unwrap(std::forward<Func>(f));
48}
49
50template <typename Func, typename T> auto unwrapSharedFuture(Func&& f) {
51 return std::conditional<
52 std::is_same<
53 typename ContinuationReturnType<Func, T>::type,
54 typename RemoveFuture<
55 typename ContinuationFutureType<Func, T>::type>::type>::value,
56 IdentityUnwrapper,
57 ParameterizedTaskUnwrapper<T>>::type::unwrapShared(std::forward<Func>(f));
58}
59
60template <typename Func> auto unwrapFuture(Func&& f) {
61 return std::conditional<
62 std::is_same<
63 typename ContinuationReturnType<Func, void>::type,
64 typename RemoveFuture<
65 typename ContinuationFutureType<Func, void>::type>::type>::value,
66 IdentityUnwrapper,
67 TaskUnwrapper>::type::unwrap(std::forward<Func>(f));
68}
69
70template <typename Func> auto unwrapSharedFuture(Func&& f) {
71 return unwrapFuture(std::forward<Func>(f));
72}
73
75// End omitting doxgen warnings for Impl namespace
76} // namespace CesiumImpl
77} // namespace CesiumAsync
Classes that support asynchronous operations.