-
Notifications
You must be signed in to change notification settings - Fork 3
/
error_code.hh
53 lines (42 loc) · 1.22 KB
/
error_code.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2022 Mikael Simonsson <https://mikaelsimonsson.com>.
// SPDX-License-Identifier: BSL-1.0
// # Format `error_code`
#pragma once
#include "snn-core/error_code.hh"
#include "snn-core/formatter.hh"
#include "snn-core/strcore.hh"
#include "snn-core/fmt/context.hh"
namespace snn::fmt
{
// ## Functions
// ### error_code
template <typename Buf>
constexpr void error_code(const snn::error_code ec, strcore<Buf>& append_to)
{
append_to << ec.category().name<cstrview>() << ": " << ec.message<cstrview>() << " ("
<< as_num(ec.value()) << ")";
}
template <any_strcore Str = str>
[[nodiscard]] constexpr Str error_code(const snn::error_code ec)
{
Str append_to;
fmt::error_code(ec, append_to);
return append_to;
}
}
namespace snn
{
// ## Specializations
// ### formatter<error_code>
template <>
struct formatter<error_code>
{
using type = error_code;
template <typename Buf>
constexpr void format(const error_code ec, cstrview, const fmt::context&,
strcore<Buf>& append_to, promise::no_overlap_t)
{
fmt::error_code(ec, append_to);
}
};
}