| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
1 |
// Formatting library for C++ - formatters for standard library types |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
2 |
// |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
3 |
// Copyright (c) 2012 - present, Victor Zverovich |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
4 |
// All rights reserved. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
5 |
// |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
6 |
// For the license information refer to format.h. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
7 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
8 |
#ifndef FMT_STD_H_ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
9 |
#define FMT_STD_H_ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
10 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
11 |
#include "format.h" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
12 |
#include "ostream.h" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
13 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
14 |
#ifndef FMT_MODULE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
15 |
# include <atomic> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
16 |
# include <bitset> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
17 |
# include <complex> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
18 |
# include <cstdlib> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
19 |
# include <exception> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
20 |
# include <memory> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
21 |
# include <thread> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
22 |
# include <type_traits> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
23 |
# include <typeinfo> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
24 |
# include <utility> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
25 |
# include <vector> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
26 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
27 |
// Check FMT_CPLUSPLUS to suppress a bogus warning in MSVC. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
28 |
# if FMT_CPLUSPLUS >= 201703L |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
29 |
# if FMT_HAS_INCLUDE(<filesystem>) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
30 |
# include <filesystem> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
31 |
# endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
32 |
# if FMT_HAS_INCLUDE(<variant>) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
33 |
# include <variant> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
34 |
# endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
35 |
# if FMT_HAS_INCLUDE(<optional>) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
36 |
# include <optional> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
37 |
# endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
38 |
# endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
39 |
// Use > instead of >= in the version check because <source_location> may be |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
40 |
// available after C++17 but before C++20 is marked as implemented. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
41 |
# if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE(<source_location>) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
42 |
# include <source_location> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
43 |
# endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
44 |
# if FMT_CPLUSPLUS > 202002L && FMT_HAS_INCLUDE(<expected>) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
45 |
# include <expected> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
46 |
# endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
47 |
#endif // FMT_MODULE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
48 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
49 |
#if FMT_HAS_INCLUDE(<version>) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
50 |
# include <version> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
51 |
#endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
52 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
53 |
// GCC 4 does not support FMT_HAS_INCLUDE. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
54 |
#if FMT_HAS_INCLUDE(<cxxabi.h>) || defined(__GLIBCXX__) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
55 |
# include <cxxabi.h> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
56 |
// Android NDK with gabi++ library on some architectures does not implement |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
57 |
// abi::__cxa_demangle(). |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
58 |
# ifndef __GABIXX_CXXABI_H__ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
59 |
# define FMT_HAS_ABI_CXA_DEMANGLE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
60 |
# endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
61 |
#endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
62 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
63 |
// For older Xcode versions, __cpp_lib_xxx flags are inaccurately defined. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
64 |
#ifndef FMT_CPP_LIB_FILESYSTEM |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
65 |
# ifdef __cpp_lib_filesystem |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
66 |
# define FMT_CPP_LIB_FILESYSTEM __cpp_lib_filesystem |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
67 |
# else |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
68 |
# define FMT_CPP_LIB_FILESYSTEM 0 |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
69 |
# endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
70 |
#endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
71 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
72 |
#ifndef FMT_CPP_LIB_VARIANT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
73 |
# ifdef __cpp_lib_variant |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
74 |
# define FMT_CPP_LIB_VARIANT __cpp_lib_variant |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
75 |
# else |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
76 |
# define FMT_CPP_LIB_VARIANT 0 |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
77 |
# endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
78 |
#endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
79 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
80 |
#if FMT_CPP_LIB_FILESYSTEM |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
81 |
FMT_BEGIN_NAMESPACE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
82 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
83 |
namespace detail { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
84 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
85 |
template <typename Char, typename PathChar> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
86 |
auto get_path_string(const std::filesystem::path& p, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
87 |
const std::basic_string<PathChar>& native) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
88 |
if constexpr (std::is_same_v<Char, char> && std::is_same_v<PathChar, wchar_t>) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
89 |
return to_utf8<wchar_t>(native, to_utf8_error_policy::replace); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
90 |
else |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
91 |
return p.string<Char>(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
92 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
93 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
94 |
template <typename Char, typename PathChar> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
95 |
void write_escaped_path(basic_memory_buffer<Char>& quoted, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
96 |
const std::filesystem::path& p, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
97 |
const std::basic_string<PathChar>& native) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
98 |
if constexpr (std::is_same_v<Char, char> && |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
99 |
std::is_same_v<PathChar, wchar_t>) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
100 |
auto buf = basic_memory_buffer<wchar_t>(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
101 |
write_escaped_string<wchar_t>(std::back_inserter(buf), native); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
102 |
bool valid = to_utf8<wchar_t>::convert(quoted, {buf.data(), buf.size()}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
103 |
FMT_ASSERT(valid, "invalid utf16"); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
104 |
} else if constexpr (std::is_same_v<Char, PathChar>) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
105 |
write_escaped_string<std::filesystem::path::value_type>( |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
106 |
std::back_inserter(quoted), native); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
107 |
} else { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
108 |
write_escaped_string<Char>(std::back_inserter(quoted), p.string<Char>()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
109 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
110 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
111 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
112 |
} // namespace detail |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
113 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
114 |
FMT_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
115 |
template <typename Char> struct formatter<std::filesystem::path, Char> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
116 |
private: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
117 |
format_specs specs_; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
118 |
detail::arg_ref<Char> width_ref_; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
119 |
bool debug_ = false; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
120 |
char path_type_ = 0; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
121 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
122 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
123 |
FMT_CONSTEXPR void set_debug_format(bool set = true) { debug_ = set; } |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
124 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
125 |
template <typename ParseContext> FMT_CONSTEXPR auto parse(ParseContext& ctx) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
126 |
auto it = ctx.begin(), end = ctx.end(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
127 |
if (it == end) return it; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
128 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
129 |
it = detail::parse_align(it, end, specs_); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
130 |
if (it == end) return it; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
131 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
132 |
it = detail::parse_dynamic_spec(it, end, specs_.width, width_ref_, ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
133 |
if (it != end && *it == '?') { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
134 |
debug_ = true; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
135 |
++it; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
136 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
137 |
if (it != end && (*it == 'g')) path_type_ = detail::to_ascii(*it++); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
138 |
return it; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
139 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
140 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
141 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
142 |
auto format(const std::filesystem::path& p, FormatContext& ctx) const { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
143 |
auto specs = specs_; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
144 |
auto path_string = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
145 |
!path_type_ ? p.native() |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
146 |
: p.generic_string<std::filesystem::path::value_type>(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
147 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
148 |
detail::handle_dynamic_spec<detail::width_checker>(specs.width, width_ref_, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
149 |
ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
150 |
if (!debug_) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
151 |
auto s = detail::get_path_string<Char>(p, path_string); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
152 |
return detail::write(ctx.out(), basic_string_view<Char>(s), specs); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
153 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
154 |
auto quoted = basic_memory_buffer<Char>(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
155 |
detail::write_escaped_path(quoted, p, path_string); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
156 |
return detail::write(ctx.out(), |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
157 |
basic_string_view<Char>(quoted.data(), quoted.size()), |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
158 |
specs); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
159 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
160 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
161 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
162 |
class path : public std::filesystem::path { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
163 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
164 |
auto display_string() const -> std::string { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
165 |
const std::filesystem::path& base = *this; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
166 |
return fmt::format(FMT_STRING("{}"), base); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
167 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
168 |
auto system_string() const -> std::string { return string(); } |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
169 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
170 |
auto generic_display_string() const -> std::string { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
171 |
const std::filesystem::path& base = *this; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
172 |
return fmt::format(FMT_STRING("{:g}"), base); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
173 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
174 |
auto generic_system_string() const -> std::string { return generic_string(); } |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
175 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
176 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
177 |
FMT_END_NAMESPACE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
178 |
#endif // FMT_CPP_LIB_FILESYSTEM |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
179 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
180 |
FMT_BEGIN_NAMESPACE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
181 |
FMT_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
182 |
template <std::size_t N, typename Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
183 |
struct formatter<std::bitset<N>, Char> : nested_formatter<string_view> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
184 |
private: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
185 |
// Functor because C++11 doesn't support generic lambdas. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
186 |
struct writer { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
187 |
const std::bitset<N>& bs; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
188 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
189 |
template <typename OutputIt> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
190 |
FMT_CONSTEXPR auto operator()(OutputIt out) -> OutputIt { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
191 |
for (auto pos = N; pos > 0; --pos) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
192 |
out = detail::write<Char>(out, bs[pos - 1] ? Char('1') : Char('0')); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
193 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
194 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
195 |
return out; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
196 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
197 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
198 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
199 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
200 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
201 |
auto format(const std::bitset<N>& bs, FormatContext& ctx) const |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
202 |
-> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
203 |
return write_padded(ctx, writer{bs}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
204 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
205 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
206 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
207 |
FMT_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
208 |
template <typename Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
209 |
struct formatter<std::thread::id, Char> : basic_ostream_formatter<Char> {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
210 |
FMT_END_NAMESPACE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
211 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
212 |
#ifdef __cpp_lib_optional |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
213 |
FMT_BEGIN_NAMESPACE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
214 |
FMT_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
215 |
template <typename T, typename Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
216 |
struct formatter<std::optional<T>, Char, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
217 |
std::enable_if_t<is_formattable<T, Char>::value>> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
218 |
private: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
219 |
formatter<T, Char> underlying_; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
220 |
static constexpr basic_string_view<Char> optional = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
221 |
detail::string_literal<Char, 'o', 'p', 't', 'i', 'o', 'n', 'a', 'l', |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
222 |
'('>{}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
223 |
static constexpr basic_string_view<Char> none = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
224 |
detail::string_literal<Char, 'n', 'o', 'n', 'e'>{}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
225 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
226 |
template <class U> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
227 |
FMT_CONSTEXPR static auto maybe_set_debug_format(U& u, bool set) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
228 |
-> decltype(u.set_debug_format(set)) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
229 |
u.set_debug_format(set); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
230 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
231 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
232 |
template <class U> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
233 |
FMT_CONSTEXPR static void maybe_set_debug_format(U&, ...) {} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
234 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
235 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
236 |
template <typename ParseContext> FMT_CONSTEXPR auto parse(ParseContext& ctx) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
237 |
maybe_set_debug_format(underlying_, true); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
238 |
return underlying_.parse(ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
239 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
240 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
241 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
242 |
auto format(const std::optional<T>& opt, FormatContext& ctx) const |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
243 |
-> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
244 |
if (!opt) return detail::write<Char>(ctx.out(), none); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
245 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
246 |
auto out = ctx.out(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
247 |
out = detail::write<Char>(out, optional); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
248 |
ctx.advance_to(out); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
249 |
out = underlying_.format(*opt, ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
250 |
return detail::write(out, ')'); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
251 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
252 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
253 |
FMT_END_NAMESPACE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
254 |
#endif // __cpp_lib_optional |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
255 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
256 |
#if defined(__cpp_lib_expected) || FMT_CPP_LIB_VARIANT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
257 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
258 |
FMT_BEGIN_NAMESPACE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
259 |
namespace detail { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
260 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
261 |
template <typename Char, typename OutputIt, typename T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
262 |
auto write_escaped_alternative(OutputIt out, const T& v) -> OutputIt { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
263 |
if constexpr (has_to_string_view<T>::value) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
264 |
return write_escaped_string<Char>(out, detail::to_string_view(v)); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
265 |
if constexpr (std::is_same_v<T, Char>) return write_escaped_char(out, v); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
266 |
return write<Char>(out, v); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
267 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
268 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
269 |
} // namespace detail |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
270 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
271 |
FMT_END_NAMESPACE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
272 |
#endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
273 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
274 |
#ifdef __cpp_lib_expected |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
275 |
FMT_BEGIN_NAMESPACE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
276 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
277 |
FMT_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
278 |
template <typename T, typename E, typename Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
279 |
struct formatter<std::expected<T, E>, Char, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
280 |
std::enable_if_t<is_formattable<T, Char>::value && |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
281 |
is_formattable<E, Char>::value>> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
282 |
template <typename ParseContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
283 |
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
284 |
return ctx.begin(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
285 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
286 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
287 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
288 |
auto format(const std::expected<T, E>& value, FormatContext& ctx) const |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
289 |
-> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
290 |
auto out = ctx.out(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
291 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
292 |
if (value.has_value()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
293 |
out = detail::write<Char>(out, "expected("); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
294 |
out = detail::write_escaped_alternative<Char>(out, *value); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
295 |
} else { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
296 |
out = detail::write<Char>(out, "unexpected("); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
297 |
out = detail::write_escaped_alternative<Char>(out, value.error()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
298 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
299 |
*out++ = ')'; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
300 |
return out; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
301 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
302 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
303 |
FMT_END_NAMESPACE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
304 |
#endif // __cpp_lib_expected |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
305 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
306 |
#ifdef __cpp_lib_source_location |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
307 |
FMT_BEGIN_NAMESPACE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
308 |
FMT_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
309 |
template <> struct formatter<std::source_location> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
310 |
template <typename ParseContext> FMT_CONSTEXPR auto parse(ParseContext& ctx) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
311 |
return ctx.begin(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
312 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
313 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
314 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
315 |
auto format(const std::source_location& loc, FormatContext& ctx) const |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
316 |
-> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
317 |
auto out = ctx.out(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
318 |
out = detail::write(out, loc.file_name()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
319 |
out = detail::write(out, ':'); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
320 |
out = detail::write<char>(out, loc.line()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
321 |
out = detail::write(out, ':'); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
322 |
out = detail::write<char>(out, loc.column()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
323 |
out = detail::write(out, ": "); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
324 |
out = detail::write(out, loc.function_name()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
325 |
return out; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
326 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
327 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
328 |
FMT_END_NAMESPACE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
329 |
#endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
330 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
331 |
#if FMT_CPP_LIB_VARIANT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
332 |
FMT_BEGIN_NAMESPACE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
333 |
namespace detail { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
334 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
335 |
template <typename T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
336 |
using variant_index_sequence = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
337 |
std::make_index_sequence<std::variant_size<T>::value>; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
338 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
339 |
template <typename> struct is_variant_like_ : std::false_type {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
340 |
template <typename... Types> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
341 |
struct is_variant_like_<std::variant<Types...>> : std::true_type {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
342 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
343 |
// formattable element check. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
344 |
template <typename T, typename C> class is_variant_formattable_ { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
345 |
template <std::size_t... Is> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
346 |
static std::conjunction< |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
347 |
is_formattable<std::variant_alternative_t<Is, T>, C>...> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
348 |
check(std::index_sequence<Is...>); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
349 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
350 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
351 |
static constexpr const bool value = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
352 |
decltype(check(variant_index_sequence<T>{}))::value; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
353 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
354 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
355 |
} // namespace detail |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
356 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
357 |
template <typename T> struct is_variant_like { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
358 |
static constexpr const bool value = detail::is_variant_like_<T>::value; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
359 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
360 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
361 |
template <typename T, typename C> struct is_variant_formattable { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
362 |
static constexpr const bool value = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
363 |
detail::is_variant_formattable_<T, C>::value; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
364 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
365 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
366 |
FMT_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
367 |
template <typename Char> struct formatter<std::monostate, Char> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
368 |
template <typename ParseContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
369 |
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
370 |
return ctx.begin(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
371 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
372 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
373 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
374 |
auto format(const std::monostate&, FormatContext& ctx) const |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
375 |
-> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
376 |
return detail::write<Char>(ctx.out(), "monostate"); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
377 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
378 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
379 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
380 |
FMT_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
381 |
template <typename Variant, typename Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
382 |
struct formatter< |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
383 |
Variant, Char, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
384 |
std::enable_if_t<std::conjunction_v< |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
385 |
is_variant_like<Variant>, is_variant_formattable<Variant, Char>>>> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
386 |
template <typename ParseContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
387 |
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
388 |
return ctx.begin(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
389 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
390 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
391 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
392 |
auto format(const Variant& value, FormatContext& ctx) const |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
393 |
-> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
394 |
auto out = ctx.out(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
395 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
396 |
out = detail::write<Char>(out, "variant("); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
397 |
FMT_TRY { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
398 |
std::visit( |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
399 |
[&](const auto& v) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
400 |
out = detail::write_escaped_alternative<Char>(out, v); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
401 |
}, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
402 |
value); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
403 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
404 |
FMT_CATCH(const std::bad_variant_access&) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
405 |
detail::write<Char>(out, "valueless by exception"); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
406 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
407 |
*out++ = ')'; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
408 |
return out; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
409 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
410 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
411 |
FMT_END_NAMESPACE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
412 |
#endif // FMT_CPP_LIB_VARIANT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
413 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
414 |
FMT_BEGIN_NAMESPACE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
415 |
FMT_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
416 |
template <typename Char> struct formatter<std::error_code, Char> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
417 |
template <typename ParseContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
418 |
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
419 |
return ctx.begin(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
420 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
421 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
422 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
423 |
FMT_CONSTEXPR auto format(const std::error_code& ec, FormatContext& ctx) const |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
424 |
-> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
425 |
auto out = ctx.out(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
426 |
out = detail::write_bytes<Char>(out, ec.category().name(), format_specs()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
427 |
out = detail::write<Char>(out, Char(':')); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
428 |
out = detail::write<Char>(out, ec.value()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
429 |
return out; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
430 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
431 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
432 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
433 |
#if FMT_USE_RTTI |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
434 |
namespace detail { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
435 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
436 |
template <typename Char, typename OutputIt> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
437 |
auto write_demangled_name(OutputIt out, const std::type_info& ti) -> OutputIt { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
438 |
# ifdef FMT_HAS_ABI_CXA_DEMANGLE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
439 |
int status = 0; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
440 |
std::size_t size = 0; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
441 |
std::unique_ptr<char, void (*)(void*)> demangled_name_ptr( |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
442 |
abi::__cxa_demangle(ti.name(), nullptr, &size, &status), &std::free); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
443 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
444 |
string_view demangled_name_view; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
445 |
if (demangled_name_ptr) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
446 |
demangled_name_view = demangled_name_ptr.get(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
447 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
448 |
// Normalization of stdlib inline namespace names. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
449 |
// libc++ inline namespaces. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
450 |
// std::__1::* -> std::* |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
451 |
// std::__1::__fs::* -> std::* |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
452 |
// libstdc++ inline namespaces. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
453 |
// std::__cxx11::* -> std::* |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
454 |
// std::filesystem::__cxx11::* -> std::filesystem::* |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
455 |
if (demangled_name_view.starts_with("std::")) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
456 |
char* begin = demangled_name_ptr.get(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
457 |
char* to = begin + 5; // std:: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
458 |
for (char *from = to, *end = begin + demangled_name_view.size(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
459 |
from < end;) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
460 |
// This is safe, because demangled_name is NUL-terminated. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
461 |
if (from[0] == '_' && from[1] == '_') { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
462 |
char* next = from + 1; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
463 |
while (next < end && *next != ':') next++; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
464 |
if (next[0] == ':' && next[1] == ':') { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
465 |
from = next + 2; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
466 |
continue; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
467 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
468 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
469 |
*to++ = *from++; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
470 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
471 |
demangled_name_view = {begin, detail::to_unsigned(to - begin)}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
472 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
473 |
} else { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
474 |
demangled_name_view = string_view(ti.name()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
475 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
476 |
return detail::write_bytes<Char>(out, demangled_name_view); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
477 |
# elif FMT_MSC_VERSION |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
478 |
const string_view demangled_name(ti.name()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
479 |
for (std::size_t i = 0; i < demangled_name.size(); ++i) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
480 |
auto sub = demangled_name; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
481 |
sub.remove_prefix(i); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
482 |
if (sub.starts_with("enum ")) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
483 |
i += 4; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
484 |
continue; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
485 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
486 |
if (sub.starts_with("class ") || sub.starts_with("union ")) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
487 |
i += 5; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
488 |
continue; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
489 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
490 |
if (sub.starts_with("struct ")) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
491 |
i += 6; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
492 |
continue; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
493 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
494 |
if (*sub.begin() != ' ') *out++ = *sub.begin(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
495 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
496 |
return out; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
497 |
# else |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
498 |
return detail::write_bytes<Char>(out, string_view(ti.name())); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
499 |
# endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
500 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
501 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
502 |
} // namespace detail |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
503 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
504 |
FMT_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
505 |
template <typename Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
506 |
struct formatter<std::type_info, Char // DEPRECATED! Mixing code unit types. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
507 |
> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
508 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
509 |
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& ctx) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
510 |
-> decltype(ctx.begin()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
511 |
return ctx.begin(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
512 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
513 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
514 |
template <typename Context> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
515 |
auto format(const std::type_info& ti, Context& ctx) const |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
516 |
-> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
517 |
return detail::write_demangled_name<Char>(ctx.out(), ti); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
518 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
519 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
520 |
#endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
521 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
522 |
FMT_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
523 |
template <typename T, typename Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
524 |
struct formatter< |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
525 |
T, Char, // DEPRECATED! Mixing code unit types. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
526 |
typename std::enable_if<std::is_base_of<std::exception, T>::value>::type> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
527 |
private: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
528 |
bool with_typename_ = false; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
529 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
530 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
531 |
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& ctx) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
532 |
-> decltype(ctx.begin()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
533 |
auto it = ctx.begin(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
534 |
auto end = ctx.end(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
535 |
if (it == end || *it == '}') return it; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
536 |
if (*it == 't') { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
537 |
++it; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
538 |
with_typename_ = FMT_USE_RTTI != 0; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
539 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
540 |
return it; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
541 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
542 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
543 |
template <typename Context> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
544 |
auto format(const std::exception& ex, Context& ctx) const |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
545 |
-> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
546 |
auto out = ctx.out(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
547 |
#if FMT_USE_RTTI |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
548 |
if (with_typename_) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
549 |
out = detail::write_demangled_name<Char>(out, typeid(ex)); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
550 |
*out++ = ':'; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
551 |
*out++ = ' '; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
552 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
553 |
#endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
554 |
return detail::write_bytes<Char>(out, string_view(ex.what())); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
555 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
556 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
557 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
558 |
namespace detail { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
559 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
560 |
template <typename T, typename Enable = void> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
561 |
struct has_flip : std::false_type {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
562 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
563 |
template <typename T> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
564 |
struct has_flip<T, void_t<decltype(std::declval<T>().flip())>> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
565 |
: std::true_type {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
566 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
567 |
template <typename T> struct is_bit_reference_like { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
568 |
static constexpr const bool value = |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
569 |
std::is_convertible<T, bool>::value && |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
570 |
std::is_nothrow_assignable<T, bool>::value && has_flip<T>::value; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
571 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
572 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
573 |
#ifdef _LIBCPP_VERSION |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
574 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
575 |
// Workaround for libc++ incompatibility with C++ standard. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
576 |
// According to the Standard, `bitset::operator[] const` returns bool. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
577 |
template <typename C> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
578 |
struct is_bit_reference_like<std::__bit_const_reference<C>> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
579 |
static constexpr const bool value = true; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
580 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
581 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
582 |
#endif |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
583 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
584 |
} // namespace detail |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
585 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
586 |
// We can't use std::vector<bool, Allocator>::reference and |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
587 |
// std::bitset<N>::reference because the compiler can't deduce Allocator and N |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
588 |
// in partial specialization. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
589 |
FMT_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
590 |
template <typename BitRef, typename Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
591 |
struct formatter<BitRef, Char, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
592 |
enable_if_t<detail::is_bit_reference_like<BitRef>::value>> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
593 |
: formatter<bool, Char> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
594 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
595 |
FMT_CONSTEXPR auto format(const BitRef& v, FormatContext& ctx) const |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
596 |
-> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
597 |
return formatter<bool, Char>::format(v, ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
598 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
599 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
600 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
601 |
template <typename T, typename Deleter> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
602 |
auto ptr(const std::unique_ptr<T, Deleter>& p) -> const void* { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
603 |
return p.get(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
604 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
605 |
template <typename T> auto ptr(const std::shared_ptr<T>& p) -> const void* { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
606 |
return p.get(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
607 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
608 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
609 |
FMT_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
610 |
template <typename T, typename Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
611 |
struct formatter<std::atomic<T>, Char, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
612 |
enable_if_t<is_formattable<T, Char>::value>> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
613 |
: formatter<T, Char> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
614 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
615 |
auto format(const std::atomic<T>& v, FormatContext& ctx) const |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
616 |
-> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
617 |
return formatter<T, Char>::format(v.load(), ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
618 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
619 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
620 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
621 |
#ifdef __cpp_lib_atomic_flag_test |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
622 |
FMT_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
623 |
template <typename Char> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
624 |
struct formatter<std::atomic_flag, Char> : formatter<bool, Char> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
625 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
626 |
auto format(const std::atomic_flag& v, FormatContext& ctx) const |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
627 |
-> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
628 |
return formatter<bool, Char>::format(v.test(), ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
629 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
630 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
631 |
#endif // __cpp_lib_atomic_flag_test |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
632 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
633 |
FMT_EXPORT |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
634 |
template <typename T, typename Char> struct formatter<std::complex<T>, Char> { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
635 |
private: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
636 |
detail::dynamic_format_specs<Char> specs_; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
637 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
638 |
template <typename FormatContext, typename OutputIt> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
639 |
FMT_CONSTEXPR auto do_format(const std::complex<T>& c, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
640 |
detail::dynamic_format_specs<Char>& specs, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
641 |
FormatContext& ctx, OutputIt out) const |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
642 |
-> OutputIt { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
643 |
if (c.real() != 0) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
644 |
*out++ = Char('('); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
645 |
out = detail::write<Char>(out, c.real(), specs, ctx.locale()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
646 |
specs.sign = sign::plus; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
647 |
out = detail::write<Char>(out, c.imag(), specs, ctx.locale()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
648 |
if (!detail::isfinite(c.imag())) *out++ = Char(' '); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
649 |
*out++ = Char('i'); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
650 |
*out++ = Char(')'); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
651 |
return out; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
652 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
653 |
out = detail::write<Char>(out, c.imag(), specs, ctx.locale()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
654 |
if (!detail::isfinite(c.imag())) *out++ = Char(' '); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
655 |
*out++ = Char('i'); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
656 |
return out; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
657 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
658 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
659 |
public: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
660 |
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& ctx) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
661 |
-> decltype(ctx.begin()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
662 |
if (ctx.begin() == ctx.end() || *ctx.begin() == '}') return ctx.begin(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
663 |
return parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
664 |
detail::type_constant<T, Char>::value); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
665 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
666 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
667 |
template <typename FormatContext> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
668 |
auto format(const std::complex<T>& c, FormatContext& ctx) const |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
669 |
-> decltype(ctx.out()) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
670 |
auto specs = specs_; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
671 |
if (specs.width_ref.kind != detail::arg_id_kind::none || |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
672 |
specs.precision_ref.kind != detail::arg_id_kind::none) { |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
673 |
detail::handle_dynamic_spec<detail::width_checker>(specs.width, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
674 |
specs.width_ref, ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
675 |
detail::handle_dynamic_spec<detail::precision_checker>( |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
676 |
specs.precision, specs.precision_ref, ctx); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
677 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
678 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
679 |
if (specs.width == 0) return do_format(c, specs, ctx, ctx.out()); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
680 |
auto buf = basic_memory_buffer<Char>(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
681 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
682 |
auto outer_specs = format_specs(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
683 |
outer_specs.width = specs.width; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
684 |
outer_specs.fill = specs.fill; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
685 |
outer_specs.align = specs.align; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
686 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
687 |
specs.width = 0; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
688 |
specs.fill = {}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
689 |
specs.align = align::none; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
690 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
691 |
do_format(c, specs, ctx, basic_appender<Char>(buf)); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
692 |
return detail::write<Char>(ctx.out(), |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
693 |
basic_string_view<Char>(buf.data(), buf.size()), |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
694 |
outer_specs); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
695 |
} |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
696 |
}; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
697 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
698 |
FMT_END_NAMESPACE |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
699 |
#endif // FMT_STD_H_ |
|
|
1970-01-01 00:00 |
700 |
|