errors
0.6.3
Loading...
Searching...
No Matches
include
errors
utils.hpp
1
#pragma once
2
3
#include "errors/error.hpp"
4
#include "errors/error_ptr.hpp"
5
6
namespace
errors
7
{
8
9
template
<
typename
E>
10
[[nodiscard]]
11
bool
is(
const
error &err)
noexcept
12
{
13
auto
current = &err;
14
while
(current !=
nullptr
) {
15
if
(
dynamic_cast<
const
E *
>
(current) !=
nullptr
) {
16
return
true
;
17
}
18
19
current = current->cause().get();
20
}
21
return
false
;
22
}
23
24
template
<
typename
E>
25
[[nodiscard]]
26
const
E *as(
const
error &err)
noexcept
27
{
28
auto
current = &err;
29
while
(current !=
nullptr
) {
30
auto
result =
dynamic_cast<
const
E *
>
(current);
31
if
(result !=
nullptr
) {
32
return
result;
33
}
34
35
current = current->cause().get();
36
}
37
return
nullptr
;
38
}
39
40
}
Generated by
1.12.0