ThreadSchedule
3.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
try_result.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include "../result.hpp"
4
5
#include <exception>
6
#include <new>
7
#include <system_error>
8
#include <utility>
9
10
namespace
threadschedule::detail
11
{
12
13
[[nodiscard]]
inline
auto
14
current_exception_error_code
() noexcept ->
std
::error_code
15
{
16
try
17
{
18
throw
;
19
}
20
catch
(std::system_error
const
& error)
21
{
22
return
error.code();
23
}
24
catch
(std::bad_alloc
const
&)
25
{
26
return
std::make_error_code(std::errc::not_enough_memory);
27
}
28
catch
(...)
29
{
30
return
std::make_error_code(std::errc::state_not_recoverable);
31
}
32
}
33
34
template
<
typename
Function>
35
[[nodiscard]]
auto
36
try_result
(Function&& function) ->
decltype
(std::forward<Function>(function)())
37
{
38
try
39
{
40
return
std::forward<Function>(function)();
41
}
42
catch
(...)
43
{
44
return
unexpected
(
current_exception_error_code
());
45
}
46
}
47
48
}
// namespace threadschedule::detail
threadschedule::unexpected
Definition
expected.hpp:94
std
Definition
thread_id.hpp:101
threadschedule::detail
Aggregates multiple thread_registry_backend instances into a single queryable view.
Definition
native_thread.hpp:20
threadschedule::detail::current_exception_error_code
auto current_exception_error_code() noexcept -> std::error_code
Definition
try_result.hpp:14
threadschedule::detail::try_result
auto try_result(Function &&function) -> decltype(std::forward< Function >(function)())
Definition
try_result.hpp:36
include
threadschedule
detail
try_result.hpp
Generated by
1.9.8