YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
safe_call.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <yaclib/config.hpp>
4
5#include <type_traits>
6#include <utility>
7
8namespace yaclib::detail {
9
10template <typename Func>
11class SafeCall {
12 public:
13 using Store = std::decay_t<Func>;
14 using Invoke = std::conditional_t<std::is_function_v<std::remove_reference_t<Func>>, Store, Func>;
15
16 explicit SafeCall(Store&& f) noexcept(std::is_nothrow_move_constructible_v<Store>) : _func{std::move(f)} {
17 }
18
19 explicit SafeCall(const Store& f) noexcept(std::is_nothrow_copy_constructible_v<Store>) : _func{f} {
20 }
21
22 protected:
23 void Call() noexcept {
24 if constexpr (std::is_nothrow_invocable_v<Invoke>) { // TODO(MBkkt) Is it really necessary?
25 std::forward<Invoke>(_func)();
26 } else {
27 try {
28 std::forward<Invoke>(_func)();
29 } catch (...) {
30 // TODO(MBkkt) Special macro for user callback function?
31 }
32 }
33 }
34
35 private:
37};
38
39} // namespace yaclib::detail
std::decay_t< Func > Store
Definition safe_call.hpp:13
SafeCall(const Store &f) noexcept(std::is_nothrow_copy_constructible_v< Store >)
Definition safe_call.hpp:19
void Call() noexcept
Definition safe_call.hpp:23
std::conditional_t< std::is_function_v< std::remove_reference_t< Func > >, Store, Func > Invoke
Definition safe_call.hpp:14
SafeCall(Store &&f) noexcept(std::is_nothrow_move_constructible_v< Store >)
Definition safe_call.hpp:16
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25