Coverage Report

Created: 2026-07-26 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fmt/include/fmt/base.h
Line
Count
Source
1
// Formatting library for C++ - the base API for char/UTF-8
2
//
3
// Copyright (c) 2012 - present, Victor Zverovich and {fmt} contributors
4
// All rights reserved.
5
//
6
// For the license information refer to format.h.
7
8
#ifndef FMT_BASE_H_
9
#define FMT_BASE_H_
10
11
#if defined(FMT_IMPORT_STD) && !defined(FMT_MODULE)
12
#  define FMT_MODULE
13
#endif
14
15
#ifndef FMT_MODULE
16
#  include <limits.h>  // CHAR_BIT
17
#  include <stdio.h>   // FILE
18
#  include <string.h>  // memcmp
19
20
#  include <type_traits>  // std::enable_if
21
#endif
22
23
// The fmt library version in the form major * 10000 + minor * 100 + patch.
24
#define FMT_VERSION 120200
25
26
// Detect compiler versions.
27
#if defined(__clang__) && !defined(__ibmxl__)
28
#  define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
29
#else
30
#  define FMT_CLANG_VERSION 0
31
#endif
32
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
33
#  define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
34
#else
35
0
#  define FMT_GCC_VERSION 0
36
#endif
37
#if defined(__ICL)
38
#  define FMT_ICC_VERSION __ICL
39
#elif defined(__INTEL_COMPILER)
40
#  define FMT_ICC_VERSION __INTEL_COMPILER
41
#else
42
#  define FMT_ICC_VERSION 0
43
#endif
44
#if defined(_MSC_VER)
45
#  define FMT_MSC_VERSION _MSC_VER
46
#else
47
0
#  define FMT_MSC_VERSION 0
48
#endif
49
50
// Detect standard library versions.
51
#ifdef _GLIBCXX_RELEASE
52
#  define FMT_GLIBCXX_RELEASE _GLIBCXX_RELEASE
53
#else
54
#  define FMT_GLIBCXX_RELEASE 0
55
#endif
56
#ifdef _LIBCPP_VERSION
57
#  define FMT_LIBCPP_VERSION _LIBCPP_VERSION
58
#else
59
#  define FMT_LIBCPP_VERSION 0
60
#endif
61
62
#ifdef _MSVC_LANG
63
#  define FMT_CPLUSPLUS _MSVC_LANG
64
#else
65
#  define FMT_CPLUSPLUS __cplusplus
66
#endif
67
68
// Detect __has_*.
69
#ifdef __has_feature
70
#  define FMT_HAS_FEATURE(x) __has_feature(x)
71
#else
72
#  define FMT_HAS_FEATURE(x) 0
73
#endif
74
#ifdef __has_include
75
#  define FMT_HAS_INCLUDE(x) __has_include(x)
76
#else
77
#  define FMT_HAS_INCLUDE(x) 0
78
#endif
79
#ifdef __has_builtin
80
#  define FMT_HAS_BUILTIN(x) __has_builtin(x)
81
#else
82
#  define FMT_HAS_BUILTIN(x) 0
83
#endif
84
#ifdef __has_cpp_attribute
85
#  define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
86
#else
87
#  define FMT_HAS_CPP_ATTRIBUTE(x) 0
88
#endif
89
90
#define FMT_HAS_CPP14_ATTRIBUTE(attribute) \
91
  (FMT_CPLUSPLUS >= 201402L && FMT_HAS_CPP_ATTRIBUTE(attribute))
92
93
#define FMT_HAS_CPP17_ATTRIBUTE(attribute) \
94
  (FMT_CPLUSPLUS >= 201703L && FMT_HAS_CPP_ATTRIBUTE(attribute))
95
96
// Detect C++14 relaxed constexpr.
97
#ifdef FMT_USE_CONSTEXPR
98
// Use the provided definition.
99
#elif FMT_GCC_VERSION >= 702 && FMT_CPLUSPLUS >= 201402L
100
// GCC only allows constexpr member functions in non-literal types since 7.2:
101
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66297.
102
#  define FMT_USE_CONSTEXPR 1
103
#elif FMT_ICC_VERSION
104
#  define FMT_USE_CONSTEXPR 0  // https://github.com/fmtlib/fmt/issues/1628
105
#elif FMT_HAS_FEATURE(cxx_relaxed_constexpr) || FMT_MSC_VERSION >= 1912
106
#  define FMT_USE_CONSTEXPR 1
107
#else
108
#  define FMT_USE_CONSTEXPR 0
109
#endif
110
#if FMT_USE_CONSTEXPR
111
0
#  define FMT_CONSTEXPR constexpr
112
#else
113
#  define FMT_CONSTEXPR
114
#endif
115
116
// Detect consteval, C++20 constexpr extensions and std::is_constant_evaluated.
117
#ifdef FMT_USE_CONSTEVAL
118
// Use the provided definition.
119
#elif !defined(__cpp_lib_is_constant_evaluated)
120
2.09k
#  define FMT_USE_CONSTEVAL 0
121
#elif FMT_CPLUSPLUS < 201709L
122
#  define FMT_USE_CONSTEVAL 0
123
#elif FMT_GLIBCXX_RELEASE && FMT_GLIBCXX_RELEASE < 10
124
#  define FMT_USE_CONSTEVAL 0
125
#elif FMT_LIBCPP_VERSION && FMT_LIBCPP_VERSION < 10000
126
#  define FMT_USE_CONSTEVAL 0
127
#elif defined(__apple_build_version__) && __apple_build_version__ < 14000029L
128
#  define FMT_USE_CONSTEVAL 0  // consteval is broken in Apple clang < 14.
129
#elif FMT_MSC_VERSION && FMT_MSC_VERSION < 1940
130
#  define FMT_USE_CONSTEVAL 0  // consteval is broken in some MSVC2022 versions.
131
#elif defined(__cpp_consteval)
132
#  define FMT_USE_CONSTEVAL 1
133
#elif FMT_GCC_VERSION >= 1002 || FMT_CLANG_VERSION >= 1101
134
#  define FMT_USE_CONSTEVAL 1
135
#else
136
#  define FMT_USE_CONSTEVAL 0
137
#endif
138
#if FMT_USE_CONSTEVAL
139
#  define FMT_CONSTEVAL consteval
140
#  define FMT_CONSTEXPR20 constexpr
141
#else
142
#  define FMT_CONSTEVAL
143
#  define FMT_CONSTEXPR20
144
#endif
145
146
// Check if exceptions are disabled.
147
#ifdef FMT_USE_EXCEPTIONS
148
// Use the provided definition.
149
#elif defined(__GNUC__) && !defined(__EXCEPTIONS)
150
#  define FMT_USE_EXCEPTIONS 0
151
#elif defined(__clang__) && !defined(__cpp_exceptions)
152
#  define FMT_USE_EXCEPTIONS 0
153
#elif FMT_MSC_VERSION && !_HAS_EXCEPTIONS
154
#  define FMT_USE_EXCEPTIONS 0
155
#else
156
#  define FMT_USE_EXCEPTIONS 1
157
#endif
158
#if FMT_USE_EXCEPTIONS
159
0
#  define FMT_TRY try
160
#  define FMT_CATCH(x) catch (x)
161
#else
162
#  define FMT_TRY if (true)
163
#  define FMT_CATCH(x) if (false)
164
#endif
165
166
#ifdef FMT_NO_UNIQUE_ADDRESS
167
// Use the provided definition.
168
#elif FMT_CPLUSPLUS < 202002L
169
// Not supported.
170
#elif FMT_HAS_CPP_ATTRIBUTE(no_unique_address)
171
#  define FMT_NO_UNIQUE_ADDRESS [[no_unique_address]]
172
// VS2019 v16.10 and later except clang-cl (https://reviews.llvm.org/D110485).
173
#elif FMT_MSC_VERSION >= 1929 && !FMT_CLANG_VERSION
174
#  define FMT_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
175
#endif
176
#ifndef FMT_NO_UNIQUE_ADDRESS
177
#  define FMT_NO_UNIQUE_ADDRESS
178
#endif
179
180
#if FMT_HAS_CPP17_ATTRIBUTE(fallthrough)
181
#  define FMT_FALLTHROUGH [[fallthrough]]
182
#elif defined(__clang__)
183
0
#  define FMT_FALLTHROUGH [[clang::fallthrough]]
184
#elif FMT_GCC_VERSION >= 700 && \
185
    (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 520)
186
#  define FMT_FALLTHROUGH [[gnu::fallthrough]]
187
#else
188
#  define FMT_FALLTHROUGH
189
#endif
190
191
// Disable [[noreturn]] on MSVC/NVCC because of bogus unreachable code warnings.
192
#if FMT_HAS_CPP_ATTRIBUTE(noreturn) && !FMT_MSC_VERSION && !defined(__NVCC__)
193
#  define FMT_NORETURN [[noreturn]]
194
#else
195
#  define FMT_NORETURN
196
#endif
197
198
#ifdef FMT_NODISCARD
199
// Use the provided definition.
200
#elif FMT_HAS_CPP17_ATTRIBUTE(nodiscard)
201
#  define FMT_NODISCARD [[nodiscard]]
202
#else
203
#  define FMT_NODISCARD
204
#endif
205
206
#if FMT_GCC_VERSION || FMT_CLANG_VERSION
207
#  define FMT_VISIBILITY(value) __attribute__((visibility(value)))
208
#else
209
#  define FMT_VISIBILITY(value)
210
#endif
211
212
// Detect pragmas.
213
#define FMT_PRAGMA_IMPL(x) _Pragma(#x)
214
#if FMT_GCC_VERSION >= 504 && !defined(__NVCOMPILER)
215
// Workaround a _Pragma bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59884
216
// and an nvhpc warning: https://github.com/fmtlib/fmt/pull/2582.
217
#  define FMT_PRAGMA_GCC(x) FMT_PRAGMA_IMPL(GCC x)
218
#else
219
#  define FMT_PRAGMA_GCC(x)
220
#endif
221
#if FMT_CLANG_VERSION
222
#  define FMT_PRAGMA_CLANG(x) FMT_PRAGMA_IMPL(clang x)
223
#else
224
#  define FMT_PRAGMA_CLANG(x)
225
#endif
226
#if FMT_MSC_VERSION
227
#  define FMT_PRAGMA_MSVC(x) __pragma(x)
228
#else
229
#  define FMT_PRAGMA_MSVC(x)
230
#endif
231
232
#ifndef FMT_USE_OPTIMIZE_PRAGMA
233
#  define FMT_USE_OPTIMIZE_PRAGMA 1
234
#endif
235
236
// Enable minimal optimizations for more compact code in debug mode.
237
FMT_PRAGMA_GCC(push_options)
238
#if FMT_USE_OPTIMIZE_PRAGMA && !defined(__OPTIMIZE__) && \
239
    !defined(__CUDACC__) && !defined(FMT_MODULE)
240
FMT_PRAGMA_GCC(optimize("Og"))
241
#endif
242
243
FMT_PRAGMA_MSVC(warning(push))
244
FMT_PRAGMA_MSVC(warning(disable : 4702))
245
246
#ifdef FMT_DEPRECATED
247
// Use the provided definition.
248
#elif FMT_HAS_CPP14_ATTRIBUTE(deprecated)
249
#  define FMT_DEPRECATED [[deprecated]]
250
#else
251
#  define FMT_DEPRECATED /* deprecated */
252
#endif
253
254
#ifdef FMT_ALWAYS_INLINE
255
// Use the provided definition.
256
#elif FMT_GCC_VERSION || FMT_CLANG_VERSION
257
#  define FMT_ALWAYS_INLINE inline __attribute__((always_inline))
258
#else
259
#  define FMT_ALWAYS_INLINE inline
260
#endif
261
// A version of FMT_ALWAYS_INLINE to prevent code bloat in debug mode.
262
#ifdef NDEBUG
263
#  define FMT_INLINE FMT_ALWAYS_INLINE
264
#else
265
#  define FMT_INLINE inline
266
#endif
267
268
#ifndef FMT_BEGIN_NAMESPACE
269
#  define FMT_BEGIN_NAMESPACE \
270
    namespace fmt {           \
271
    inline namespace v12 {
272
#  define FMT_END_NAMESPACE \
273
    }                       \
274
    }
275
#endif
276
277
#ifndef FMT_EXPORT
278
#  define FMT_EXPORT
279
#  define FMT_BEGIN_EXPORT
280
#  define FMT_END_EXPORT
281
#endif
282
283
#ifdef _WIN32
284
#  define FMT_WIN32 1
285
#else
286
#  define FMT_WIN32 0
287
#endif
288
289
#if !defined(FMT_HEADER_ONLY) && FMT_WIN32
290
#  if defined(FMT_LIB_EXPORT)
291
#    define FMT_API __declspec(dllexport)
292
#  elif defined(FMT_SHARED)
293
#    define FMT_API __declspec(dllimport)
294
#  endif
295
#elif defined(FMT_LIB_EXPORT) || defined(FMT_SHARED)
296
#  define FMT_API FMT_VISIBILITY("default")
297
#endif
298
#ifndef FMT_API
299
#  define FMT_API
300
#endif
301
302
#ifndef FMT_OPTIMIZE_SIZE
303
0
#  define FMT_OPTIMIZE_SIZE 0
304
#endif
305
306
// FMT_BUILTIN_TYPE=0 may result in smaller library size at the cost of higher
307
// per-call binary size by passing built-in types through the extension API.
308
#ifndef FMT_BUILTIN_TYPES
309
#  define FMT_BUILTIN_TYPES 1
310
#endif
311
312
#define FMT_APPLY_VARIADIC(expr) \
313
  using unused = int[];          \
314
  (void)unused { 0, (expr, 0)... }
315
316
FMT_BEGIN_NAMESPACE
317
318
// Implementations of enable_if_t and other metafunctions for older systems.
319
template <bool B, typename T = void>
320
using enable_if_t = typename std::enable_if<B, T>::type;
321
template <bool B, typename T, typename F>
322
using conditional_t = typename std::conditional<B, T, F>::type;
323
template <bool B> using bool_constant = std::integral_constant<bool, B>;
324
template <typename T>
325
using remove_reference_t = typename std::remove_reference<T>::type;
326
template <typename T>
327
using remove_const_t = typename std::remove_const<T>::type;
328
template <typename T>
329
using remove_cvref_t = typename std::remove_cv<remove_reference_t<T>>::type;
330
template <typename T>
331
using make_unsigned_t = typename std::make_unsigned<T>::type;
332
template <typename T>
333
using underlying_t = typename std::underlying_type<T>::type;
334
template <typename T> using decay_t = typename std::decay<T>::type;
335
using nullptr_t = decltype(nullptr);
336
337
using ullong = unsigned long long;
338
339
#if (FMT_GCC_VERSION && FMT_GCC_VERSION < 500) || FMT_MSC_VERSION
340
// A workaround for gcc 4.9 & MSVC v141 to make void_t work in a SFINAE context.
341
template <typename...> struct void_t_impl {
342
  using type = void;
343
};
344
template <typename... T> using void_t = typename void_t_impl<T...>::type;
345
#else
346
template <typename...> using void_t = void;
347
#endif
348
349
struct monostate {
350
2.09k
  constexpr monostate() {}
351
};
352
353
// An enable_if helper to be used in template parameters which results in much
354
// shorter symbols: https://godbolt.org/z/sWw4vP. Extra parentheses are needed
355
// to workaround a bug in MSVC 2019 (see #1140 and #1186).
356
#ifdef FMT_DOC
357
#  define FMT_ENABLE_IF(...)
358
#else
359
#  define FMT_ENABLE_IF(...) fmt::enable_if_t<(__VA_ARGS__), int> = 0
360
#endif
361
362
184k
template <typename T> constexpr auto min_of(T a, T b) -> T {
363
184k
  return a < b ? a : b;
364
184k
}
unsigned long fmt::v12::min_of<unsigned long>(unsigned long, unsigned long)
Line
Count
Source
362
180k
template <typename T> constexpr auto min_of(T a, T b) -> T {
363
180k
  return a < b ? a : b;
364
180k
}
int fmt::v12::min_of<int>(int, int)
Line
Count
Source
362
3.71k
template <typename T> constexpr auto min_of(T a, T b) -> T {
363
3.71k
  return a < b ? a : b;
364
3.71k
}
365
1.30k
template <typename T> constexpr auto max_of(T a, T b) -> T {
366
1.30k
  return a > b ? a : b;
367
1.30k
}
Unexecuted instantiation: unsigned long fmt::v12::max_of<unsigned long>(unsigned long, unsigned long)
int fmt::v12::max_of<int>(int, int)
Line
Count
Source
365
1.30k
template <typename T> constexpr auto max_of(T a, T b) -> T {
366
1.30k
  return a > b ? a : b;
367
1.30k
}
Unexecuted instantiation: long fmt::v12::max_of<long>(long, long)
368
369
FMT_NORETURN FMT_API void assert_fail(const char* file, int line,
370
                                      const char* message);
371
372
namespace detail {
373
// Suppresses "unused variable" warnings with the method described in
374
// https://herbsutter.com/2009/10/18/mailbag-shutting-up-compiler-warnings/.
375
// (void)var does not work on many Intel compilers.
376
359
template <typename... T> FMT_CONSTEXPR void ignore_unused(const T&...) {}
void fmt::v12::detail::ignore_unused<bool>(bool const&)
Line
Count
Source
376
359
template <typename... T> FMT_CONSTEXPR void ignore_unused(const T&...) {}
Unexecuted instantiation: void fmt::v12::detail::ignore_unused<unsigned long>(unsigned long const&)
Unexecuted instantiation: void fmt::v12::detail::ignore_unused<int, int>(int const&, int const&)
Unexecuted instantiation: void fmt::v12::detail::ignore_unused<int>(int const&)
Unexecuted instantiation: void fmt::v12::detail::ignore_unused<fmt::v12::basic_string_view<char> >(fmt::v12::basic_string_view<char> const&)
377
378
constexpr auto is_constant_evaluated(bool default_value = false) noexcept
379
0
    -> bool {
380
0
// Workaround for incompatibility between clang 14 and libstdc++ consteval-based
381
0
// std::is_constant_evaluated: https://github.com/fmtlib/fmt/issues/3247.
382
0
#if FMT_CPLUSPLUS >= 202002L && FMT_GLIBCXX_RELEASE >= 12 && \
383
0
    (FMT_CLANG_VERSION >= 1400 && FMT_CLANG_VERSION < 1500)
384
0
  ignore_unused(default_value);
385
0
  return __builtin_is_constant_evaluated();
386
0
#elif defined(__cpp_lib_is_constant_evaluated)
387
0
  ignore_unused(default_value);
388
0
  return std::is_constant_evaluated();
389
0
#else
390
0
  return default_value;
391
0
#endif
392
0
}
393
394
#ifdef FMT_ASSERT
395
// Use the provided definition.
396
#elif defined(NDEBUG)
397
// FMT_ASSERT is not empty to avoid -Wempty-body.
398
#  define FMT_ASSERT(condition, message) \
399
    fmt::detail::ignore_unused((condition), (message))
400
#else
401
#  define FMT_ASSERT(condition, message)                                    \
402
806k
    ((condition) /* void() fails with -Winvalid-constexpr on clang 4.0.1 */ \
403
806k
         ? (void)0                                                          \
404
806k
         : ::fmt::assert_fail(__FILE__, __LINE__, (message)))
405
#endif
406
407
#ifdef FMT_USE_INT128
408
// Use the provided definition.
409
#elif defined(__SIZEOF_INT128__) && !defined(__NVCC__) && \
410
    !(FMT_CLANG_VERSION && FMT_MSC_VERSION)
411
#  define FMT_USE_INT128 1
412
using native_int128 = __int128_t;
413
using native_uint128 = __uint128_t;
414
0
inline auto map(native_int128 x) -> native_int128 { return x; }
415
0
inline auto map(native_uint128 x) -> native_uint128 { return x; }
416
#else
417
#  define FMT_USE_INT128 0
418
#endif
419
#if !FMT_USE_INT128
420
// Fallbacks to reduce conditional compilation and SFINAE.
421
enum class native_int128 {};
422
enum class native_uint128 {};
423
inline auto map(native_int128) -> monostate { return {}; }
424
inline auto map(native_uint128) -> monostate { return {}; }
425
#endif
426
427
// Casts a nonnegative integer to unsigned.
428
template <typename Int>
429
176k
FMT_CONSTEXPR auto to_unsigned(Int value) -> make_unsigned_t<Int> {
430
176k
  FMT_ASSERT(std::is_unsigned<Int>::value || value >= 0, "negative value");
431
176k
  return static_cast<make_unsigned_t<Int>>(value);
432
176k
}
std::__1::make_unsigned<int>::type fmt::v12::detail::to_unsigned<int>(int)
Line
Count
Source
429
174k
FMT_CONSTEXPR auto to_unsigned(Int value) -> make_unsigned_t<Int> {
430
174k
  FMT_ASSERT(std::is_unsigned<Int>::value || value >= 0, "negative value");
431
174k
  return static_cast<make_unsigned_t<Int>>(value);
432
174k
}
std::__1::make_unsigned<long>::type fmt::v12::detail::to_unsigned<long>(long)
Line
Count
Source
429
1.99k
FMT_CONSTEXPR auto to_unsigned(Int value) -> make_unsigned_t<Int> {
430
1.99k
  FMT_ASSERT(std::is_unsigned<Int>::value || value >= 0, "negative value");
431
1.99k
  return static_cast<make_unsigned_t<Int>>(value);
432
1.99k
}
Unexecuted instantiation: std::__1::make_unsigned<unsigned long>::type fmt::v12::detail::to_unsigned<unsigned long>(unsigned long)
433
434
template <typename Char>
435
using unsigned_char = conditional_t<sizeof(Char) == 1, unsigned char, unsigned>;
436
437
// A heuristic to detect std::string and std::[experimental::]string_view.
438
// It is mainly used to avoid dependency on <[experimental/]string_view>.
439
template <typename T, typename Enable = void>
440
struct is_std_string_like : std::false_type {};
441
template <typename T>
442
struct is_std_string_like<T, void_t<decltype(std::declval<T>().find_first_of(
443
                                 typename T::value_type(), 0))>>
444
    : std::is_convertible<decltype(std::declval<T>().data()),
445
                          const typename T::value_type*> {};
446
447
// Check if the literal encoding is UTF-8.
448
enum { is_utf8_enabled = "\u00A7"[1] == '\xA7' };
449
enum { use_utf8 = !FMT_WIN32 || is_utf8_enabled };
450
451
#ifndef FMT_UNICODE
452
#  define FMT_UNICODE 1
453
#endif
454
455
static_assert(!FMT_UNICODE || use_utf8,
456
              "Unicode support requires compiling with /utf-8");
457
458
template <typename T> constexpr auto narrow(T*) -> char* { return nullptr; }
459
2.27k
constexpr FMT_ALWAYS_INLINE auto narrow(const char* s) -> const char* {
460
2.27k
  return s;
461
2.27k
}
462
463
template <typename Char>
464
186
FMT_CONSTEXPR auto compare(const Char* s1, const Char* s2, size_t n) -> int {
465
186
  if (!is_constant_evaluated() && sizeof(Char) == 1) return memcmp(s1, s2, n);
466
0
  for (; n != 0; ++s1, ++s2, --n) {
467
0
    if (*s1 < *s2) return -1;
468
0
    if (*s1 > *s2) return 1;
469
0
  }
470
0
  return 0;
471
0
}
472
473
namespace adl {
474
using namespace std;
475
476
template <typename Container>
477
auto invoke_back_inserter()
478
    -> decltype(back_inserter(std::declval<Container&>()));
479
}  // namespace adl
480
481
template <typename It, typename Enable = std::true_type>
482
struct is_back_insert_iterator : std::false_type {};
483
484
template <typename It>
485
struct is_back_insert_iterator<
486
    It, bool_constant<std::is_same<
487
            decltype(adl::invoke_back_inserter<typename It::container_type>()),
488
            It>::value>> : std::true_type {};
489
490
// Extracts a reference to the container from *insert_iterator.
491
template <typename OutputIt>
492
inline FMT_CONSTEXPR auto get_container(OutputIt it) ->
493
8.49k
    typename OutputIt::container_type& {
494
8.49k
  struct accessor : OutputIt {
495
8.49k
    constexpr accessor(OutputIt base) : OutputIt(base) {}
fmt::v12::detail::get_container<std::__1::back_insert_iterator<fmt::v12::basic_memory_buffer<char, 500ul, fmt::v12::detail::allocator<char> > > >(std::__1::back_insert_iterator<fmt::v12::basic_memory_buffer<char, 500ul, fmt::v12::detail::allocator<char> > >)::accessor::accessor(std::__1::back_insert_iterator<fmt::v12::basic_memory_buffer<char, 500ul, fmt::v12::detail::allocator<char> > >)
Line
Count
Source
495
2.09k
    constexpr accessor(OutputIt base) : OutputIt(base) {}
fmt::v12::detail::get_container<fmt::v12::basic_appender<char> >(fmt::v12::basic_appender<char>)::accessor::accessor(fmt::v12::basic_appender<char>)
Line
Count
Source
495
6.40k
    constexpr accessor(OutputIt base) : OutputIt(base) {}
496
8.49k
    using OutputIt::container;
497
8.49k
  };
498
8.49k
  return *accessor(it).container;
499
8.49k
}
std::__1::back_insert_iterator<fmt::v12::basic_memory_buffer<char, 500ul, fmt::v12::detail::allocator<char> > >::container_type& fmt::v12::detail::get_container<std::__1::back_insert_iterator<fmt::v12::basic_memory_buffer<char, 500ul, fmt::v12::detail::allocator<char> > > >(std::__1::back_insert_iterator<fmt::v12::basic_memory_buffer<char, 500ul, fmt::v12::detail::allocator<char> > >)
Line
Count
Source
493
2.09k
    typename OutputIt::container_type& {
494
2.09k
  struct accessor : OutputIt {
495
2.09k
    constexpr accessor(OutputIt base) : OutputIt(base) {}
496
2.09k
    using OutputIt::container;
497
2.09k
  };
498
2.09k
  return *accessor(it).container;
499
2.09k
}
fmt::v12::basic_appender<char>::container_type& fmt::v12::detail::get_container<fmt::v12::basic_appender<char> >(fmt::v12::basic_appender<char>)
Line
Count
Source
493
6.40k
    typename OutputIt::container_type& {
494
6.40k
  struct accessor : OutputIt {
495
6.40k
    constexpr accessor(OutputIt base) : OutputIt(base) {}
496
6.40k
    using OutputIt::container;
497
6.40k
  };
498
6.40k
  return *accessor(it).container;
499
6.40k
}
500
501
template <typename T, typename Enable = void>
502
struct is_contiguous : std::false_type {};
503
template <typename T>
504
struct is_contiguous<T,
505
                     void_t<decltype(std::declval<T&>().data()),
506
                            decltype(std::declval<T&>().size()),
507
                            decltype(std::declval<T&>().operator[](size_t()))>>
508
    : std::true_type {};
509
}  // namespace detail
510
511
// Parsing-related public API and forward declarations.
512
FMT_BEGIN_EXPORT
513
514
/**
515
 * An implementation of `std::basic_string_view` for pre-C++17 providing a
516
 * subset of the API. `fmt::basic_string_view` is used in the public API even
517
 * if `std::basic_string_view` is available to prevent issues when a library is
518
 * compiled with a different `-std` option than the client code (which is not
519
 * recommended).
520
 */
521
template <typename Char> class basic_string_view {
522
 private:
523
  const Char* data_;
524
  size_t size_;
525
526
 public:
527
  using value_type = Char;
528
  using iterator = const Char*;
529
530
0
  constexpr basic_string_view() noexcept : data_(nullptr), size_(0) {}
531
  constexpr basic_string_view(const Char* s, size_t count) noexcept
532
186
      : data_(s), size_(count) {}
533
534
#if FMT_GCC_VERSION
535
  FMT_ALWAYS_INLINE
536
#endif
537
2.27k
  FMT_CONSTEXPR basic_string_view(const Char* s) : data_(s) {
538
2.27k
#if FMT_HAS_BUILTIN(__builtin_strlen) || FMT_GCC_VERSION || FMT_CLANG_VERSION
539
2.27k
    if (std::is_same<Char, char>::value && !detail::is_constant_evaluated()) {
540
2.27k
      size_ = __builtin_strlen(detail::narrow(s));  // strlen is not constexpr.
541
2.27k
      return;
542
2.27k
    }
543
0
#endif
544
0
    size_t len = 0;
545
0
    while (*s++) ++len;
546
0
    size_ = len;
547
0
  }
548
549
  template <
550
      typename S,
551
      FMT_ENABLE_IF(detail::is_std_string_like<S>::value&&  //
552
                        std::is_same<typename S::value_type, Char>::value)>
553
  constexpr basic_string_view(const S& s) noexcept
554
      : data_(s.data()), size_(s.size()) {}
555
556
2.09k
  constexpr auto data() const noexcept -> const Char* { return data_; }
557
3.13k
  constexpr auto size() const noexcept -> size_t { return size_; }
558
559
0
  constexpr auto begin() const noexcept -> iterator { return data_; }
560
0
  constexpr auto end() const noexcept -> iterator { return data_ + size_; }
561
562
0
  constexpr auto operator[](size_t pos) const noexcept -> const Char& {
563
0
    return data_[pos];
564
0
  }
565
566
0
  FMT_CONSTEXPR void remove_prefix(size_t n) noexcept {
567
0
    data_ += n;
568
0
    size_ -= n;
569
0
  }
570
571
  FMT_CONSTEXPR auto starts_with(basic_string_view sv) const noexcept -> bool {
572
    return size_ >= sv.size_ && detail::compare(data_, sv.data_, sv.size_) == 0;
573
  }
574
  FMT_CONSTEXPR auto starts_with(Char c) const noexcept -> bool {
575
    return size_ >= 1 && *data_ == c;
576
  }
577
  FMT_CONSTEXPR auto starts_with(const Char* s) const -> bool {
578
    return starts_with(basic_string_view(s));
579
  }
580
581
186
  FMT_CONSTEXPR auto compare(basic_string_view other) const -> int {
582
186
    int cmp = detail::compare(data_, other.data_, min_of(size_, other.size_));
583
186
    if (cmp != 0) return cmp;
584
186
    return size_ == other.size_ ? 0 : (size_ < other.size_ ? -1 : 1);
585
186
  }
586
587
  FMT_CONSTEXPR friend auto operator==(basic_string_view lhs,
588
0
                                       basic_string_view rhs) -> bool {
589
0
    return lhs.compare(rhs) == 0;
590
0
  }
591
186
  friend auto operator!=(basic_string_view lhs, basic_string_view rhs) -> bool {
592
186
    return lhs.compare(rhs) != 0;
593
186
  }
594
  friend auto operator<(basic_string_view lhs, basic_string_view rhs) -> bool {
595
    return lhs.compare(rhs) < 0;
596
  }
597
  friend auto operator<=(basic_string_view lhs, basic_string_view rhs) -> bool {
598
    return lhs.compare(rhs) <= 0;
599
  }
600
  friend auto operator>(basic_string_view lhs, basic_string_view rhs) -> bool {
601
    return lhs.compare(rhs) > 0;
602
  }
603
  friend auto operator>=(basic_string_view lhs, basic_string_view rhs) -> bool {
604
    return lhs.compare(rhs) >= 0;
605
  }
606
};
607
using string_view = basic_string_view<char>;
608
609
template <typename T> class basic_appender;
610
using appender = basic_appender<char>;
611
612
class context;
613
template <typename OutputIt, typename Char> class generic_context;
614
template <typename Char> class parse_context;
615
616
// Longer aliases for C++20 compatibility.
617
template <typename Char> using basic_format_parse_context = parse_context<Char>;
618
using format_parse_context = parse_context<char>;
619
template <typename OutputIt, typename Char>
620
using basic_format_context =
621
    conditional_t<std::is_same<OutputIt, appender>::value, context,
622
                  generic_context<OutputIt, Char>>;
623
using format_context = context;
624
625
template <typename Char>
626
using buffered_context =
627
    conditional_t<std::is_same<Char, char>::value, context,
628
                  generic_context<basic_appender<Char>, Char>>;
629
630
template <typename T> struct is_contiguous : detail::is_contiguous<T> {};
631
632
template <typename Context> class basic_format_arg;
633
template <typename Context> class basic_format_args;
634
635
// A separate type would result in shorter symbols but break ABI compatibility
636
// between clang and gcc on ARM (#1919).
637
using format_args = basic_format_args<context>;
638
639
// A formatter for objects of type T.
640
template <typename T, typename Char = char, typename Enable = void>
641
struct formatter {
642
  // A deleted default constructor indicates a disabled formatter.
643
  formatter() = delete;
644
};
645
646
template <typename T, typename Enable = void>
647
struct locking : std::false_type {};
648
649
/// Reports a format error at compile time or, via a `format_error` exception,
650
/// at runtime.
651
// This function is intentionally not constexpr to give a compile-time error.
652
FMT_NORETURN FMT_API void report_error(const char* message);
653
654
enum class presentation_type : unsigned char {
655
  // Common specifiers:
656
  none = 0,
657
  debug = 1,   // '?'
658
  string = 2,  // 's' (string, bool)
659
660
  // Integral, bool and character specifiers:
661
  dec = 3,  // 'd'
662
  hex,      // 'x' or 'X'
663
  oct,      // 'o'
664
  bin,      // 'b' or 'B'
665
  chr,      // 'c'
666
667
  // String and pointer specifiers:
668
  pointer = 3,  // 'p'
669
670
  // Floating-point specifiers:
671
  exp = 1,  // 'e' or 'E' (1 since there is no FP debug presentation)
672
  fixed,    // 'f' or 'F'
673
  general,  // 'g' or 'G'
674
  hexfloat  // 'a' or 'A'
675
};
676
677
enum class align { none, left, right, center, numeric };
678
enum class sign { none, minus, plus, space };
679
enum class arg_id_kind { none, index, name };
680
681
// Basic format specifiers for built-in and string types.
682
class basic_specs {
683
 private:
684
  // Data is arranged as follows:
685
  //
686
  //  0                   1                   2                   3
687
  //  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
688
  // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
689
  // |type |align| w | p | s |u|#|L|  f  |          unused           |
690
  // +-----+-----+---+---+---+-+-+-+-----+---------------------------+
691
  //
692
  //   w - dynamic width info
693
  //   p - dynamic precision info
694
  //   s - sign
695
  //   u - uppercase (e.g. 'X' for 'x')
696
  //   # - alternate form ('#')
697
  //   L - localized
698
  //   f - fill size
699
  //
700
  // Bitfields are not used because of compiler bugs such as gcc bug 61414.
701
  enum : unsigned {
702
    type_mask = 0x00007,
703
    align_mask = 0x00038,
704
    width_mask = 0x000C0,
705
    precision_mask = 0x00300,
706
    sign_mask = 0x00C00,
707
    uppercase_mask = 0x01000,
708
    alternate_mask = 0x02000,
709
    localized_mask = 0x04000,
710
    fill_size_mask = 0x38000,
711
712
    align_shift = 3,
713
    width_shift = 6,
714
    precision_shift = 8,
715
    sign_shift = 10,
716
    fill_size_shift = 15,
717
718
    max_fill_size = 4
719
  };
720
721
  unsigned data_ = 1 << fill_size_shift;
722
  static_assert(sizeof(basic_specs::data_) * CHAR_BIT >= 18, "");
723
724
  // Character (code unit) type is erased to prevent template bloat.
725
  char fill_data_[max_fill_size] = {' '};
726
727
0
  FMT_CONSTEXPR void set_fill_size(size_t size) {
728
0
    data_ = (data_ & ~fill_size_mask) | (unsigned(size) << fill_size_shift);
729
0
  }
730
731
 public:
732
5.70k
  constexpr auto type() const -> presentation_type {
733
5.70k
    return static_cast<presentation_type>(data_ & type_mask);
734
5.70k
  }
735
1.04k
  FMT_CONSTEXPR void set_type(presentation_type t) {
736
1.04k
    data_ = (data_ & ~type_mask) | unsigned(t);
737
1.04k
  }
738
739
1.98k
  constexpr auto align() const -> align {
740
1.98k
    return static_cast<fmt::align>((data_ & align_mask) >> align_shift);
741
1.98k
  }
742
0
  FMT_CONSTEXPR void set_align(fmt::align a) {
743
0
    data_ = (data_ & ~align_mask) | (unsigned(a) << align_shift);
744
0
  }
745
746
0
  constexpr auto dynamic_width() const -> arg_id_kind {
747
0
    return static_cast<arg_id_kind>((data_ & width_mask) >> width_shift);
748
0
  }
749
0
  FMT_CONSTEXPR void set_dynamic_width(arg_id_kind w) {
750
0
    data_ = (data_ & ~width_mask) | (unsigned(w) << width_shift);
751
0
  }
752
753
0
  FMT_CONSTEXPR auto dynamic_precision() const -> arg_id_kind {
754
0
    return static_cast<arg_id_kind>((data_ & precision_mask) >>
755
0
                                    precision_shift);
756
0
  }
757
1.04k
  FMT_CONSTEXPR void set_dynamic_precision(arg_id_kind p) {
758
1.04k
    data_ = (data_ & ~precision_mask) | (unsigned(p) << precision_shift);
759
1.04k
  }
760
761
1.04k
  constexpr auto dynamic() const -> bool {
762
1.04k
    return (data_ & (width_mask | precision_mask)) != 0;
763
1.04k
  }
764
765
569
  constexpr auto sign() const -> sign {
766
569
    return static_cast<fmt::sign>((data_ & sign_mask) >> sign_shift);
767
569
  }
768
0
  FMT_CONSTEXPR void set_sign(fmt::sign s) {
769
0
    data_ = (data_ & ~sign_mask) | (unsigned(s) << sign_shift);
770
0
  }
771
772
693
  constexpr auto upper() const -> bool { return (data_ & uppercase_mask) != 0; }
773
0
  FMT_CONSTEXPR void set_upper() { data_ |= uppercase_mask; }
774
775
2.52k
  constexpr auto alt() const -> bool { return (data_ & alternate_mask) != 0; }
776
0
  FMT_CONSTEXPR void set_alt() { data_ |= alternate_mask; }
777
0
  FMT_CONSTEXPR void clear_alt() { data_ &= ~alternate_mask; }
778
779
2.71k
  constexpr auto localized() const -> bool {
780
2.71k
    return (data_ & localized_mask) != 0;
781
2.71k
  }
782
0
  FMT_CONSTEXPR void set_localized() { data_ |= localized_mask; }
783
784
1.22k
  constexpr auto fill_size() const -> size_t {
785
1.22k
    return (data_ & fill_size_mask) >> fill_size_shift;
786
1.22k
  }
787
788
  template <typename Char, FMT_ENABLE_IF(std::is_same<Char, char>::value)>
789
0
  constexpr auto fill() const -> const Char* {
790
0
    return fill_data_;
791
0
  }
792
  template <typename Char, FMT_ENABLE_IF(!std::is_same<Char, char>::value)>
793
  constexpr auto fill() const -> const Char* {
794
    return nullptr;
795
  }
796
797
190
  template <typename Char> constexpr auto fill_unit() const -> Char {
798
190
    using uchar = unsigned char;
799
190
    return Char(uchar(fill_data_[0]) | uchar(fill_data_[1]) << 8 |
800
190
                uchar(fill_data_[2]) << 16);
801
190
  }
802
803
0
  FMT_CONSTEXPR void set_fill(char c) {
804
0
    fill_data_[0] = c;
805
0
    set_fill_size(1);
806
0
  }
807
808
  template <typename Char>
809
0
  FMT_CONSTEXPR void set_fill(basic_string_view<Char> s) {
810
0
    auto size = s.size();
811
0
    set_fill_size(size);
812
0
    if (size == 1) {
813
0
      unsigned uchar = static_cast<detail::unsigned_char<Char>>(s[0]);
814
0
      fill_data_[0] = char(uchar);
815
0
      fill_data_[1] = char(uchar >> 8);
816
0
      fill_data_[2] = char(uchar >> 16);
817
0
      return;
818
0
    }
819
0
    FMT_ASSERT(size <= max_fill_size, "invalid fill");
820
0
    for (size_t i = 0; i < size; ++i) fill_data_[i & 3] = char(s[i]);
821
0
  }
822
823
0
  FMT_CONSTEXPR void copy_fill_from(const basic_specs& specs) {
824
0
    set_fill_size(specs.fill_size());
825
0
    for (size_t i = 0; i < max_fill_size; ++i)
826
0
      fill_data_[i] = specs.fill_data_[i];
827
0
  }
828
};
829
830
// Format specifiers for built-in and string types.
831
struct format_specs : basic_specs {
832
  int width;
833
  int precision;
834
835
1.54k
  constexpr format_specs() : width(0), precision(-1) {}
836
};
837
838
/**
839
 * Parsing context consisting of a format string range being parsed and an
840
 * argument counter for automatic indexing.
841
 */
842
template <typename Char = char> class parse_context {
843
 private:
844
  basic_string_view<Char> fmt_;
845
  int next_arg_id_;
846
847
  enum { use_constexpr_cast = !FMT_GCC_VERSION || FMT_GCC_VERSION >= 1200 };
848
849
  FMT_CONSTEXPR void do_check_arg_id(int arg_id);
850
851
 public:
852
  using char_type = Char;
853
  using iterator = const Char*;
854
855
  constexpr explicit parse_context(basic_string_view<Char> fmt,
856
                                   int next_arg_id = 0)
857
1.04k
      : fmt_(fmt), next_arg_id_(next_arg_id) {}
858
859
  /// Returns an iterator to the beginning of the format string range being
860
  /// parsed.
861
0
  constexpr auto begin() const noexcept -> iterator { return fmt_.begin(); }
862
863
  /// Returns an iterator past the end of the format string range being parsed.
864
0
  constexpr auto end() const noexcept -> iterator { return fmt_.end(); }
865
866
  /// Advances the begin iterator to `it`.
867
0
  FMT_CONSTEXPR void advance_to(iterator it) {
868
0
    fmt_.remove_prefix(detail::to_unsigned(it - begin()));
869
0
  }
870
871
  /// Reports an error if using the manual argument indexing; otherwise returns
872
  /// the next argument index and switches to the automatic indexing.
873
1.04k
  FMT_CONSTEXPR auto next_arg_id() -> int {
874
1.04k
    if (next_arg_id_ < 0) {
875
0
      report_error("cannot switch from manual to automatic argument indexing");
876
0
      return 0;
877
0
    }
878
1.04k
    int id = next_arg_id_++;
879
1.04k
    do_check_arg_id(id);
880
1.04k
    return id;
881
1.04k
  }
882
883
  /// Reports an error if using the automatic argument indexing; otherwise
884
  /// switches to the manual indexing.
885
0
  FMT_CONSTEXPR void check_arg_id(int id) {
886
0
    if (next_arg_id_ > 0) {
887
0
      report_error("cannot switch from automatic to manual argument indexing");
888
0
      return;
889
0
    }
890
0
    next_arg_id_ = -1;
891
0
    do_check_arg_id(id);
892
0
  }
893
0
  FMT_CONSTEXPR void check_arg_id(basic_string_view<Char>) {
894
0
    next_arg_id_ = -1;
895
0
  }
896
  FMT_CONSTEXPR void check_dynamic_spec(int arg_id);
897
};
898
899
#ifndef FMT_USE_LOCALE
900
#  define FMT_USE_LOCALE (FMT_OPTIMIZE_SIZE <= 1)
901
#endif
902
903
// A type-erased reference to std::locale to avoid the heavy <locale> include.
904
class locale_ref {
905
#if FMT_USE_LOCALE
906
 private:
907
  const void* locale_;  // A type-erased pointer to std::locale.
908
909
 public:
910
2.49k
  constexpr locale_ref() : locale_(nullptr) {}
911
912
  template <typename Locale, FMT_ENABLE_IF(sizeof(Locale::collate) != 0)>
913
0
  locale_ref(const Locale& loc) : locale_(&loc) {
914
    // Check if std::isalpha is found via ADL to reduce the chance of misuse.
915
0
    detail::ignore_unused(sizeof(isalpha('x', loc)));
916
0
  }
917
918
0
  inline explicit operator bool() const noexcept { return locale_ != nullptr; }
919
#else
920
 public:
921
  inline explicit operator bool() const noexcept { return false; }
922
#endif  // FMT_USE_LOCALE
923
924
 public:
925
  template <typename Locale> auto get() const -> Locale;
926
};
927
928
FMT_END_EXPORT
929
930
namespace detail {
931
932
// Specifies if `T` is a code unit type.
933
template <typename T> struct is_code_unit : std::false_type {};
934
template <> struct is_code_unit<char> : std::true_type {};
935
template <> struct is_code_unit<wchar_t> : std::true_type {};
936
template <> struct is_code_unit<char16_t> : std::true_type {};
937
template <> struct is_code_unit<char32_t> : std::true_type {};
938
#ifdef __cpp_char8_t
939
template <> struct is_code_unit<char8_t> : bool_constant<is_utf8_enabled> {};
940
#endif
941
942
// Constructs fmt::basic_string_view<Char> from types implicitly convertible
943
// to it, deducing Char. Explicitly convertible types such as the ones returned
944
// from FMT_STRING are intentionally excluded.
945
template <typename Char, FMT_ENABLE_IF(is_code_unit<Char>::value)>
946
constexpr auto to_string_view(const Char* s) -> basic_string_view<Char> {
947
  return s;
948
}
949
template <typename T, FMT_ENABLE_IF(is_std_string_like<T>::value)>
950
constexpr auto to_string_view(const T& s)
951
    -> basic_string_view<typename T::value_type> {
952
  return s;
953
}
954
template <typename Char>
955
constexpr auto to_string_view(basic_string_view<Char> s)
956
0
    -> basic_string_view<Char> {
957
0
  return s;
958
0
}
959
960
template <typename T, typename Enable = void>
961
struct has_to_string_view : std::false_type {};
962
// detail:: is intentional since to_string_view is not an extension point.
963
template <typename T>
964
struct has_to_string_view<
965
    T, void_t<decltype(detail::to_string_view(std::declval<T>()))>>
966
    : std::true_type {};
967
968
/// String's character (code unit) type. detail:: is intentional to prevent ADL.
969
template <typename S,
970
          typename V = decltype(detail::to_string_view(std::declval<S>()))>
971
using char_t = typename V::value_type;
972
973
enum class type {
974
  none_type,
975
  // Integer types should go first,
976
  int_type,
977
  uint_type,
978
  long_long_type,
979
  ulong_long_type,
980
  int128_type,
981
  uint128_type,
982
  bool_type,
983
  char_type,
984
  last_integer_type = char_type,
985
  // followed by floating-point types.
986
  float_type,
987
  double_type,
988
  long_double_type,
989
  last_numeric_type = long_double_type,
990
  cstring_type,
991
  string_type,
992
  pointer_type,
993
  custom_type
994
};
995
996
// Maps core type T to the corresponding type enum constant.
997
template <typename T, typename Char>
998
struct type_constant : std::integral_constant<type, type::custom_type> {};
999
1000
#define FMT_TYPE_CONSTANT(Type, constant) \
1001
  template <typename Char>                \
1002
  struct type_constant<Type, Char>        \
1003
      : std::integral_constant<type, type::constant> {}
1004
1005
FMT_TYPE_CONSTANT(int, int_type);
1006
FMT_TYPE_CONSTANT(unsigned, uint_type);
1007
FMT_TYPE_CONSTANT(long long, long_long_type);
1008
FMT_TYPE_CONSTANT(ullong, ulong_long_type);
1009
FMT_TYPE_CONSTANT(native_int128, int128_type);
1010
FMT_TYPE_CONSTANT(native_uint128, uint128_type);
1011
FMT_TYPE_CONSTANT(bool, bool_type);
1012
FMT_TYPE_CONSTANT(Char, char_type);
1013
FMT_TYPE_CONSTANT(float, float_type);
1014
FMT_TYPE_CONSTANT(double, double_type);
1015
FMT_TYPE_CONSTANT(long double, long_double_type);
1016
FMT_TYPE_CONSTANT(const Char*, cstring_type);
1017
FMT_TYPE_CONSTANT(basic_string_view<Char>, string_type);
1018
FMT_TYPE_CONSTANT(const void*, pointer_type);
1019
1020
0
constexpr auto is_integral_type(type t) -> bool {
1021
0
  return t > type::none_type && t <= type::last_integer_type;
1022
0
}
1023
0
constexpr auto is_arithmetic_type(type t) -> bool {
1024
0
  return t > type::none_type && t <= type::last_numeric_type;
1025
0
}
1026
1027
0
constexpr auto set(type rhs) -> int { return 1 << int(rhs); }
1028
2.09k
constexpr auto in(type t, int set) -> bool {
1029
2.09k
  return ((set >> int(t)) & 1) != 0;
1030
2.09k
}
1031
1032
// Bitsets of types.
1033
enum {
1034
  sint_set =
1035
      set(type::int_type) | set(type::long_long_type) | set(type::int128_type),
1036
  uint_set = set(type::uint_type) | set(type::ulong_long_type) |
1037
             set(type::uint128_type),
1038
  bool_set = set(type::bool_type),
1039
  char_set = set(type::char_type),
1040
  float_set = set(type::float_type) | set(type::double_type) |
1041
              set(type::long_double_type),
1042
  string_set = set(type::string_type),
1043
  cstring_set = set(type::cstring_type),
1044
  pointer_set = set(type::pointer_type)
1045
};
1046
1047
struct view {};
1048
1049
template <typename T, typename Enable = std::true_type>
1050
struct is_view : std::false_type {};
1051
template <typename T>
1052
struct is_view<T, bool_constant<sizeof(T) != 0>> : std::is_base_of<view, T> {};
1053
1054
// DEPRECATED! named_arg will be moved to the fmt namespace.
1055
template <typename T, typename Char> struct named_arg;
1056
template <typename T> struct is_named_arg : std::false_type {};
1057
template <typename T> struct is_static_named_arg : std::false_type {};
1058
1059
template <typename T, typename Char>
1060
struct is_named_arg<named_arg<T, Char>> : std::true_type {};
1061
1062
template <typename T, typename Char = char> struct named_arg : view {
1063
  const Char* name;
1064
  const T& value;
1065
1066
  named_arg(const Char* n, const T& v) : name(n), value(v) {}
1067
  static_assert(!is_named_arg<T>::value, "nested named arguments");
1068
};
1069
1070
0
template <bool B = false> constexpr auto count() -> int { return B ? 1 : 0; }
1071
0
template <bool B1, bool B2, bool... Tail> constexpr auto count() -> int {
1072
0
  return (B1 ? 1 : 0) + count<B2, Tail...>();
1073
0
}
1074
1075
0
template <typename... T> constexpr auto count_named_args() -> int {
1076
0
  return count<is_named_arg<T>::value...>();
1077
0
}
Unexecuted instantiation: int fmt::v12::detail::count_named_args<double&>()
Unexecuted instantiation: int fmt::v12::detail::count_named_args<fmt::v12::basic_string_view<char>&, char const (&) [3]>()
Unexecuted instantiation: int fmt::v12::detail::count_named_args<char const (&) [7], int&>()
Unexecuted instantiation: int fmt::v12::detail::count_named_args<>()
Unexecuted instantiation: int fmt::v12::detail::count_named_args<unsigned int&>()
Unexecuted instantiation: int fmt::v12::detail::count_named_args<int>()
1078
0
template <typename... T> constexpr auto count_static_named_args() -> int {
1079
0
  return count<is_static_named_arg<T>::value...>();
1080
0
}
Unexecuted instantiation: int fmt::v12::detail::count_static_named_args<double&>()
Unexecuted instantiation: int fmt::v12::detail::count_static_named_args<fmt::v12::basic_string_view<char>&, char const (&) [3]>()
Unexecuted instantiation: int fmt::v12::detail::count_static_named_args<char const (&) [7], int&>()
Unexecuted instantiation: int fmt::v12::detail::count_static_named_args<>()
Unexecuted instantiation: int fmt::v12::detail::count_static_named_args<unsigned int&>()
Unexecuted instantiation: int fmt::v12::detail::count_static_named_args<int>()
1081
1082
template <typename Char> struct named_arg_info {
1083
  const Char* name;
1084
  int id;
1085
};
1086
1087
// named_args is non-const to suppress a bogus -Wmaybe-uninitialized in gcc 13.
1088
template <typename Char>
1089
FMT_CONSTEXPR void check_for_duplicate(named_arg_info<Char>* named_args,
1090
                                       int named_arg_index,
1091
                                       basic_string_view<Char> arg_name) {
1092
  for (int i = 0; i < named_arg_index; ++i) {
1093
    if (named_args[i].name == arg_name) report_error("duplicate named arg");
1094
  }
1095
}
1096
1097
template <typename Char, typename T, FMT_ENABLE_IF(!is_named_arg<T>::value)>
1098
void init_named_arg(named_arg_info<Char>*, int& arg_index, int&, const T&) {
1099
  ++arg_index;
1100
}
1101
template <typename Char, typename T, FMT_ENABLE_IF(is_named_arg<T>::value)>
1102
void init_named_arg(named_arg_info<Char>* named_args, int& arg_index,
1103
                    int& named_arg_index, const T& arg) {
1104
  check_for_duplicate<Char>(named_args, named_arg_index, arg.name);
1105
  named_args[named_arg_index++] = {arg.name, arg_index++};
1106
}
1107
1108
template <typename T, typename Char,
1109
          FMT_ENABLE_IF(!is_static_named_arg<T>::value)>
1110
FMT_CONSTEXPR void init_static_named_arg(named_arg_info<Char>*, int& arg_index,
1111
0
                                         int&) {
1112
0
  ++arg_index;
1113
0
}
Unexecuted instantiation: _ZN3fmt3v126detail21init_static_named_argIRdcTnNSt3__19enable_ifIXntsr19is_static_named_argIT_EE5valueEiE4typeELi0EEEvPNS1_14named_arg_infoIT0_EERiSD_
Unexecuted instantiation: _ZN3fmt3v126detail21init_static_named_argIRNS0_17basic_string_viewIcEEcTnNSt3__19enable_ifIXntsr19is_static_named_argIT_EE5valueEiE4typeELi0EEEvPNS1_14named_arg_infoIT0_EERiSF_
Unexecuted instantiation: _ZN3fmt3v126detail21init_static_named_argIRA3_KccTnNSt3__19enable_ifIXntsr19is_static_named_argIT_EE5valueEiE4typeELi0EEEvPNS1_14named_arg_infoIT0_EERiSF_
Unexecuted instantiation: _ZN3fmt3v126detail21init_static_named_argIRA7_KccTnNSt3__19enable_ifIXntsr19is_static_named_argIT_EE5valueEiE4typeELi0EEEvPNS1_14named_arg_infoIT0_EERiSF_
Unexecuted instantiation: _ZN3fmt3v126detail21init_static_named_argIRicTnNSt3__19enable_ifIXntsr19is_static_named_argIT_EE5valueEiE4typeELi0EEEvPNS1_14named_arg_infoIT0_EES3_S3_
Unexecuted instantiation: _ZN3fmt3v126detail21init_static_named_argIRjcTnNSt3__19enable_ifIXntsr19is_static_named_argIT_EE5valueEiE4typeELi0EEEvPNS1_14named_arg_infoIT0_EERiSD_
Unexecuted instantiation: _ZN3fmt3v126detail21init_static_named_argIicTnNSt3__19enable_ifIXntsr19is_static_named_argIT_EE5valueEiE4typeELi0EEEvPNS1_14named_arg_infoIT0_EERiSC_
1114
template <typename T, typename Char,
1115
          FMT_ENABLE_IF(is_static_named_arg<T>::value)>
1116
FMT_CONSTEXPR void init_static_named_arg(named_arg_info<Char>* named_args,
1117
                                         int& arg_index, int& named_arg_index) {
1118
  check_for_duplicate<Char>(named_args, named_arg_index, T::name);
1119
  named_args[named_arg_index++] = {T::name, arg_index++};
1120
}
1121
1122
// To minimize the number of types we need to deal with, long is translated
1123
// either to int or to long long depending on its size.
1124
enum { long_short = sizeof(long) == sizeof(int) && FMT_BUILTIN_TYPES };
1125
using long_type = conditional_t<long_short, int, long long>;
1126
using ulong_type = conditional_t<long_short, unsigned, ullong>;
1127
1128
template <typename T>
1129
using format_as_result =
1130
    remove_cvref_t<decltype(format_as(std::declval<const T&>()))>;
1131
template <typename T>
1132
using format_as_member_result =
1133
    remove_cvref_t<decltype(formatter<T>::format_as(std::declval<const T&>()))>;
1134
1135
template <typename T, typename Enable = std::true_type>
1136
struct use_format_as : std::false_type {};
1137
// format_as member is only used to avoid injection into the std namespace.
1138
template <typename T, typename Enable = std::true_type>
1139
struct use_format_as_member : std::false_type {};
1140
1141
// Only map owning types because mapping views can be unsafe.
1142
template <typename T>
1143
struct use_format_as<
1144
    T, bool_constant<std::is_arithmetic<format_as_result<T>>::value>>
1145
    : std::true_type {};
1146
template <typename T>
1147
struct use_format_as_member<
1148
    T, bool_constant<std::is_arithmetic<format_as_member_result<T>>::value>>
1149
    : std::true_type {};
1150
1151
template <typename T, typename U = remove_const_t<T>>
1152
using use_formatter =
1153
    bool_constant<(std::is_class<T>::value || std::is_enum<T>::value ||
1154
                   std::is_union<T>::value || std::is_array<T>::value) &&
1155
                  !has_to_string_view<T>::value && !is_named_arg<T>::value &&
1156
                  !use_format_as<T>::value && !use_format_as_member<U>::value>;
1157
1158
template <typename Char, typename T, typename U = remove_const_t<T>>
1159
auto has_formatter_impl(T* p, buffered_context<Char>* ctx = nullptr)
1160
    -> decltype(formatter<U, Char>().format(*p, *ctx), std::true_type());
1161
template <typename Char> auto has_formatter_impl(...) -> std::false_type;
1162
1163
// T can be const-qualified to check if it is const-formattable.
1164
template <typename T, typename Char> constexpr auto has_formatter() -> bool {
1165
  return decltype(has_formatter_impl<Char>(static_cast<T*>(nullptr)))::value;
1166
}
1167
1168
// Maps formatting argument types to natively supported types or user-defined
1169
// types with formatters. Returns void on errors to be SFINAE-friendly.
1170
template <typename Char> struct type_mapper {
1171
  static auto map(signed char) -> int;
1172
  static auto map(unsigned char) -> unsigned;
1173
  static auto map(short) -> int;
1174
  static auto map(unsigned short) -> unsigned;
1175
  static auto map(int) -> int;
1176
  static auto map(unsigned) -> unsigned;
1177
  static auto map(long) -> long_type;
1178
  static auto map(unsigned long) -> ulong_type;
1179
  static auto map(long long) -> long long;
1180
  static auto map(ullong) -> ullong;
1181
  static auto map(native_int128) -> native_int128;
1182
  static auto map(native_uint128) -> native_uint128;
1183
  static auto map(bool) -> bool;
1184
1185
  template <typename T, FMT_ENABLE_IF(is_code_unit<T>::value)>
1186
  static auto map(T) -> conditional_t<
1187
      std::is_same<T, char>::value || std::is_same<T, Char>::value, Char, void>;
1188
1189
  static auto map(float) -> float;
1190
  static auto map(double) -> double;
1191
  static auto map(long double) -> long double;
1192
1193
  static auto map(Char*) -> const Char*;
1194
  static auto map(const Char*) -> const Char*;
1195
  template <typename T, typename C = char_t<T>,
1196
            FMT_ENABLE_IF(!std::is_pointer<T>::value)>
1197
  static auto map(const T&) -> conditional_t<std::is_same<C, Char>::value,
1198
                                             basic_string_view<C>, void>;
1199
1200
  static auto map(void*) -> const void*;
1201
  static auto map(const void*) -> const void*;
1202
  static auto map(volatile void*) -> const void*;
1203
  static auto map(const volatile void*) -> const void*;
1204
  static auto map(nullptr_t) -> const void*;
1205
  template <typename T, FMT_ENABLE_IF(std::is_pointer<T>::value ||
1206
                                      std::is_member_pointer<T>::value)>
1207
  static auto map(const T&) -> void;
1208
1209
  template <typename T, FMT_ENABLE_IF(use_format_as<T>::value)>
1210
  static auto map(const T& x) -> decltype(map(format_as(x)));
1211
  template <typename T, FMT_ENABLE_IF(use_format_as_member<T>::value)>
1212
  static auto map(const T& x) -> decltype(map(formatter<T>::format_as(x)));
1213
1214
  template <typename T, FMT_ENABLE_IF(use_formatter<T>::value)>
1215
  static auto map(T&) -> conditional_t<has_formatter<T, Char>(), T&, void>;
1216
1217
  template <typename T, FMT_ENABLE_IF(is_named_arg<T>::value)>
1218
  static auto map(const T& named_arg) -> decltype(map(named_arg.value));
1219
};
1220
1221
// detail:: is used to workaround a bug in MSVC 2017.
1222
template <typename T, typename Char>
1223
using mapped_t = decltype(detail::type_mapper<Char>::map(std::declval<T&>()));
1224
1225
// A type constant after applying type_mapper.
1226
template <typename T, typename Char = char>
1227
using mapped_type_constant = type_constant<mapped_t<T, Char>, Char>;
1228
1229
template <typename T, typename Context,
1230
          type TYPE =
1231
              mapped_type_constant<T, typename Context::char_type>::value>
1232
using stored_type_constant = std::integral_constant<
1233
    type, Context::builtin_types || TYPE == type::int_type ? TYPE
1234
                                                           : type::custom_type>;
1235
// A parse context with extra data used only in compile-time checks.
1236
template <typename Char>
1237
class compile_parse_context : public parse_context<Char> {
1238
 private:
1239
  int num_args_;
1240
  const type* types_;
1241
  using base = parse_context<Char>;
1242
1243
 public:
1244
  constexpr explicit compile_parse_context(basic_string_view<Char> fmt,
1245
                                           int num_args, const type* types,
1246
                                           int next_arg_id = 0)
1247
      : base(fmt, next_arg_id), num_args_(num_args), types_(types) {}
1248
1249
0
  constexpr auto num_args() const -> int { return num_args_; }
1250
  constexpr auto arg_type(int id) const -> type { return types_[id]; }
1251
1252
0
  FMT_CONSTEXPR auto next_arg_id() -> int {
1253
0
    int id = base::next_arg_id();
1254
0
    if (id >= num_args_) report_error("argument not found");
1255
0
    return id;
1256
0
  }
1257
1258
0
  FMT_CONSTEXPR void check_arg_id(int id) {
1259
0
    base::check_arg_id(id);
1260
0
    if (id >= num_args_) report_error("argument not found");
1261
0
  }
1262
  using base::check_arg_id;
1263
1264
0
  FMT_CONSTEXPR void check_dynamic_spec(int arg_id) {
1265
0
    if (arg_id < num_args_ && types_ && !is_integral_type(types_[arg_id]))
1266
0
      report_error("width/precision is not integer");
1267
0
  }
1268
};
1269
1270
// An argument reference.
1271
template <typename Char> union arg_ref {
1272
2.09k
  FMT_CONSTEXPR arg_ref(int idx = 0) : index(idx) {}
1273
0
  FMT_CONSTEXPR arg_ref(basic_string_view<Char> n) : name(n) {}
1274
1275
  int index;
1276
  basic_string_view<Char> name;
1277
};
1278
1279
// Format specifiers with width and precision resolved at formatting rather
1280
// than parsing time to allow reusing the same parsed specifiers with
1281
// different sets of arguments (precompilation of format strings).
1282
template <typename Char = char> struct dynamic_format_specs : format_specs {
1283
  arg_ref<Char> width_ref;
1284
  arg_ref<Char> precision_ref;
1285
};
1286
1287
// Converts a character to ASCII. Returns '\0' on conversion failure.
1288
template <typename Char, FMT_ENABLE_IF(std::is_integral<Char>::value)>
1289
3.13k
constexpr auto to_ascii(Char c) -> char {
1290
3.13k
  return c <= 0xff ? char(c) : '\0';
1291
3.13k
}
1292
1293
// Returns the number of code units in a code point or 1 on error.
1294
template <typename Char>
1295
0
FMT_CONSTEXPR auto code_point_length(const Char* begin) -> int {
1296
0
  if FMT_CONSTEXPR20 (sizeof(Char) != 1) return 1;
1297
0
  auto c = static_cast<unsigned char>(*begin);
1298
0
  return static_cast<int>((0x3a55000000000000ull >> (2 * (c >> 3))) & 3) + 1;
1299
0
}
1300
1301
// Parses the range [begin, end) as an unsigned integer. This function assumes
1302
// that the range is non-empty and the first character is a digit.
1303
template <typename Char>
1304
FMT_CONSTEXPR auto parse_nonnegative_int(const Char*& begin, const Char* end,
1305
1.04k
                                         int error_value) noexcept -> int {
1306
1.04k
  FMT_ASSERT(begin != end && '0' <= *begin && *begin <= '9', "");
1307
1.04k
  unsigned value = 0, prev = 0;
1308
1.04k
  auto p = begin;
1309
2.09k
  do {
1310
2.09k
    prev = value;
1311
2.09k
    value = value * 10 + unsigned(*p - '0');
1312
2.09k
    ++p;
1313
2.09k
  } while (p != end && '0' <= *p && *p <= '9');
1314
1.04k
  auto num_digits = p - begin;
1315
1.04k
  begin = p;
1316
1.04k
  int digits10 = int(sizeof(int) * CHAR_BIT * 3 / 10);
1317
1.04k
  if (num_digits <= digits10) return int(value);
1318
  // Check for overflow.
1319
0
  unsigned max = INT_MAX;
1320
0
  return num_digits == digits10 + 1 &&
1321
0
                 prev * 10ull + unsigned(p[-1] - '0') <= max
1322
0
             ? int(value)
1323
0
             : error_value;
1324
1.04k
}
1325
1326
1.04k
FMT_CONSTEXPR inline auto parse_align(char c) -> align {
1327
1.04k
  switch (c) {
1328
0
  case '<': return align::left;
1329
0
  case '>': return align::right;
1330
0
  case '^': return align::center;
1331
1.04k
  }
1332
1.04k
  return align::none;
1333
1.04k
}
1334
1335
0
template <typename Char> constexpr auto is_name_start(Char c) -> bool {
1336
0
  return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '_';
1337
0
}
1338
1339
template <typename Char, typename Handler>
1340
FMT_CONSTEXPR auto parse_arg_id(const Char* begin, const Char* end,
1341
0
                                Handler&& handler) -> const Char* {
1342
0
  Char c = *begin;
1343
0
  if (c >= '0' && c <= '9') {
1344
0
    int index = 0;
1345
0
    if (c != '0')
1346
0
      index = parse_nonnegative_int(begin, end, INT_MAX);
1347
0
    else
1348
0
      ++begin;
1349
0
    if (begin == end || (*begin != '}' && *begin != ':'))
1350
0
      report_error("invalid format string");
1351
0
    else
1352
0
      handler.on_index(index);
1353
0
    return begin;
1354
0
  }
1355
0
  if (FMT_OPTIMIZE_SIZE > 1 || !is_name_start(c)) {
1356
0
    report_error("invalid format string");
1357
0
    return begin;
1358
0
  }
1359
0
  auto it = begin;
1360
0
  do {
1361
0
    ++it;
1362
0
  } while (it != end && (is_name_start(*it) || ('0' <= *it && *it <= '9')));
1363
0
  handler.on_name({begin, to_unsigned(it - begin)});
1364
0
  return it;
1365
0
}
Unexecuted instantiation: char const* fmt::v12::detail::parse_arg_id<char, fmt::v12::detail::dynamic_spec_handler<char> >(char const*, char const*, fmt::v12::detail::dynamic_spec_handler<char>&&)
Unexecuted instantiation: char const* fmt::v12::detail::parse_arg_id<char, fmt::v12::detail::parse_replacement_field<char, fmt::v12::detail::format_string_checker<char, 1, 0, false>&>(char const*, char const*, fmt::v12::detail::format_string_checker<char, 1, 0, false>&)::id_adapter&>(char const*, char const*, fmt::v12::detail::format_string_checker<char, 1, 0, false>&)
Unexecuted instantiation: char const* fmt::v12::detail::parse_arg_id<char, fmt::v12::detail::parse_replacement_field<char, fmt::v12::detail::format_handler<char>&>(char const*, char const*, fmt::v12::detail::format_handler<char>&)::id_adapter&>(char const*, char const*, fmt::v12::detail::format_handler<char>&)
Unexecuted instantiation: char const* fmt::v12::detail::parse_arg_id<char, fmt::v12::detail::parse_replacement_field<char, fmt::v12::detail::format_string_checker<char, 2, 0, false>&>(char const*, char const*, fmt::v12::detail::format_string_checker<char, 2, 0, false>&)::id_adapter&>(char const*, char const*, fmt::v12::detail::format_string_checker<char, 2, 0, false>&)
Unexecuted instantiation: char const* fmt::v12::detail::parse_arg_id<char, fmt::v12::detail::parse_replacement_field<char, fmt::v12::detail::format_string_checker<char, 0, 0, false>&>(char const*, char const*, fmt::v12::detail::format_string_checker<char, 0, 0, false>&)::id_adapter&>(char const*, char const*, fmt::v12::detail::format_string_checker<char, 0, 0, false>&)
1366
1367
template <typename Char> struct dynamic_spec_handler {
1368
  parse_context<Char>& ctx;
1369
  arg_ref<Char>& ref;
1370
  arg_id_kind& kind;
1371
1372
0
  FMT_CONSTEXPR void on_index(int id) {
1373
0
    ref = id;
1374
0
    kind = arg_id_kind::index;
1375
0
    ctx.check_arg_id(id);
1376
0
    ctx.check_dynamic_spec(id);
1377
0
  }
1378
0
  FMT_CONSTEXPR void on_name(basic_string_view<Char> id) {
1379
0
    ref = id;
1380
0
    kind = arg_id_kind::name;
1381
0
    ctx.check_arg_id(id);
1382
0
  }
1383
};
1384
1385
template <typename Char> struct parse_dynamic_spec_result {
1386
  const Char* end;
1387
  arg_id_kind kind;
1388
};
1389
1390
// Parses integer | "{" [arg_id] "}".
1391
template <typename Char>
1392
FMT_CONSTEXPR auto parse_dynamic_spec(const Char* begin, const Char* end,
1393
                                      int& value, arg_ref<Char>& ref,
1394
                                      parse_context<Char>& ctx)
1395
1.04k
    -> parse_dynamic_spec_result<Char> {
1396
1.04k
  FMT_ASSERT(begin != end, "");
1397
1.04k
  auto kind = arg_id_kind::none;
1398
1.04k
  if ('0' <= *begin && *begin <= '9') {
1399
1.04k
    int val = parse_nonnegative_int(begin, end, -1);
1400
1.04k
    if (val == -1) report_error("number is too big");
1401
1.04k
    value = val;
1402
1.04k
  } else {
1403
0
    if (*begin == '{') {
1404
0
      ++begin;
1405
0
      if (begin != end) {
1406
0
        Char c = *begin;
1407
0
        if (c == '}' || c == ':') {
1408
0
          int id = ctx.next_arg_id();
1409
0
          ref = id;
1410
0
          kind = arg_id_kind::index;
1411
0
          ctx.check_dynamic_spec(id);
1412
0
        } else {
1413
0
          begin = parse_arg_id(begin, end,
1414
0
                               dynamic_spec_handler<Char>{ctx, ref, kind});
1415
0
        }
1416
0
      }
1417
0
      if (begin != end && *begin == '}') return {++begin, kind};
1418
0
    }
1419
0
    report_error("invalid format string");
1420
0
  }
1421
1.04k
  return {begin, kind};
1422
1.04k
}
1423
1424
template <typename Char>
1425
FMT_CONSTEXPR auto parse_width(const Char* begin, const Char* end,
1426
                               format_specs& specs, arg_ref<Char>& width_ref,
1427
0
                               parse_context<Char>& ctx) -> const Char* {
1428
0
  auto result = parse_dynamic_spec(begin, end, specs.width, width_ref, ctx);
1429
0
  specs.set_dynamic_width(result.kind);
1430
0
  return result.end;
1431
0
}
1432
1433
template <typename Char>
1434
FMT_CONSTEXPR auto parse_precision(const Char* begin, const Char* end,
1435
                                   format_specs& specs,
1436
                                   arg_ref<Char>& precision_ref,
1437
1.04k
                                   parse_context<Char>& ctx) -> const Char* {
1438
1.04k
  ++begin;
1439
1.04k
  if (begin == end) {
1440
0
    report_error("invalid precision");
1441
0
    return begin;
1442
0
  }
1443
1.04k
  auto result =
1444
1.04k
      parse_dynamic_spec(begin, end, specs.precision, precision_ref, ctx);
1445
1.04k
  specs.set_dynamic_precision(result.kind);
1446
1.04k
  return result.end;
1447
1.04k
}
1448
1449
enum class state { start, align, sign, hash, zero, width, precision, locale };
1450
1451
// Parses standard format specifiers.
1452
template <typename Char>
1453
FMT_CONSTEXPR auto parse_format_specs(const Char* begin, const Char* end,
1454
                                      dynamic_format_specs<Char>& specs,
1455
                                      parse_context<Char>& ctx, type arg_type)
1456
1.04k
    -> const Char* {
1457
1.04k
  auto c = '\0';
1458
1.04k
  if (end - begin > 1) {
1459
1.04k
    auto next = to_ascii(begin[1]);
1460
1.04k
    c = parse_align(next) == align::none ? to_ascii(*begin) : '\0';
1461
1.04k
  } else {
1462
0
    if (begin == end) return begin;
1463
0
    c = to_ascii(*begin);
1464
0
  }
1465
1466
1.04k
  struct {
1467
1.04k
    state current_state = state::start;
1468
1.04k
    FMT_CONSTEXPR void operator()(state s, bool valid = true) {
1469
1.04k
      if (current_state >= s || !valid)
1470
0
        report_error("invalid format specifier");
1471
1.04k
      current_state = s;
1472
1.04k
    }
1473
1.04k
  } enter_state;
1474
1475
1.04k
  using pres = presentation_type;
1476
1.04k
  constexpr auto integral_set = sint_set | uint_set | bool_set | char_set;
1477
1.04k
  struct {
1478
1.04k
    const Char*& begin;
1479
1.04k
    format_specs& specs;
1480
1.04k
    type arg_type;
1481
1482
1.04k
    FMT_CONSTEXPR auto operator()(pres pres_type, int set) -> const Char* {
1483
1.04k
      if (!in(arg_type, set)) report_error("invalid format specifier");
1484
1.04k
      specs.set_type(pres_type);
1485
1.04k
      return begin + 1;
1486
1.04k
    }
1487
1.04k
  } parse_presentation_type{begin, specs, arg_type};
1488
1489
2.09k
  for (;;) {
1490
2.09k
    switch (c) {
1491
0
    case '<':
1492
0
    case '>':
1493
0
    case '^':
1494
0
      enter_state(state::align);
1495
0
      specs.set_align(parse_align(c));
1496
0
      ++begin;
1497
0
      break;
1498
0
    case '+':
1499
0
    case ' ':
1500
0
      specs.set_sign(c == ' ' ? sign::space : sign::plus);
1501
0
      FMT_FALLTHROUGH;
1502
0
    case '-':
1503
0
      enter_state(state::sign, in(arg_type, sint_set | float_set));
1504
0
      ++begin;
1505
0
      break;
1506
0
    case '#':
1507
0
      enter_state(state::hash, is_arithmetic_type(arg_type));
1508
0
      specs.set_alt();
1509
0
      ++begin;
1510
0
      break;
1511
0
    case '0':
1512
0
      enter_state(state::zero);
1513
0
      if (!is_arithmetic_type(arg_type))
1514
0
        report_error("format specifier requires numeric argument");
1515
0
      if (specs.align() == align::none) {
1516
        // Ignore 0 if align is specified for compatibility with std::format.
1517
0
        specs.set_align(align::numeric);
1518
0
        specs.set_fill('0');
1519
0
      }
1520
0
      ++begin;
1521
0
      break;
1522
      // clang-format off
1523
0
    case '1': case '2': case '3': case '4': case '5':
1524
0
    case '6': case '7': case '8': case '9': case '{':
1525
      // clang-format on
1526
0
      enter_state(state::width);
1527
0
      begin = parse_width(begin, end, specs, specs.width_ref, ctx);
1528
0
      break;
1529
1.04k
    case '.':
1530
1.04k
      enter_state(state::precision,
1531
1.04k
                  in(arg_type, float_set | string_set | cstring_set));
1532
1.04k
      begin = parse_precision(begin, end, specs, specs.precision_ref, ctx);
1533
1.04k
      break;
1534
0
    case 'L':
1535
0
      enter_state(state::locale, is_arithmetic_type(arg_type));
1536
0
      specs.set_localized();
1537
0
      ++begin;
1538
0
      break;
1539
0
    case 'd': return parse_presentation_type(pres::dec, integral_set);
1540
0
    case 'X': specs.set_upper(); FMT_FALLTHROUGH;
1541
0
    case 'x': return parse_presentation_type(pres::hex, integral_set);
1542
0
    case 'o': return parse_presentation_type(pres::oct, integral_set);
1543
0
    case 'B': specs.set_upper(); FMT_FALLTHROUGH;
1544
0
    case 'b': return parse_presentation_type(pres::bin, integral_set);
1545
0
    case 'E': specs.set_upper(); FMT_FALLTHROUGH;
1546
0
    case 'e': return parse_presentation_type(pres::exp, float_set);
1547
0
    case 'F': specs.set_upper(); FMT_FALLTHROUGH;
1548
0
    case 'f': return parse_presentation_type(pres::fixed, float_set);
1549
0
    case 'G': specs.set_upper(); FMT_FALLTHROUGH;
1550
1.04k
    case 'g': return parse_presentation_type(pres::general, float_set);
1551
0
    case 'A': specs.set_upper(); FMT_FALLTHROUGH;
1552
0
    case 'a': return parse_presentation_type(pres::hexfloat, float_set);
1553
0
    case 'c':
1554
0
      if (arg_type == type::bool_type) report_error("invalid format specifier");
1555
0
      return parse_presentation_type(pres::chr, integral_set);
1556
0
    case 's':
1557
0
      return parse_presentation_type(pres::string,
1558
0
                                     bool_set | string_set | cstring_set);
1559
0
    case 'p':
1560
0
      return parse_presentation_type(pres::pointer, pointer_set | cstring_set);
1561
0
    case '?':
1562
0
      return parse_presentation_type(pres::debug,
1563
0
                                     char_set | string_set | cstring_set);
1564
0
    case '}': return begin;
1565
0
    default:  {
1566
0
      if (*begin == '}') return begin;
1567
      // Parse fill and alignment.
1568
0
      auto fill_end = begin + code_point_length(begin);
1569
0
      if (end - fill_end <= 0) {
1570
0
        report_error("invalid format specifier");
1571
0
        return begin;
1572
0
      }
1573
0
      if (*begin == '{') {
1574
0
        report_error("invalid fill character '{'");
1575
0
        return begin;
1576
0
      }
1577
0
      auto alignment = parse_align(to_ascii(*fill_end));
1578
0
      enter_state(state::align, alignment != align::none);
1579
0
      specs.set_fill(
1580
0
          basic_string_view<Char>(begin, to_unsigned(fill_end - begin)));
1581
0
      specs.set_align(alignment);
1582
0
      begin = fill_end + 1;
1583
0
    }
1584
2.09k
    }
1585
1.04k
    if (begin == end) return begin;
1586
1.04k
    c = to_ascii(*begin);
1587
1.04k
  }
1588
1.04k
}
1589
1590
template <typename Char, typename Handler>
1591
FMT_CONSTEXPR FMT_INLINE auto parse_replacement_field(const Char* begin,
1592
                                                      const Char* end,
1593
                                                      Handler&& handler)
1594
1.04k
    -> const Char* {
1595
1.04k
  ++begin;
1596
1.04k
  if (begin == end) {
1597
0
    handler.on_error("invalid format string");
1598
0
    return end;
1599
0
  }
1600
1.04k
  int arg_id = 0;
1601
1.04k
  switch (*begin) {
1602
0
  case '}':
1603
0
    handler.on_replacement_field(handler.on_arg_id(), begin);
1604
0
    return begin + 1;
1605
0
  case '{': handler.on_text(begin, begin + 1); return begin + 1;
1606
1.04k
  case ':': arg_id = handler.on_arg_id(); break;
1607
0
  default:  {
1608
0
    struct id_adapter {
1609
0
      Handler& handler;
1610
0
      int arg_id;
1611
1612
0
      FMT_CONSTEXPR void on_index(int id) { arg_id = handler.on_arg_id(id); }
Unexecuted instantiation: fmt::v12::detail::parse_replacement_field<char, fmt::v12::detail::format_string_checker<char, 1, 0, false>&>(char const*, char const*, fmt::v12::detail::format_string_checker<char, 1, 0, false>&)::id_adapter::on_index(int)
Unexecuted instantiation: fmt::v12::detail::parse_replacement_field<char, fmt::v12::detail::format_handler<char>&>(char const*, char const*, fmt::v12::detail::format_handler<char>&)::id_adapter::on_index(int)
Unexecuted instantiation: fmt::v12::detail::parse_replacement_field<char, fmt::v12::detail::format_string_checker<char, 2, 0, false>&>(char const*, char const*, fmt::v12::detail::format_string_checker<char, 2, 0, false>&)::id_adapter::on_index(int)
Unexecuted instantiation: fmt::v12::detail::parse_replacement_field<char, fmt::v12::detail::format_string_checker<char, 0, 0, false>&>(char const*, char const*, fmt::v12::detail::format_string_checker<char, 0, 0, false>&)::id_adapter::on_index(int)
1613
0
      FMT_CONSTEXPR void on_name(basic_string_view<Char> id) {
1614
0
        arg_id = handler.on_arg_id(id);
1615
0
      }
Unexecuted instantiation: fmt::v12::detail::parse_replacement_field<char, fmt::v12::detail::format_string_checker<char, 1, 0, false>&>(char const*, char const*, fmt::v12::detail::format_string_checker<char, 1, 0, false>&)::id_adapter::on_name(fmt::v12::basic_string_view<char>)
Unexecuted instantiation: fmt::v12::detail::parse_replacement_field<char, fmt::v12::detail::format_handler<char>&>(char const*, char const*, fmt::v12::detail::format_handler<char>&)::id_adapter::on_name(fmt::v12::basic_string_view<char>)
Unexecuted instantiation: fmt::v12::detail::parse_replacement_field<char, fmt::v12::detail::format_string_checker<char, 2, 0, false>&>(char const*, char const*, fmt::v12::detail::format_string_checker<char, 2, 0, false>&)::id_adapter::on_name(fmt::v12::basic_string_view<char>)
Unexecuted instantiation: fmt::v12::detail::parse_replacement_field<char, fmt::v12::detail::format_string_checker<char, 0, 0, false>&>(char const*, char const*, fmt::v12::detail::format_string_checker<char, 0, 0, false>&)::id_adapter::on_name(fmt::v12::basic_string_view<char>)
1616
0
    } adapter = {handler, 0};
1617
0
    begin = parse_arg_id(begin, end, adapter);
1618
0
    arg_id = adapter.arg_id;
1619
0
    Char c = begin != end ? *begin : Char();
1620
0
    if (c == '}') {
1621
0
      handler.on_replacement_field(arg_id, begin);
1622
0
      return begin + 1;
1623
0
    }
1624
0
    if (c != ':') {
1625
0
      handler.on_error("missing '}' in format string");
1626
0
      return end;
1627
0
    }
1628
0
    break;
1629
0
  }
1630
1.04k
  }
1631
1.04k
  begin = handler.on_format_specs(arg_id, begin + 1, end);
1632
1.04k
  if (begin == end || *begin != '}')
1633
0
    return handler.on_error("unknown format specifier"), end;
1634
1.04k
  return begin + 1;
1635
1.04k
}
Unexecuted instantiation: char const* fmt::v12::detail::parse_replacement_field<char, fmt::v12::detail::format_string_checker<char, 1, 0, false>&>(char const*, char const*, fmt::v12::detail::format_string_checker<char, 1, 0, false>&)
char const* fmt::v12::detail::parse_replacement_field<char, fmt::v12::detail::format_handler<char>&>(char const*, char const*, fmt::v12::detail::format_handler<char>&)
Line
Count
Source
1594
1.04k
    -> const Char* {
1595
1.04k
  ++begin;
1596
1.04k
  if (begin == end) {
1597
0
    handler.on_error("invalid format string");
1598
0
    return end;
1599
0
  }
1600
1.04k
  int arg_id = 0;
1601
1.04k
  switch (*begin) {
1602
0
  case '}':
1603
0
    handler.on_replacement_field(handler.on_arg_id(), begin);
1604
0
    return begin + 1;
1605
0
  case '{': handler.on_text(begin, begin + 1); return begin + 1;
1606
1.04k
  case ':': arg_id = handler.on_arg_id(); break;
1607
0
  default:  {
1608
0
    struct id_adapter {
1609
0
      Handler& handler;
1610
0
      int arg_id;
1611
1612
0
      FMT_CONSTEXPR void on_index(int id) { arg_id = handler.on_arg_id(id); }
1613
0
      FMT_CONSTEXPR void on_name(basic_string_view<Char> id) {
1614
0
        arg_id = handler.on_arg_id(id);
1615
0
      }
1616
0
    } adapter = {handler, 0};
1617
0
    begin = parse_arg_id(begin, end, adapter);
1618
0
    arg_id = adapter.arg_id;
1619
0
    Char c = begin != end ? *begin : Char();
1620
0
    if (c == '}') {
1621
0
      handler.on_replacement_field(arg_id, begin);
1622
0
      return begin + 1;
1623
0
    }
1624
0
    if (c != ':') {
1625
0
      handler.on_error("missing '}' in format string");
1626
0
      return end;
1627
0
    }
1628
0
    break;
1629
0
  }
1630
1.04k
  }
1631
1.04k
  begin = handler.on_format_specs(arg_id, begin + 1, end);
1632
1.04k
  if (begin == end || *begin != '}')
1633
0
    return handler.on_error("unknown format specifier"), end;
1634
1.04k
  return begin + 1;
1635
1.04k
}
Unexecuted instantiation: char const* fmt::v12::detail::parse_replacement_field<char, fmt::v12::detail::format_string_checker<char, 2, 0, false>&>(char const*, char const*, fmt::v12::detail::format_string_checker<char, 2, 0, false>&)
Unexecuted instantiation: char const* fmt::v12::detail::parse_replacement_field<char, fmt::v12::detail::format_string_checker<char, 0, 0, false>&>(char const*, char const*, fmt::v12::detail::format_string_checker<char, 0, 0, false>&)
1636
1637
template <typename Char, typename Handler>
1638
FMT_CONSTEXPR void parse_format_string(basic_string_view<Char> fmt,
1639
1.04k
                                       Handler&& handler) {
1640
1.04k
  auto begin = fmt.data(), end = begin + fmt.size();
1641
1.04k
  auto p = begin;
1642
2.09k
  while (p != end) {
1643
1.04k
    auto c = *p++;
1644
1.04k
    if (c == '{') {
1645
1.04k
      handler.on_text(begin, p - 1);
1646
1.04k
      begin = p = parse_replacement_field(p - 1, end, handler);
1647
1.04k
    } else if (c == '}') {
1648
0
      if (p == end || *p != '}')
1649
0
        return handler.on_error("unmatched '}' in format string");
1650
0
      handler.on_text(begin, p);
1651
0
      begin = ++p;
1652
0
    }
1653
1.04k
  }
1654
1.04k
  handler.on_text(begin, end);
1655
1.04k
}
Unexecuted instantiation: void fmt::v12::detail::parse_format_string<char, fmt::v12::detail::format_string_checker<char, 1, 0, false> >(fmt::v12::basic_string_view<char>, fmt::v12::detail::format_string_checker<char, 1, 0, false>&&)
void fmt::v12::detail::parse_format_string<char, fmt::v12::detail::format_handler<char> >(fmt::v12::basic_string_view<char>, fmt::v12::detail::format_handler<char>&&)
Line
Count
Source
1639
1.04k
                                       Handler&& handler) {
1640
1.04k
  auto begin = fmt.data(), end = begin + fmt.size();
1641
1.04k
  auto p = begin;
1642
2.09k
  while (p != end) {
1643
1.04k
    auto c = *p++;
1644
1.04k
    if (c == '{') {
1645
1.04k
      handler.on_text(begin, p - 1);
1646
1.04k
      begin = p = parse_replacement_field(p - 1, end, handler);
1647
1.04k
    } else if (c == '}') {
1648
0
      if (p == end || *p != '}')
1649
0
        return handler.on_error("unmatched '}' in format string");
1650
0
      handler.on_text(begin, p);
1651
0
      begin = ++p;
1652
0
    }
1653
1.04k
  }
1654
1.04k
  handler.on_text(begin, end);
1655
1.04k
}
Unexecuted instantiation: void fmt::v12::detail::parse_format_string<char, fmt::v12::detail::format_string_checker<char, 2, 0, false> >(fmt::v12::basic_string_view<char>, fmt::v12::detail::format_string_checker<char, 2, 0, false>&&)
Unexecuted instantiation: void fmt::v12::detail::parse_format_string<char, fmt::v12::detail::format_string_checker<char, 0, 0, false> >(fmt::v12::basic_string_view<char>, fmt::v12::detail::format_string_checker<char, 0, 0, false>&&)
1656
1657
// Checks char specs and returns true iff the presentation type is char-like.
1658
0
FMT_CONSTEXPR inline auto check_char_specs(const format_specs& specs) -> bool {
1659
0
  auto type = specs.type();
1660
0
  if (type != presentation_type::none && type != presentation_type::chr &&
1661
0
      type != presentation_type::debug) {
1662
0
    return false;
1663
0
  }
1664
0
  if (specs.align() == align::numeric || specs.sign() != sign::none ||
1665
0
      specs.alt()) {
1666
0
    report_error("invalid format specifier for char");
1667
0
  }
1668
0
  return true;
1669
0
}
1670
1671
// A base class for compile-time strings.
1672
struct compile_string {};
1673
1674
template <typename T, typename Char>
1675
FMT_VISIBILITY("hidden")  // Suppress an ld warning on macOS (#3769).
1676
0
FMT_CONSTEXPR auto invoke_parse(parse_context<Char>& ctx) -> const Char* {
1677
0
  using mapped_type = remove_cvref_t<mapped_t<T, Char>>;
1678
0
  constexpr bool formattable =
1679
0
      std::is_constructible<formatter<mapped_type, Char>>::value;
1680
0
  if (!formattable) return ctx.begin();  // Error is reported in the value ctor.
1681
0
  using formatted_type = conditional_t<formattable, mapped_type, int>;
1682
0
  return formatter<formatted_type, Char>().parse(ctx);
1683
0
}
Unexecuted instantiation: char const* fmt::v12::detail::invoke_parse<double&, char>(fmt::v12::parse_context<char>&)
Unexecuted instantiation: char const* fmt::v12::detail::invoke_parse<fmt::v12::basic_string_view<char>&, char>(fmt::v12::parse_context<char>&)
Unexecuted instantiation: char const* fmt::v12::detail::invoke_parse<char const (&) [3], char>(fmt::v12::parse_context<char>&)
Unexecuted instantiation: char const* fmt::v12::detail::invoke_parse<char const (&) [7], char>(fmt::v12::parse_context<char>&)
Unexecuted instantiation: char const* fmt::v12::detail::invoke_parse<int&, char>(fmt::v12::parse_context<char>&)
Unexecuted instantiation: char const* fmt::v12::detail::invoke_parse<unsigned int&, char>(fmt::v12::parse_context<char>&)
Unexecuted instantiation: char const* fmt::v12::detail::invoke_parse<int, char>(fmt::v12::parse_context<char>&)
1684
1685
template <typename... T> struct arg_pack {};
1686
1687
template <typename Char, int NUM_ARGS, int NUM_NAMED_ARGS, bool DYNAMIC_NAMES>
1688
class format_string_checker {
1689
 private:
1690
  type types_[max_of<size_t>(1, NUM_ARGS)];
1691
  named_arg_info<Char> named_args_[max_of<size_t>(1, NUM_NAMED_ARGS)];
1692
  compile_parse_context<Char> context_;
1693
1694
  using parse_func = auto (*)(parse_context<Char>&) -> const Char*;
1695
  parse_func parse_funcs_[max_of<size_t>(1, NUM_ARGS)];
1696
1697
 public:
1698
  template <typename... T>
1699
  FMT_CONSTEXPR explicit format_string_checker(basic_string_view<Char> fmt,
1700
                                               arg_pack<T...>)
1701
      : types_{mapped_type_constant<T, Char>::value...},
1702
        named_args_{},
1703
        context_(fmt, NUM_ARGS, types_),
1704
        parse_funcs_{&invoke_parse<T, Char>...} {
1705
    int arg_index = 0, named_arg_index = 0;
1706
    FMT_APPLY_VARIADIC(
1707
        init_static_named_arg<T>(named_args_, arg_index, named_arg_index));
1708
    ignore_unused(arg_index, named_arg_index);
1709
  }
1710
1711
0
  FMT_CONSTEXPR void on_text(const Char*, const Char*) {}
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 1, 0, false>::on_text(char const*, char const*)
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 2, 0, false>::on_text(char const*, char const*)
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 0, 0, false>::on_text(char const*, char const*)
1712
1713
0
  FMT_CONSTEXPR auto on_arg_id() -> int { return context_.next_arg_id(); }
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 1, 0, false>::on_arg_id()
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 2, 0, false>::on_arg_id()
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 0, 0, false>::on_arg_id()
1714
0
  FMT_CONSTEXPR auto on_arg_id(int id) -> int {
1715
0
    context_.check_arg_id(id);
1716
0
    return id;
1717
0
  }
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 1, 0, false>::on_arg_id(int)
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 2, 0, false>::on_arg_id(int)
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 0, 0, false>::on_arg_id(int)
1718
0
  FMT_CONSTEXPR auto on_arg_id(basic_string_view<Char> id) -> int {
1719
0
    for (int i = 0; i < NUM_NAMED_ARGS; ++i) {
1720
0
      if (named_args_[i].name == id) return named_args_[i].id;
1721
0
    }
1722
0
    if (!DYNAMIC_NAMES) on_error("argument not found");
1723
0
    return -1;
1724
0
  }
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 1, 0, false>::on_arg_id(fmt::v12::basic_string_view<char>)
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 2, 0, false>::on_arg_id(fmt::v12::basic_string_view<char>)
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 0, 0, false>::on_arg_id(fmt::v12::basic_string_view<char>)
1725
1726
0
  FMT_CONSTEXPR void on_replacement_field(int id, const Char* begin) {
1727
0
    on_format_specs(id, begin, begin);  // Call parse() on empty specs.
1728
0
  }
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 1, 0, false>::on_replacement_field(int, char const*)
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 2, 0, false>::on_replacement_field(int, char const*)
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 0, 0, false>::on_replacement_field(int, char const*)
1729
1730
  FMT_CONSTEXPR auto on_format_specs(int id, const Char* begin, const Char* end)
1731
0
      -> const Char* {
1732
0
    context_.advance_to(begin);
1733
0
    if (id >= 0 && id < NUM_ARGS) return parse_funcs_[id](context_);
1734
0
1735
0
    // If id is out of range, it means we do not know the type and cannot parse
1736
0
    // the format at compile time. Instead, skip over content until we finish
1737
0
    // the format spec, accounting for any nested replacements.
1738
0
    for (int bracket_count = 0;
1739
0
         begin != end && (bracket_count > 0 || *begin != '}'); ++begin) {
1740
0
      if (*begin == '{')
1741
0
        ++bracket_count;
1742
0
      else if (*begin == '}')
1743
0
        --bracket_count;
1744
0
    }
1745
0
    return begin;
1746
0
  }
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 1, 0, false>::on_format_specs(int, char const*, char const*)
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 2, 0, false>::on_format_specs(int, char const*, char const*)
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 0, 0, false>::on_format_specs(int, char const*, char const*)
1747
1748
0
  FMT_NORETURN FMT_CONSTEXPR void on_error(const char* message) {
1749
0
    report_error(message);
1750
0
  }
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 1, 0, false>::on_error(char const*)
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 2, 0, false>::on_error(char const*)
Unexecuted instantiation: fmt::v12::detail::format_string_checker<char, 0, 0, false>::on_error(char const*)
1751
};
1752
1753
/// A contiguous memory buffer with an optional growing ability. It is an
1754
/// internal class and shouldn't be used directly, only via `memory_buffer`.
1755
template <typename T> class buffer {
1756
 private:
1757
  T* ptr_;
1758
  size_t size_;
1759
  size_t capacity_;
1760
1761
  using grow_fun = void (*)(buffer& buf, size_t capacity);
1762
  grow_fun grow_;
1763
1764
 protected:
1765
  // Don't initialize ptr_ since it is not accessed to save a few cycles.
1766
  FMT_CONSTEXPR buffer(grow_fun grow, size_t sz) noexcept
1767
0
      : size_(sz), capacity_(sz), grow_(grow) {
1768
0
    if (FMT_MSC_VERSION != 0) ptr_ = nullptr;  // Suppress warning 26495.
1769
0
  }
1770
1771
  constexpr buffer(grow_fun grow, T* p = nullptr, size_t sz = 0,
1772
                   size_t cap = 0) noexcept
1773
11.0k
      : ptr_(p), size_(sz), capacity_(cap), grow_(grow) {}
fmt::v12::detail::buffer<char>::buffer(void (*)(fmt::v12::detail::buffer<char>&, unsigned long), char*, unsigned long, unsigned long)
Line
Count
Source
1773
3.04k
      : ptr_(p), size_(sz), capacity_(cap), grow_(grow) {}
Unexecuted instantiation: fmt::v12::detail::buffer<wchar_t>::buffer(void (*)(fmt::v12::detail::buffer<wchar_t>&, unsigned long), wchar_t*, unsigned long, unsigned long)
fmt::v12::detail::buffer<unsigned int>::buffer(void (*)(fmt::v12::detail::buffer<unsigned int>&, unsigned long), unsigned int*, unsigned long, unsigned long)
Line
Count
Source
1773
8.03k
      : ptr_(p), size_(sz), capacity_(cap), grow_(grow) {}
Unexecuted instantiation: fmt::v12::detail::buffer<int>::buffer(void (*)(fmt::v12::detail::buffer<int>&, unsigned long), int*, unsigned long, unsigned long)
1774
1775
  FMT_CONSTEXPR20 ~buffer() = default;
1776
  buffer(buffer&&) = default;
1777
1778
  /// Sets the buffer data and capacity.
1779
11.0k
  FMT_CONSTEXPR void set(T* buf_data, size_t buf_capacity) noexcept {
1780
11.0k
    ptr_ = buf_data;
1781
11.0k
    capacity_ = buf_capacity;
1782
11.0k
  }
fmt::v12::detail::buffer<char>::set(char*, unsigned long)
Line
Count
Source
1779
3.04k
  FMT_CONSTEXPR void set(T* buf_data, size_t buf_capacity) noexcept {
1780
3.04k
    ptr_ = buf_data;
1781
3.04k
    capacity_ = buf_capacity;
1782
3.04k
  }
Unexecuted instantiation: fmt::v12::detail::buffer<int>::set(int*, unsigned long)
fmt::v12::detail::buffer<unsigned int>::set(unsigned int*, unsigned long)
Line
Count
Source
1779
8.03k
  FMT_CONSTEXPR void set(T* buf_data, size_t buf_capacity) noexcept {
1780
8.03k
    ptr_ = buf_data;
1781
8.03k
    capacity_ = buf_capacity;
1782
8.03k
  }
Unexecuted instantiation: fmt::v12::detail::buffer<wchar_t>::set(wchar_t*, unsigned long)
1783
1784
 public:
1785
  using value_type = T;
1786
  using const_reference = const T&;
1787
1788
  buffer(const buffer&) = delete;
1789
  void operator=(const buffer&) = delete;
1790
1791
  auto begin() noexcept -> T* { return ptr_; }
1792
1.90k
  auto end() noexcept -> T* { return ptr_ + size_; }
1793
1794
  auto begin() const noexcept -> const T* { return ptr_; }
1795
  auto end() const noexcept -> const T* { return ptr_ + size_; }
1796
1797
  /// Returns the size of this buffer.
1798
1.85M
  constexpr auto size() const noexcept -> size_t { return size_; }
fmt::v12::detail::buffer<char>::size() const
Line
Count
Source
1798
5.16k
  constexpr auto size() const noexcept -> size_t { return size_; }
Unexecuted instantiation: fmt::v12::detail::buffer<wchar_t>::size() const
Unexecuted instantiation: fmt::v12::detail::buffer<int>::size() const
fmt::v12::detail::buffer<unsigned int>::size() const
Line
Count
Source
1798
1.84M
  constexpr auto size() const noexcept -> size_t { return size_; }
1799
1800
  /// Returns the capacity of this buffer.
1801
5.01k
  constexpr auto capacity() const noexcept -> size_t { return capacity_; }
fmt::v12::detail::buffer<char>::capacity() const
Line
Count
Source
1801
772
  constexpr auto capacity() const noexcept -> size_t { return capacity_; }
Unexecuted instantiation: fmt::v12::detail::buffer<int>::capacity() const
fmt::v12::detail::buffer<unsigned int>::capacity() const
Line
Count
Source
1801
4.24k
  constexpr auto capacity() const noexcept -> size_t { return capacity_; }
Unexecuted instantiation: fmt::v12::detail::buffer<wchar_t>::capacity() const
1802
1803
  /// Returns a pointer to the buffer data (not null-terminated).
1804
24.0k
  FMT_CONSTEXPR auto data() noexcept -> T* { return ptr_; }
fmt::v12::detail::buffer<char>::data()
Line
Count
Source
1804
6.85k
  FMT_CONSTEXPR auto data() noexcept -> T* { return ptr_; }
fmt::v12::detail::buffer<unsigned int>::data()
Line
Count
Source
1804
17.1k
  FMT_CONSTEXPR auto data() noexcept -> T* { return ptr_; }
Unexecuted instantiation: fmt::v12::detail::buffer<int>::data()
Unexecuted instantiation: fmt::v12::detail::buffer<wchar_t>::data()
1805
461
  FMT_CONSTEXPR auto data() const noexcept -> const T* { return ptr_; }
fmt::v12::detail::buffer<unsigned int>::data() const
Line
Count
Source
1805
461
  FMT_CONSTEXPR auto data() const noexcept -> const T* { return ptr_; }
Unexecuted instantiation: fmt::v12::detail::buffer<char>::data() const
1806
1807
  /// Clears this buffer.
1808
0
  FMT_CONSTEXPR void clear() { size_ = 0; }
Unexecuted instantiation: fmt::v12::detail::buffer<char>::clear()
Unexecuted instantiation: fmt::v12::detail::buffer<unsigned int>::clear()
Unexecuted instantiation: fmt::v12::detail::buffer<int>::clear()
1809
1810
  // Tries resizing the buffer to contain `count` elements. If T is a POD type
1811
  // the new elements may not be initialized.
1812
180k
  FMT_CONSTEXPR void try_resize(size_t count) {
1813
180k
    try_reserve(count);
1814
180k
    size_ = min_of(count, capacity_);
1815
180k
  }
fmt::v12::detail::buffer<unsigned int>::try_resize(unsigned long)
Line
Count
Source
1812
177k
  FMT_CONSTEXPR void try_resize(size_t count) {
1813
177k
    try_reserve(count);
1814
177k
    size_ = min_of(count, capacity_);
1815
177k
  }
fmt::v12::detail::buffer<char>::try_resize(unsigned long)
Line
Count
Source
1812
2.66k
  FMT_CONSTEXPR void try_resize(size_t count) {
1813
2.66k
    try_reserve(count);
1814
2.66k
    size_ = min_of(count, capacity_);
1815
2.66k
  }
Unexecuted instantiation: fmt::v12::detail::buffer<int>::try_resize(unsigned long)
1816
1817
  // Tries increasing the buffer capacity to `new_capacity`. It can increase the
1818
  // capacity by a smaller amount than requested but guarantees there is space
1819
  // for at least one additional element either by increasing the capacity or by
1820
  // flushing the buffer if it is full.
1821
193k
  FMT_CONSTEXPR void try_reserve(size_t new_capacity) {
1822
193k
    if (new_capacity > capacity_) grow_(*this, new_capacity);
1823
193k
  }
fmt::v12::detail::buffer<char>::try_reserve(unsigned long)
Line
Count
Source
1821
11.2k
  FMT_CONSTEXPR void try_reserve(size_t new_capacity) {
1822
11.2k
    if (new_capacity > capacity_) grow_(*this, new_capacity);
1823
11.2k
  }
Unexecuted instantiation: fmt::v12::detail::buffer<int>::try_reserve(unsigned long)
fmt::v12::detail::buffer<unsigned int>::try_reserve(unsigned long)
Line
Count
Source
1821
182k
  FMT_CONSTEXPR void try_reserve(size_t new_capacity) {
1822
182k
    if (new_capacity > capacity_) grow_(*this, new_capacity);
1823
182k
  }
Unexecuted instantiation: fmt::v12::detail::buffer<wchar_t>::try_reserve(unsigned long)
1824
1825
11.2k
  FMT_CONSTEXPR void push_back(const T& value) {
1826
11.2k
    try_reserve(size_ + 1);
1827
11.2k
    ptr_[size_++] = value;
1828
11.2k
  }
fmt::v12::detail::buffer<char>::push_back(char const&)
Line
Count
Source
1825
6.29k
  FMT_CONSTEXPR void push_back(const T& value) {
1826
6.29k
    try_reserve(size_ + 1);
1827
6.29k
    ptr_[size_++] = value;
1828
6.29k
  }
Unexecuted instantiation: fmt::v12::detail::buffer<int>::push_back(int const&)
fmt::v12::detail::buffer<unsigned int>::push_back(unsigned int const&)
Line
Count
Source
1825
4.97k
  FMT_CONSTEXPR void push_back(const T& value) {
1826
4.97k
    try_reserve(size_ + 1);
1827
4.97k
    ptr_[size_++] = value;
1828
4.97k
  }
Unexecuted instantiation: fmt::v12::detail::buffer<wchar_t>::push_back(wchar_t const&)
1829
1830
  /// Appends data to the end of the buffer.
1831
  template <typename U>
1832
4.08k
  FMT_CONSTEXPR20 void append(const U* begin, const U* end) {
1833
4.08k
    static_assert(std::is_same<T, U>() || std::is_same<U, char>(), "");
1834
6.08k
    while (begin != end) {
1835
1.99k
      auto size = size_;
1836
1.99k
      auto free_cap = capacity_ - size;
1837
1.99k
      auto count = to_unsigned(end - begin);
1838
1.99k
      if (free_cap < count) {
1839
0
        grow_(*this, size + count);
1840
0
        size = size_;
1841
0
        free_cap = capacity_ - size;
1842
0
        count = count < free_cap ? count : free_cap;
1843
0
      }
1844
      // A loop is faster than memcpy on small sizes.
1845
1.99k
      T* out = ptr_ + size;
1846
40.5k
      for (size_t i = 0; i < count; ++i) out[i] = static_cast<T>(begin[i]);
1847
1.99k
      size_ += count;
1848
1.99k
      begin += count;
1849
1.99k
    }
1850
4.08k
  }
void fmt::v12::detail::buffer<char>::append<char>(char const*, char const*)
Line
Count
Source
1832
4.08k
  FMT_CONSTEXPR20 void append(const U* begin, const U* end) {
1833
4.08k
    static_assert(std::is_same<T, U>() || std::is_same<U, char>(), "");
1834
6.08k
    while (begin != end) {
1835
1.99k
      auto size = size_;
1836
1.99k
      auto free_cap = capacity_ - size;
1837
1.99k
      auto count = to_unsigned(end - begin);
1838
1.99k
      if (free_cap < count) {
1839
0
        grow_(*this, size + count);
1840
0
        size = size_;
1841
0
        free_cap = capacity_ - size;
1842
0
        count = count < free_cap ? count : free_cap;
1843
0
      }
1844
      // A loop is faster than memcpy on small sizes.
1845
1.99k
      T* out = ptr_ + size;
1846
40.5k
      for (size_t i = 0; i < count; ++i) out[i] = static_cast<T>(begin[i]);
1847
1.99k
      size_ += count;
1848
1.99k
      begin += count;
1849
1.99k
    }
1850
4.08k
  }
Unexecuted instantiation: void fmt::v12::detail::buffer<wchar_t>::append<wchar_t>(wchar_t const*, wchar_t const*)
1851
1852
2.92M
  template <typename Idx> FMT_CONSTEXPR auto operator[](Idx index) -> T& {
1853
2.92M
    return ptr_[index];
1854
2.92M
  }
Unexecuted instantiation: int& fmt::v12::detail::buffer<int>::operator[]<int>(int)
unsigned int& fmt::v12::detail::buffer<unsigned int>::operator[]<int>(int)
Line
Count
Source
1852
1.89M
  template <typename Idx> FMT_CONSTEXPR auto operator[](Idx index) -> T& {
1853
1.89M
    return ptr_[index];
1854
1.89M
  }
unsigned int& fmt::v12::detail::buffer<unsigned int>::operator[]<unsigned long>(unsigned long)
Line
Count
Source
1852
974k
  template <typename Idx> FMT_CONSTEXPR auto operator[](Idx index) -> T& {
1853
974k
    return ptr_[index];
1854
974k
  }
char& fmt::v12::detail::buffer<char>::operator[]<int>(int)
Line
Count
Source
1852
47.6k
  template <typename Idx> FMT_CONSTEXPR auto operator[](Idx index) -> T& {
1853
47.6k
    return ptr_[index];
1854
47.6k
  }
char& fmt::v12::detail::buffer<char>::operator[]<unsigned long>(unsigned long)
Line
Count
Source
1852
13.3k
  template <typename Idx> FMT_CONSTEXPR auto operator[](Idx index) -> T& {
1853
13.3k
    return ptr_[index];
1854
13.3k
  }
1855
  template <typename Idx>
1856
1.50M
  constexpr auto operator[](Idx index) const -> const T& {
1857
1.50M
    return ptr_[index];
1858
1.50M
  }
Unexecuted instantiation: wchar_t const& fmt::v12::detail::buffer<wchar_t>::operator[]<int>(int) const
unsigned int const& fmt::v12::detail::buffer<unsigned int>::operator[]<int>(int) const
Line
Count
Source
1856
686k
  constexpr auto operator[](Idx index) const -> const T& {
1857
686k
    return ptr_[index];
1858
686k
  }
unsigned int const& fmt::v12::detail::buffer<unsigned int>::operator[]<unsigned long>(unsigned long) const
Line
Count
Source
1856
819k
  constexpr auto operator[](Idx index) const -> const T& {
1857
819k
    return ptr_[index];
1858
819k
  }
1859
};
1860
1861
struct buffer_traits {
1862
0
  constexpr explicit buffer_traits(size_t) {}
1863
0
  constexpr auto count() const -> size_t { return 0; }
1864
0
  constexpr auto limit(size_t size) const -> size_t { return size; }
1865
};
1866
1867
class fixed_buffer_traits {
1868
 private:
1869
  size_t count_ = 0;
1870
  size_t limit_;
1871
1872
 public:
1873
0
  constexpr explicit fixed_buffer_traits(size_t limit) : limit_(limit) {}
1874
0
  constexpr auto count() const -> size_t { return count_; }
1875
0
  FMT_CONSTEXPR auto limit(size_t size) -> size_t {
1876
0
    size_t n = limit_ > count_ ? limit_ - count_ : 0;
1877
0
    count_ += size;
1878
0
    return min_of(size, n);
1879
0
  }
1880
};
1881
1882
template <typename OutputIt, typename InputIt, typename = void>
1883
struct has_append : std::false_type {};
1884
1885
template <typename OutputIt, typename InputIt>
1886
struct has_append<OutputIt, InputIt,
1887
                  void_t<decltype(get_container(std::declval<OutputIt>())
1888
                                      .append(std::declval<InputIt>(),
1889
                                              std::declval<InputIt>()))>>
1890
    : std::true_type {};
1891
1892
template <typename OutputIt, typename T, typename = void>
1893
struct has_insert : std::false_type {};
1894
1895
template <typename OutputIt, typename T>
1896
struct has_insert<
1897
    OutputIt, T,
1898
    void_t<decltype(get_container(std::declval<OutputIt>())
1899
                        .insert({}, std::declval<T>(), std::declval<T>()))>>
1900
    : std::true_type {};
1901
1902
// An optimized version of std::copy with the output value type (T).
1903
template <typename T, typename InputIt, typename OutputIt,
1904
          FMT_ENABLE_IF(is_back_insert_iterator<OutputIt>() &&
1905
                        has_append<OutputIt, InputIt>())>
1906
4.08k
FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
1907
4.08k
  get_container(out).append(begin, end);
1908
4.08k
  return out;
1909
4.08k
}
_ZN3fmt3v126detail4copyIcPcNS0_14basic_appenderIcEETnNSt3__19enable_ifIXaacvNS1_23is_back_insert_iteratorIT1_NS6_17integral_constantIbLb1EEEEE_EcvNS1_10has_appendIS9_T0_vEE_EEiE4typeELi0EEES9_SE_SE_S9_
Line
Count
Source
1906
178
FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
1907
178
  get_container(out).append(begin, end);
1908
178
  return out;
1909
178
}
_ZN3fmt3v126detail4copyIcPKcNS0_14basic_appenderIcEETnNSt3__19enable_ifIXaacvNS1_23is_back_insert_iteratorIT1_NS7_17integral_constantIbLb1EEEEE_EcvNS1_10has_appendISA_T0_vEE_EEiE4typeELi0EEESA_SF_SF_SA_
Line
Count
Source
1906
3.91k
FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
1907
3.91k
  get_container(out).append(begin, end);
1908
3.91k
  return out;
1909
3.91k
}
1910
1911
template <typename T, typename InputIt, typename OutputIt,
1912
          FMT_ENABLE_IF(is_back_insert_iterator<OutputIt>() &&
1913
                        !has_append<OutputIt, InputIt>() &&
1914
                        has_insert<OutputIt, InputIt>())>
1915
FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
1916
  auto& c = get_container(out);
1917
  c.insert(c.end(), begin, end);
1918
  return out;
1919
}
1920
1921
template <typename T, typename InputIt, typename OutputIt,
1922
          FMT_ENABLE_IF(!is_back_insert_iterator<OutputIt>() ||
1923
                        !(has_append<OutputIt, InputIt>() ||
1924
                          has_insert<OutputIt, InputIt>()))>
1925
4.70k
FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
1926
20.6k
  while (begin != end) *out++ = static_cast<T>(*begin++);
1927
4.70k
  return out;
1928
4.70k
}
Unexecuted instantiation: _ZN3fmt3v126detail4copyIcPKcPcTnNSt3__19enable_ifIXoontcvNS1_23is_back_insert_iteratorIT1_NS6_17integral_constantIbLb1EEEEE_EntoocvNS1_10has_appendIS9_T0_vEE_EcvNS1_10has_insertIS9_SE_vEE_EEiE4typeELi0EEES9_SE_SE_S9_
_ZN3fmt3v126detail4copyIjPKjPjTnNSt3__19enable_ifIXoontcvNS1_23is_back_insert_iteratorIT1_NS6_17integral_constantIbLb1EEEEE_EntoocvNS1_10has_appendIS9_T0_vEE_EcvNS1_10has_insertIS9_SE_vEE_EEiE4typeELi0EEES9_SE_SE_S9_
Line
Count
Source
1925
461
FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
1926
6.18k
  while (begin != end) *out++ = static_cast<T>(*begin++);
1927
461
  return out;
1928
461
}
_ZN3fmt3v126detail4copyIjPjS3_TnNSt3__19enable_ifIXoontcvNS1_23is_back_insert_iteratorIT1_NS4_17integral_constantIbLb1EEEEE_EntoocvNS1_10has_appendIS7_T0_vEE_EcvNS1_10has_insertIS7_SC_vEE_EEiE4typeELi0EEES7_SC_SC_S7_
Line
Count
Source
1925
4.24k
FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
1926
14.5k
  while (begin != end) *out++ = static_cast<T>(*begin++);
1927
4.24k
  return out;
1928
4.24k
}
Unexecuted instantiation: _ZN3fmt3v126detail4copyIcPcS3_TnNSt3__19enable_ifIXoontcvNS1_23is_back_insert_iteratorIT1_NS4_17integral_constantIbLb1EEEEE_EntoocvNS1_10has_appendIS7_T0_vEE_EcvNS1_10has_insertIS7_SC_vEE_EEiE4typeELi0EEES7_SC_SC_S7_
Unexecuted instantiation: _ZN3fmt3v126detail4copyIcPKcZNS1_5writeIcNS0_14basic_appenderIcEETnNSt3__19enable_ifIXsr3std7is_sameIT_cEE5valueEiE4typeELi0EEET0_SD_NS0_17basic_string_viewISA_EERKNS0_12format_specsEE23bounded_output_iteratorTnNS9_IXoontcvNS1_23is_back_insert_iteratorIT1_NS8_17integral_constantIbLb1EEEEE_EntoocvNS1_10has_appendISL_SD_vEE_EcvNS1_10has_insertISL_SD_vEE_EEiE4typeELi0EEESL_SD_SD_SL_
Unexecuted instantiation: _ZN3fmt3v126detail4copyIcPcZNS1_5writeIcNS0_14basic_appenderIcEETnNSt3__19enable_ifIXsr3std7is_sameIT_cEE5valueEiE4typeELi0EEET0_SC_NS0_17basic_string_viewIS9_EERKNS0_12format_specsEE23bounded_output_iteratorTnNS8_IXoontcvNS1_23is_back_insert_iteratorIT1_NS7_17integral_constantIbLb1EEEEE_EntoocvNS1_10has_appendISK_SC_vEE_EcvNS1_10has_insertISK_SC_vEE_EEiE4typeELi0EEESK_SC_SC_SK_
Unexecuted instantiation: _ZN3fmt3v126detail4copyIiPiS3_TnNSt3__19enable_ifIXoontcvNS1_23is_back_insert_iteratorIT1_NS4_17integral_constantIbLb1EEEEE_EntoocvNS1_10has_appendIS7_T0_vEE_EcvNS1_10has_insertIS7_SC_vEE_EEiE4typeELi0EEES7_SC_SC_S7_
1929
1930
// A buffer that writes to an output iterator when flushed.
1931
template <typename OutputIt, typename T, typename Traits = buffer_traits>
1932
class iterator_buffer : public Traits, public buffer<T> {
1933
 private:
1934
  OutputIt out_;
1935
  enum { buffer_size = 256 };
1936
  T data_[buffer_size];
1937
1938
  static FMT_CONSTEXPR void grow(buffer<T>& buf, size_t) {
1939
    if (buf.size() == buffer_size) static_cast<iterator_buffer&>(buf).flush();
1940
  }
1941
1942
  void flush() {
1943
    auto size = this->size();
1944
    this->clear();
1945
    const T* begin = data_;
1946
    const T* end = begin + this->limit(size);
1947
    out_ = copy<T>(begin, end, out_);
1948
  }
1949
1950
 public:
1951
  explicit iterator_buffer(OutputIt out, size_t n = buffer_size)
1952
      : Traits(n), buffer<T>(grow, data_, 0, buffer_size), out_(out) {}
1953
  iterator_buffer(iterator_buffer&& other) noexcept
1954
      : Traits(other),
1955
        buffer<T>(grow, data_, 0, buffer_size),
1956
        out_(other.out_) {}
1957
  ~iterator_buffer() {
1958
    // Don't crash if flush fails during unwinding.
1959
    FMT_TRY { flush(); }
1960
    FMT_CATCH(...) {}
1961
  }
1962
1963
  auto out() -> OutputIt {
1964
    flush();
1965
    return out_;
1966
  }
1967
  auto count() const -> size_t { return Traits::count() + this->size(); }
1968
};
1969
1970
template <typename T>
1971
class iterator_buffer<T*, T, fixed_buffer_traits> : public fixed_buffer_traits,
1972
                                                    public buffer<T> {
1973
 private:
1974
  T* out_;
1975
  enum { buffer_size = 256 };
1976
  T data_[buffer_size];
1977
1978
  static FMT_CONSTEXPR void grow(buffer<T>& buf, size_t) {
1979
    if (buf.size() == buf.capacity())
1980
      static_cast<iterator_buffer&>(buf).flush();
1981
  }
1982
1983
  void flush() {
1984
    size_t n = this->limit(this->size());
1985
    if (this->data() == out_) {
1986
      out_ += n;
1987
      this->set(data_, buffer_size);
1988
    }
1989
    this->clear();
1990
  }
1991
1992
 public:
1993
  explicit iterator_buffer(T* out, size_t n = buffer_size)
1994
      : fixed_buffer_traits(n), buffer<T>(grow, out, 0, n), out_(out) {}
1995
  iterator_buffer(iterator_buffer&& other) noexcept
1996
      : fixed_buffer_traits(other),
1997
        buffer<T>(static_cast<iterator_buffer&&>(other)),
1998
        out_(other.out_) {
1999
    if (this->data() != out_) {
2000
      this->set(data_, buffer_size);
2001
      this->clear();
2002
    }
2003
  }
2004
  ~iterator_buffer() { flush(); }
2005
2006
  auto out() -> T* {
2007
    flush();
2008
    return out_;
2009
  }
2010
  auto count() const -> size_t {
2011
    return fixed_buffer_traits::count() + this->size();
2012
  }
2013
};
2014
2015
template <typename T> class iterator_buffer<T*, T> : public buffer<T> {
2016
 public:
2017
  explicit iterator_buffer(T* out, size_t = 0)
2018
      : buffer<T>([](buffer<T>&, size_t) {}, out, 0, ~size_t()) {}
2019
2020
  auto out() -> T* { return &*this->end(); }
2021
};
2022
2023
template <typename Container>
2024
class container_buffer : public buffer<typename Container::value_type> {
2025
 private:
2026
  using value_type = typename Container::value_type;
2027
2028
0
  static FMT_CONSTEXPR void grow(buffer<value_type>& buf, size_t capacity) {
2029
0
    auto& self = static_cast<container_buffer&>(buf);
2030
0
    self.container.resize(capacity);
2031
0
    self.set(&self.container[0], capacity);
2032
0
  }
2033
2034
 public:
2035
  Container& container;
2036
2037
  explicit container_buffer(Container& c)
2038
      : buffer<value_type>(grow, c.size()), container(c) {}
2039
};
2040
2041
// A buffer that writes to a container with the contiguous storage.
2042
template <typename OutputIt>
2043
class iterator_buffer<
2044
    OutputIt,
2045
    enable_if_t<is_back_insert_iterator<OutputIt>::value &&
2046
                    is_contiguous<typename OutputIt::container_type>::value,
2047
                typename OutputIt::container_type::value_type>>
2048
    : public container_buffer<typename OutputIt::container_type> {
2049
 private:
2050
  using base = container_buffer<typename OutputIt::container_type>;
2051
2052
 public:
2053
  explicit iterator_buffer(typename OutputIt::container_type& c) : base(c) {}
2054
  explicit iterator_buffer(OutputIt out, size_t = 0)
2055
      : base(get_container(out)) {}
2056
2057
  auto out() -> OutputIt { return OutputIt(this->container); }
2058
};
2059
2060
// A buffer that counts the number of code units written discarding the output.
2061
template <typename T = char> class counting_buffer : public buffer<T> {
2062
 private:
2063
  enum { buffer_size = 256 };
2064
  T data_[buffer_size];
2065
  size_t count_ = 0;
2066
2067
0
  static FMT_CONSTEXPR void grow(buffer<T>& buf, size_t) {
2068
0
    if (buf.size() != buffer_size) return;
2069
0
    static_cast<counting_buffer&>(buf).count_ += buf.size();
2070
0
    buf.clear();
2071
0
  }
2072
2073
 public:
2074
0
  constexpr counting_buffer() : buffer<T>(grow, data_, 0, buffer_size) {}
2075
2076
0
  constexpr auto count() const noexcept -> size_t {
2077
0
    return count_ + this->size();
2078
0
  }
2079
};
2080
2081
template <typename T>
2082
struct is_back_insert_iterator<basic_appender<T>> : std::true_type {};
2083
2084
template <typename It, typename Enable = std::true_type>
2085
struct is_buffer_appender : std::false_type {};
2086
template <typename It>
2087
struct is_buffer_appender<
2088
    It, bool_constant<
2089
            is_back_insert_iterator<It>::value &&
2090
            std::is_base_of<buffer<typename It::container_type::value_type>,
2091
                            typename It::container_type>::value>>
2092
    : std::true_type {};
2093
2094
// Maps an output iterator to a buffer.
2095
template <typename T, typename OutputIt,
2096
          FMT_ENABLE_IF(!is_buffer_appender<OutputIt>::value)>
2097
auto get_buffer(OutputIt out) -> iterator_buffer<OutputIt, T> {
2098
  return iterator_buffer<OutputIt, T>(out);
2099
}
2100
template <typename T, typename OutputIt,
2101
          FMT_ENABLE_IF(is_buffer_appender<OutputIt>::value)>
2102
2.09k
auto get_buffer(OutputIt out) -> buffer<T>& {
2103
2.09k
  return get_container(out);
2104
2.09k
}
_ZN3fmt3v126detail10get_bufferIcNSt3__120back_insert_iteratorINS0_19basic_memory_bufferIcLm500ENS1_9allocatorIcEEEEEETnNS3_9enable_ifIXsr18is_buffer_appenderIT0_EE5valueEiE4typeELi0EEERNS1_6bufferIT_EESB_
Line
Count
Source
2102
2.09k
auto get_buffer(OutputIt out) -> buffer<T>& {
2103
2.09k
  return get_container(out);
2104
2.09k
}
Unexecuted instantiation: _ZN3fmt3v126detail10get_bufferIcNS0_14basic_appenderIcEETnNSt3__19enable_ifIXsr18is_buffer_appenderIT0_EE5valueEiE4typeELi0EEERNS1_6bufferIT_EES7_
2105
2106
template <typename Buf, typename OutputIt>
2107
auto get_iterator(Buf& buf, OutputIt) -> decltype(buf.out()) {
2108
  return buf.out();
2109
}
2110
template <typename T, typename OutputIt>
2111
2.09k
auto get_iterator(buffer<T>&, OutputIt out) -> OutputIt {
2112
2.09k
  return out;
2113
2.09k
}
std::__1::back_insert_iterator<fmt::v12::basic_memory_buffer<char, 500ul, fmt::v12::detail::allocator<char> > > fmt::v12::detail::get_iterator<char, std::__1::back_insert_iterator<fmt::v12::basic_memory_buffer<char, 500ul, fmt::v12::detail::allocator<char> > > >(fmt::v12::detail::buffer<char>&, std::__1::back_insert_iterator<fmt::v12::basic_memory_buffer<char, 500ul, fmt::v12::detail::allocator<char> > >)
Line
Count
Source
2111
2.09k
auto get_iterator(buffer<T>&, OutputIt out) -> OutputIt {
2112
2.09k
  return out;
2113
2.09k
}
Unexecuted instantiation: fmt::v12::basic_appender<char> fmt::v12::detail::get_iterator<char, fmt::v12::basic_appender<char> >(fmt::v12::detail::buffer<char>&, fmt::v12::basic_appender<char>)
2114
2115
// This type is intentionally undefined, only used for errors.
2116
template <typename T, typename Char> struct type_is_unformattable_for;
2117
2118
template <typename Char> struct string_value {
2119
  const Char* data;
2120
  size_t size;
2121
0
  auto str() const -> basic_string_view<Char> { return {data, size}; }
2122
};
2123
2124
template <typename Context> struct custom_value {
2125
  using char_type = typename Context::char_type;
2126
  void* value;
2127
  void (*format)(void* arg, parse_context<char_type>& parse_ctx, Context& ctx);
2128
};
2129
2130
template <typename Char> struct named_arg_value {
2131
  const named_arg_info<Char>* data;
2132
  size_t size;
2133
};
2134
2135
struct custom_tag {};
2136
2137
#if !FMT_BUILTIN_TYPES
2138
#  define FMT_BUILTIN , monostate
2139
#else
2140
#  define FMT_BUILTIN
2141
#endif
2142
2143
// A formatting argument value.
2144
template <typename Context> class value {
2145
 public:
2146
  using char_type = typename Context::char_type;
2147
2148
  union {
2149
    monostate no_value;
2150
    int int_value;
2151
    unsigned uint_value;
2152
    long long long_long_value;
2153
    ullong ulong_long_value;
2154
    native_int128 int128_value;
2155
    native_uint128 uint128_value;
2156
    bool bool_value;
2157
    char_type char_value;
2158
    float float_value;
2159
    double double_value;
2160
    long double long_double_value;
2161
    const void* pointer;
2162
    string_value<char_type> string;
2163
    custom_value<Context> custom;
2164
    named_arg_value<char_type> named_args;
2165
  };
2166
2167
2.09k
  constexpr FMT_INLINE value() : no_value() {}
2168
  constexpr FMT_INLINE value(signed char x) : int_value(x) {}
2169
0
  constexpr FMT_INLINE value(unsigned char x FMT_BUILTIN) : uint_value(x) {}
2170
  constexpr FMT_INLINE value(signed short x) : int_value(x) {}
2171
  constexpr FMT_INLINE value(unsigned short x FMT_BUILTIN) : uint_value(x) {}
2172
0
  constexpr FMT_INLINE value(int x) : int_value(x) {}
2173
0
  constexpr FMT_INLINE value(unsigned x FMT_BUILTIN) : uint_value(x) {}
2174
  constexpr FMT_INLINE value(long x FMT_BUILTIN) : value(long_type(x)) {}
2175
  constexpr FMT_INLINE value(unsigned long x FMT_BUILTIN)
2176
      : value(ulong_type(x)) {}
2177
0
  constexpr FMT_INLINE value(long long x FMT_BUILTIN) : long_long_value(x) {}
2178
0
  constexpr FMT_INLINE value(ullong x FMT_BUILTIN) : ulong_long_value(x) {}
2179
0
  FMT_INLINE value(native_int128 x FMT_BUILTIN) : int128_value(x) {}
2180
0
  FMT_INLINE value(native_uint128 x FMT_BUILTIN) : uint128_value(x) {}
2181
  constexpr FMT_INLINE value(bool x FMT_BUILTIN) : bool_value(x) {}
2182
2183
  template <typename T, FMT_ENABLE_IF(is_code_unit<T>::value)>
2184
  constexpr FMT_INLINE value(T x FMT_BUILTIN) : char_value(x) {
2185
    static_assert(
2186
        std::is_same<T, char>::value || std::is_same<T, char_type>::value,
2187
        "mixing character types is disallowed");
2188
  }
2189
2190
0
  constexpr FMT_INLINE value(float x FMT_BUILTIN) : float_value(x) {}
2191
2.09k
  constexpr FMT_INLINE value(double x FMT_BUILTIN) : double_value(x) {}
2192
0
  FMT_INLINE value(long double x FMT_BUILTIN) : long_double_value(x) {}
2193
2194
  FMT_CONSTEXPR FMT_INLINE value(char_type* x FMT_BUILTIN) {
2195
    string.data = x;
2196
    if (is_constant_evaluated()) string.size = 0;
2197
  }
2198
0
  FMT_CONSTEXPR FMT_INLINE value(const char_type* x FMT_BUILTIN) {
2199
0
    string.data = x;
2200
0
    if (is_constant_evaluated()) string.size = 0;
2201
0
  }
2202
  template <typename T, typename C = char_t<T>,
2203
            FMT_ENABLE_IF(!std::is_pointer<T>::value)>
2204
0
  FMT_CONSTEXPR value(const T& x FMT_BUILTIN) {
2205
0
    static_assert(std::is_same<C, char_type>::value,
2206
0
                  "mixing character types is disallowed");
2207
0
    auto sv = to_string_view(x);
2208
0
    string.data = sv.data();
2209
0
    string.size = sv.size();
2210
0
  }
2211
  constexpr FMT_INLINE value(void* x FMT_BUILTIN) : pointer(x) {}
2212
  constexpr FMT_INLINE value(const void* x FMT_BUILTIN) : pointer(x) {}
2213
  constexpr FMT_INLINE value(volatile void* x FMT_BUILTIN)
2214
      : pointer(const_cast<const void*>(x)) {}
2215
  constexpr FMT_INLINE value(const volatile void* x FMT_BUILTIN)
2216
      : pointer(const_cast<const void*>(x)) {}
2217
  constexpr FMT_INLINE value(nullptr_t) : pointer(nullptr) {}
2218
2219
  template <typename T,
2220
            FMT_ENABLE_IF(
2221
                (std::is_pointer<T>::value ||
2222
                 std::is_member_pointer<T>::value) &&
2223
                !std::is_void<typename std::remove_pointer<T>::type>::value)>
2224
  constexpr value(const T&) {
2225
    // Formatting of arbitrary pointers is disallowed. If you want to format a
2226
    // pointer cast it to `void*` or `const void*`. In particular, this forbids
2227
    // formatting of `[const] volatile char*` printed as bool by iostreams.
2228
    static_assert(sizeof(T) == 0,
2229
                  "formatting of non-void pointers is disallowed");
2230
  }
2231
2232
  template <typename T, FMT_ENABLE_IF(use_format_as<T>::value)>
2233
  constexpr value(const T& x) : value(format_as(x)) {}
2234
  template <typename T, FMT_ENABLE_IF(use_format_as_member<T>::value)>
2235
  constexpr value(const T& x) : value(formatter<T>::format_as(x)) {}
2236
2237
  template <typename T, FMT_ENABLE_IF(is_named_arg<T>::value)>
2238
  constexpr value(const T& named_arg) : value(named_arg.value) {}
2239
2240
  template <typename T,
2241
            FMT_ENABLE_IF(use_formatter<T>::value || !FMT_BUILTIN_TYPES)>
2242
  FMT_CONSTEXPR FMT_INLINE value(T& x) : value(x, custom_tag()) {}
2243
2244
  FMT_ALWAYS_INLINE value(const named_arg_info<char_type>* args, size_t size)
2245
      : named_args{args, size} {}
2246
2247
 private:
2248
  template <typename T, FMT_ENABLE_IF(has_formatter<T, char_type>())>
2249
  FMT_CONSTEXPR value(T& x, custom_tag) {
2250
    using value_type = remove_const_t<T>;
2251
    // T may overload operator& e.g. std::vector<bool>::reference in libc++.
2252
    if (!is_constant_evaluated()) {
2253
      custom.value =
2254
          const_cast<char*>(&reinterpret_cast<const volatile char&>(x));
2255
    } else {
2256
      custom.value = nullptr;
2257
#if defined(__cpp_if_constexpr)
2258
      if constexpr (std::is_same<decltype(&x), remove_reference_t<T>*>::value)
2259
        custom.value = const_cast<value_type*>(&x);
2260
#endif
2261
    }
2262
    custom.format = format_custom<value_type>;
2263
  }
2264
2265
  template <typename T, FMT_ENABLE_IF(!has_formatter<T, char_type>())>
2266
  FMT_CONSTEXPR value(const T&, custom_tag) {
2267
    // Cannot format an argument; to make type T formattable provide a
2268
    // formatter<T> specialization: https://fmt.dev/latest/api#udt.
2269
    type_is_unformattable_for<T, char_type> _;
2270
  }
2271
2272
  // Formats an argument of a custom type, such as a user-defined class.
2273
  template <typename T>
2274
  static void format_custom(void* arg, parse_context<char_type>& parse_ctx,
2275
                            Context& ctx) {
2276
    auto f = formatter<T, char_type>();
2277
    parse_ctx.advance_to(f.parse(parse_ctx));
2278
    using qualified_type =
2279
        conditional_t<has_formatter<const T, char_type>(), const T, T>;
2280
    // format must be const for compatibility with std::format and compilation.
2281
    const auto& cf = f;
2282
    ctx.advance_to(cf.format(*static_cast<qualified_type*>(arg), ctx));
2283
  }
2284
};
2285
2286
enum { packed_arg_bits = 4 };
2287
// Maximum number of arguments with packed types.
2288
enum { max_packed_args = 62 / packed_arg_bits };
2289
enum : ullong { is_unpacked_bit = 1ULL << 63 };
2290
enum : ullong { has_named_args_bit = 1ULL << 62 };
2291
2292
template <typename It, typename T, typename Enable = void>
2293
struct is_output_iterator : std::false_type {};
2294
2295
template <> struct is_output_iterator<appender, char> : std::true_type {};
2296
2297
template <typename It, typename T>
2298
struct is_output_iterator<
2299
    It, T,
2300
    enable_if_t<std::is_assignable<decltype(*std::declval<decay_t<It>&>()++),
2301
                                   T>::value>> : std::true_type {};
2302
2303
0
template <typename> constexpr auto encode_types() -> ullong { return 0; }
2304
2305
template <typename Context, typename First, typename... T>
2306
0
constexpr auto encode_types() -> ullong {
2307
0
  return unsigned(stored_type_constant<First, Context>::value) |
2308
0
         (encode_types<Context, T...>() << packed_arg_bits);
2309
0
}
Unexecuted instantiation: unsigned long long fmt::v12::detail::encode_types<fmt::v12::context, double&>()
Unexecuted instantiation: unsigned long long fmt::v12::detail::encode_types<fmt::v12::context, char const (&) [3]>()
Unexecuted instantiation: unsigned long long fmt::v12::detail::encode_types<fmt::v12::context, fmt::v12::basic_string_view<char>&, char const (&) [3]>()
Unexecuted instantiation: unsigned long long fmt::v12::detail::encode_types<fmt::v12::context, int&>()
Unexecuted instantiation: unsigned long long fmt::v12::detail::encode_types<fmt::v12::context, char const (&) [7], int&>()
Unexecuted instantiation: unsigned long long fmt::v12::detail::encode_types<fmt::v12::context, unsigned int&>()
Unexecuted instantiation: unsigned long long fmt::v12::detail::encode_types<fmt::v12::context, int>()
2310
2311
template <typename Context, typename... T, size_t NUM_ARGS = sizeof...(T)>
2312
0
constexpr auto make_descriptor() -> ullong {
2313
0
  return NUM_ARGS <= max_packed_args ? encode_types<Context, T...>()
2314
0
                                     : is_unpacked_bit | NUM_ARGS;
2315
0
}
Unexecuted instantiation: unsigned long long fmt::v12::detail::make_descriptor<fmt::v12::context, double&, 1ul>()
Unexecuted instantiation: unsigned long long fmt::v12::detail::make_descriptor<fmt::v12::context, fmt::v12::basic_string_view<char>&, char const (&) [3], 2ul>()
Unexecuted instantiation: unsigned long long fmt::v12::detail::make_descriptor<fmt::v12::context, char const (&) [7], int&, 2ul>()
Unexecuted instantiation: unsigned long long fmt::v12::detail::make_descriptor<fmt::v12::context, , 0ul>()
Unexecuted instantiation: unsigned long long fmt::v12::detail::make_descriptor<fmt::v12::context, unsigned int&, 1ul>()
Unexecuted instantiation: unsigned long long fmt::v12::detail::make_descriptor<fmt::v12::context, int, 1ul>()
2316
2317
template <typename Context, int NUM_ARGS>
2318
using arg_t = conditional_t<NUM_ARGS <= max_packed_args, value<Context>,
2319
                            basic_format_arg<Context>>;
2320
2321
template <typename Context, int NUM_ARGS, int NUM_NAMED_ARGS, ullong DESC>
2322
struct named_arg_store {
2323
  // args_[0].named_args points to named_args to avoid bloating format_args.
2324
  arg_t<Context, NUM_ARGS> args[NUM_ARGS + 1u];
2325
  named_arg_info<typename Context::char_type> named_args[NUM_NAMED_ARGS + 0u];
2326
2327
  template <typename... T>
2328
  FMT_CONSTEXPR FMT_ALWAYS_INLINE named_arg_store(T&... values)
2329
      : args{{named_args, NUM_NAMED_ARGS}, values...} {
2330
    int arg_index = 0, named_arg_index = 0;
2331
    FMT_APPLY_VARIADIC(
2332
        init_named_arg(named_args, arg_index, named_arg_index, values));
2333
  }
2334
2335
  named_arg_store(named_arg_store&& rhs) {
2336
    args[0] = {named_args, NUM_NAMED_ARGS};
2337
    for (size_t i = 1; i < sizeof(args) / sizeof(*args); ++i)
2338
      args[i] = rhs.args[i];
2339
    for (size_t i = 0; i < NUM_NAMED_ARGS; ++i)
2340
      named_args[i] = rhs.named_args[i];
2341
  }
2342
2343
  named_arg_store(const named_arg_store& rhs) = delete;
2344
  auto operator=(const named_arg_store& rhs) -> named_arg_store& = delete;
2345
  auto operator=(named_arg_store&& rhs) -> named_arg_store& = delete;
2346
  operator const arg_t<Context, NUM_ARGS>*() const { return args + 1; }
2347
};
2348
2349
// An array of references to arguments. It can be implicitly converted to
2350
// `basic_format_args` for passing into type-erased formatting functions
2351
// such as `vformat`. It is a plain struct to reduce binary size in debug mode.
2352
template <typename Context, int NUM_ARGS, int NUM_NAMED_ARGS, ullong DESC>
2353
struct format_arg_store {
2354
  // +1 to workaround a bug in gcc 7.5 that causes duplicated-branches warning.
2355
  using type =
2356
      conditional_t<NUM_NAMED_ARGS == 0,
2357
                    arg_t<Context, NUM_ARGS>[max_of<size_t>(1, NUM_ARGS)],
2358
                    named_arg_store<Context, NUM_ARGS, NUM_NAMED_ARGS, DESC>>;
2359
  type args;
2360
};
2361
2362
// TYPE can be different from type_constant<T>, e.g. for __float128.
2363
template <typename T, typename Char, type TYPE> struct native_formatter {
2364
 private:
2365
  dynamic_format_specs<Char> specs_;
2366
2367
 public:
2368
0
  FMT_CONSTEXPR auto parse(parse_context<Char>& ctx) -> const Char* {
2369
0
    if (ctx.begin() == ctx.end() || *ctx.begin() == '}') return ctx.begin();
2370
0
    auto end = parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, TYPE);
2371
0
    if FMT_CONSTEXPR20 (TYPE == type::char_type) check_char_specs(specs_);
2372
0
    return end;
2373
0
  }
Unexecuted instantiation: fmt::v12::detail::native_formatter<double, char, (fmt::v12::detail::type)10>::parse(fmt::v12::parse_context<char>&)
Unexecuted instantiation: fmt::v12::detail::native_formatter<fmt::v12::basic_string_view<char>, char, (fmt::v12::detail::type)13>::parse(fmt::v12::parse_context<char>&)
Unexecuted instantiation: fmt::v12::detail::native_formatter<char const*, char, (fmt::v12::detail::type)12>::parse(fmt::v12::parse_context<char>&)
Unexecuted instantiation: fmt::v12::detail::native_formatter<int, char, (fmt::v12::detail::type)1>::parse(fmt::v12::parse_context<char>&)
Unexecuted instantiation: fmt::v12::detail::native_formatter<unsigned int, char, (fmt::v12::detail::type)2>::parse(fmt::v12::parse_context<char>&)
2374
2375
  template <type U = TYPE,
2376
            FMT_ENABLE_IF(U == type::string_type || U == type::cstring_type ||
2377
                          U == type::char_type)>
2378
  FMT_CONSTEXPR void set_debug_format(bool set = true) {
2379
    specs_.set_type(set ? presentation_type::debug : presentation_type::none);
2380
  }
2381
2382
  template <typename FormatContext>
2383
  FMT_CONSTEXPR auto format(const T& val, FormatContext& ctx) const
2384
      -> decltype(ctx.out());
2385
};
2386
2387
0
template <bool B> constexpr bool enforce_compile_checks() {
2388
0
#ifdef FMT_ENFORCE_COMPILE_STRING
2389
0
  static_assert(
2390
0
      FMT_USE_CONSTEVAL && B,
2391
0
      "FMT_ENFORCE_COMPILE_STRING requires format strings to use FMT_STRING");
2392
0
#endif
2393
0
  return true;
2394
0
}
2395
2396
template <typename T = int> constexpr auto is_locking() -> bool {
2397
  return locking<remove_cvref_t<T>>::value;
2398
}
2399
template <typename T1, typename T2, typename... Tail>
2400
constexpr auto is_locking() -> bool {
2401
  return locking<remove_cvref_t<T1>>::value || is_locking<T2, Tail...>();
2402
}
2403
2404
FMT_API void vformat_to(buffer<char>& buf, string_view fmt, format_args args,
2405
                        locale_ref loc = {});
2406
2407
#if FMT_WIN32
2408
FMT_API void vprint_mojibake(FILE*, string_view, format_args, bool);
2409
#else  // format_args is passed by reference since it is defined later.
2410
0
inline void vprint_mojibake(FILE*, string_view, const format_args&, bool) {}
2411
#endif
2412
}  // namespace detail
2413
2414
// The main public API.
2415
2416
template <typename T, typename Char = char>
2417
using named_arg = detail::named_arg<T, Char>;
2418
2419
template <typename Char>
2420
1.04k
FMT_CONSTEXPR void parse_context<Char>::do_check_arg_id(int arg_id) {
2421
  // Argument id is only checked at compile time during parsing because
2422
  // formatting has its own validation.
2423
1.04k
  if (detail::is_constant_evaluated() && use_constexpr_cast) {
2424
0
    auto ctx = static_cast<detail::compile_parse_context<Char>*>(this);
2425
0
    if (arg_id >= ctx->num_args()) report_error("argument not found");
2426
0
  }
2427
1.04k
}
2428
2429
template <typename Char>
2430
0
FMT_CONSTEXPR void parse_context<Char>::check_dynamic_spec(int arg_id) {
2431
0
  using detail::compile_parse_context;
2432
0
  if (detail::is_constant_evaluated() && use_constexpr_cast)
2433
0
    static_cast<compile_parse_context<Char>*>(this)->check_dynamic_spec(arg_id);
2434
0
}
2435
2436
FMT_BEGIN_EXPORT
2437
2438
// An output iterator that appends to a buffer. It is used instead of
2439
// back_insert_iterator to reduce symbol sizes and avoid <iterator> dependency.
2440
template <typename T> class basic_appender {
2441
 protected:
2442
  detail::buffer<T>* container;
2443
2444
 public:
2445
  using container_type = detail::buffer<T>;
2446
2447
2.09k
  constexpr basic_appender(detail::buffer<T>& buf) : container(&buf) {}
2448
2449
4.39k
  FMT_CONSTEXPR auto operator=(T c) -> basic_appender& {
2450
4.39k
    container->push_back(c);
2451
4.39k
    return *this;
2452
4.39k
  }
2453
4.39k
  FMT_CONSTEXPR auto operator*() -> basic_appender& { return *this; }
2454
  FMT_CONSTEXPR auto operator++() -> basic_appender& { return *this; }
2455
4.39k
  FMT_CONSTEXPR auto operator++(int) -> basic_appender { return *this; }
2456
};
2457
2458
// A formatting argument. Context is a template parameter for the compiled API
2459
// where output can be unbuffered.
2460
template <typename Context> class basic_format_arg {
2461
 private:
2462
  detail::value<Context> value_;
2463
  detail::type type_;
2464
2465
  friend class basic_format_args<Context>;
2466
2467
  using char_type = typename Context::char_type;
2468
2469
 public:
2470
  class handle {
2471
   private:
2472
    detail::custom_value<Context> custom_;
2473
2474
   public:
2475
0
    explicit handle(detail::custom_value<Context> custom) : custom_(custom) {}
2476
2477
0
    void format(parse_context<char_type>& parse_ctx, Context& ctx) const {
2478
0
      custom_.format(custom_.value, parse_ctx, ctx);
2479
0
    }
2480
  };
2481
2482
2.09k
  constexpr basic_format_arg() : type_(detail::type::none_type) {}
2483
  basic_format_arg(const detail::named_arg_info<char_type>* args, size_t size)
2484
      : value_(args, size) {}
2485
  template <typename T>
2486
  basic_format_arg(T&& val)
2487
0
      : value_(val), type_(detail::stored_type_constant<T, Context>::value) {}
Unexecuted instantiation: fmt::v12::basic_format_arg<fmt::v12::context>::basic_format_arg<int&>(int&)
Unexecuted instantiation: fmt::v12::basic_format_arg<fmt::v12::context>::basic_format_arg<long double&>(long double&)
Unexecuted instantiation: fmt::v12::basic_format_arg<fmt::v12::context>::basic_format_arg<unsigned int&>(unsigned int&)
Unexecuted instantiation: fmt::v12::basic_format_arg<fmt::v12::context>::basic_format_arg<long long&>(long long&)
Unexecuted instantiation: fmt::v12::basic_format_arg<fmt::v12::context>::basic_format_arg<unsigned long long&>(unsigned long long&)
Unexecuted instantiation: fmt::v12::basic_format_arg<fmt::v12::context>::basic_format_arg<__int128&>(__int128&)
Unexecuted instantiation: fmt::v12::basic_format_arg<fmt::v12::context>::basic_format_arg<unsigned __int128&>(unsigned __int128&)
Unexecuted instantiation: fmt::v12::basic_format_arg<fmt::v12::context>::basic_format_arg<unsigned char&>(unsigned char&)
Unexecuted instantiation: fmt::v12::basic_format_arg<fmt::v12::context>::basic_format_arg<float&>(float&)
Unexecuted instantiation: fmt::v12::basic_format_arg<fmt::v12::context>::basic_format_arg<double&>(double&)
2488
2489
1.04k
  constexpr explicit operator bool() const noexcept {
2490
1.04k
    return type_ != detail::type::none_type;
2491
1.04k
  }
2492
1.04k
  auto type() const -> detail::type { return type_; }
2493
2494
  /**
2495
   * Visits an argument dispatching to the appropriate visit method based on
2496
   * the argument type. For example, if the argument type is `double` then
2497
   * `vis(value)` will be called with the value of type `double`.
2498
   */
2499
  template <typename Visitor>
2500
2.09k
  FMT_CONSTEXPR FMT_INLINE auto visit(Visitor&& vis) const -> decltype(vis(0)) {
2501
2.09k
    using detail::map;
2502
2.09k
    switch (type_) {
2503
0
    case detail::type::none_type:        break;
2504
0
    case detail::type::int_type:         return vis(value_.int_value);
2505
0
    case detail::type::uint_type:        return vis(value_.uint_value);
2506
0
    case detail::type::long_long_type:   return vis(value_.long_long_value);
2507
0
    case detail::type::ulong_long_type:  return vis(value_.ulong_long_value);
2508
0
    case detail::type::int128_type:      return vis(map(value_.int128_value));
2509
0
    case detail::type::uint128_type:     return vis(map(value_.uint128_value));
2510
0
    case detail::type::bool_type:        return vis(value_.bool_value);
2511
0
    case detail::type::char_type:        return vis(value_.char_value);
2512
0
    case detail::type::float_type:       return vis(value_.float_value);
2513
2.09k
    case detail::type::double_type:      return vis(value_.double_value);
2514
0
    case detail::type::long_double_type: return vis(value_.long_double_value);
2515
0
    case detail::type::cstring_type:     return vis(value_.string.data);
2516
0
    case detail::type::string_type:      return vis(value_.string.str());
2517
0
    case detail::type::pointer_type:     return vis(value_.pointer);
2518
0
    case detail::type::custom_type:      return vis(handle(value_.custom));
2519
2.09k
    }
2520
0
    return vis(monostate());
2521
2.09k
  }
decltype ({parm#1}(0)) fmt::v12::basic_format_arg<fmt::v12::context>::visit<fmt::v12::detail::default_arg_formatter<char> >(fmt::v12::detail::default_arg_formatter<char>&&) const
Line
Count
Source
2500
1.04k
  FMT_CONSTEXPR FMT_INLINE auto visit(Visitor&& vis) const -> decltype(vis(0)) {
2501
1.04k
    using detail::map;
2502
1.04k
    switch (type_) {
2503
0
    case detail::type::none_type:        break;
2504
0
    case detail::type::int_type:         return vis(value_.int_value);
2505
0
    case detail::type::uint_type:        return vis(value_.uint_value);
2506
0
    case detail::type::long_long_type:   return vis(value_.long_long_value);
2507
0
    case detail::type::ulong_long_type:  return vis(value_.ulong_long_value);
2508
0
    case detail::type::int128_type:      return vis(map(value_.int128_value));
2509
0
    case detail::type::uint128_type:     return vis(map(value_.uint128_value));
2510
0
    case detail::type::bool_type:        return vis(value_.bool_value);
2511
0
    case detail::type::char_type:        return vis(value_.char_value);
2512
0
    case detail::type::float_type:       return vis(value_.float_value);
2513
1.04k
    case detail::type::double_type:      return vis(value_.double_value);
2514
0
    case detail::type::long_double_type: return vis(value_.long_double_value);
2515
0
    case detail::type::cstring_type:     return vis(value_.string.data);
2516
0
    case detail::type::string_type:      return vis(value_.string.str());
2517
0
    case detail::type::pointer_type:     return vis(value_.pointer);
2518
0
    case detail::type::custom_type:      return vis(handle(value_.custom));
2519
1.04k
    }
2520
0
    return vis(monostate());
2521
1.04k
  }
Unexecuted instantiation: decltype ({parm#1}(0)) fmt::v12::basic_format_arg<fmt::v12::context>::visit<fmt::v12::detail::dynamic_spec_getter>(fmt::v12::detail::dynamic_spec_getter&&) const
decltype ({parm#1}(0)) fmt::v12::basic_format_arg<fmt::v12::context>::visit<fmt::v12::detail::arg_formatter<char> >(fmt::v12::detail::arg_formatter<char>&&) const
Line
Count
Source
2500
1.04k
  FMT_CONSTEXPR FMT_INLINE auto visit(Visitor&& vis) const -> decltype(vis(0)) {
2501
1.04k
    using detail::map;
2502
1.04k
    switch (type_) {
2503
0
    case detail::type::none_type:        break;
2504
0
    case detail::type::int_type:         return vis(value_.int_value);
2505
0
    case detail::type::uint_type:        return vis(value_.uint_value);
2506
0
    case detail::type::long_long_type:   return vis(value_.long_long_value);
2507
0
    case detail::type::ulong_long_type:  return vis(value_.ulong_long_value);
2508
0
    case detail::type::int128_type:      return vis(map(value_.int128_value));
2509
0
    case detail::type::uint128_type:     return vis(map(value_.uint128_value));
2510
0
    case detail::type::bool_type:        return vis(value_.bool_value);
2511
0
    case detail::type::char_type:        return vis(value_.char_value);
2512
0
    case detail::type::float_type:       return vis(value_.float_value);
2513
1.04k
    case detail::type::double_type:      return vis(value_.double_value);
2514
0
    case detail::type::long_double_type: return vis(value_.long_double_value);
2515
0
    case detail::type::cstring_type:     return vis(value_.string.data);
2516
0
    case detail::type::string_type:      return vis(value_.string.str());
2517
0
    case detail::type::pointer_type:     return vis(value_.pointer);
2518
0
    case detail::type::custom_type:      return vis(handle(value_.custom));
2519
1.04k
    }
2520
0
    return vis(monostate());
2521
1.04k
  }
Unexecuted instantiation: decltype ({parm#1}(0)) fmt::v12::basic_format_arg<fmt::v12::context>::visit<fmt::v12::detail::loc_writer<char>&>(fmt::v12::detail::loc_writer<char>&) const
2522
2523
  auto format_custom(const char_type* parse_begin,
2524
                     parse_context<char_type>& parse_ctx, Context& ctx)
2525
1.04k
      -> bool {
2526
1.04k
    if (type_ != detail::type::custom_type) return false;
2527
0
    parse_ctx.advance_to(parse_begin);
2528
0
    value_.custom.format(value_.custom.value, parse_ctx, ctx);
2529
0
    return true;
2530
1.04k
  }
2531
};
2532
2533
/**
2534
 * A view of a collection of formatting arguments. To avoid lifetime issues it
2535
 * should only be used as a parameter type in type-erased functions such as
2536
 * `vformat`:
2537
 *
2538
 *     void vlog(fmt::string_view fmt, fmt::format_args args);  // OK
2539
 *     fmt::format_args args = fmt::make_format_args();  // Dangling reference
2540
 */
2541
template <typename Context> class basic_format_args {
2542
 private:
2543
  // A descriptor that contains information about formatting arguments.
2544
  // If the number of arguments is less or equal to max_packed_args then
2545
  // argument types are passed in the descriptor. This reduces binary code size
2546
  // per formatting function call.
2547
  ullong desc_;
2548
  union {
2549
    // If is_packed() returns true then argument values are stored in values_;
2550
    // otherwise they are stored in args_. This is done to improve cache
2551
    // locality and reduce compiled code size since storing larger objects
2552
    // may require more code (at least on x86-64) even if the same amount of
2553
    // data is actually copied to stack. It saves ~10% on the bloat test.
2554
    const detail::value<Context>* values_;
2555
    const basic_format_arg<Context>* args_;
2556
  };
2557
2558
2.09k
  constexpr auto is_packed() const -> bool {
2559
2.09k
    return (desc_ & detail::is_unpacked_bit) == 0;
2560
2.09k
  }
2561
0
  constexpr auto has_named_args() const -> bool {
2562
0
    return (desc_ & detail::has_named_args_bit) != 0;
2563
0
  }
2564
2565
2.09k
  FMT_CONSTEXPR auto type(int index) const -> detail::type {
2566
2.09k
    int shift = index * detail::packed_arg_bits;
2567
2.09k
    unsigned mask = (1 << detail::packed_arg_bits) - 1;
2568
2.09k
    return static_cast<detail::type>((desc_ >> shift) & mask);
2569
2.09k
  }
2570
2571
  template <int NUM_ARGS, int NUM_NAMED_ARGS, ullong DESC>
2572
  using store =
2573
      detail::format_arg_store<Context, NUM_ARGS, NUM_NAMED_ARGS, DESC>;
2574
2575
 public:
2576
  using format_arg = basic_format_arg<Context>;
2577
2578
0
  constexpr basic_format_args() : desc_(0), args_(nullptr) {}
2579
2580
  /// Constructs a `basic_format_args` object from `format_arg_store`.
2581
  template <int NUM_ARGS, int NUM_NAMED_ARGS, ullong DESC,
2582
            FMT_ENABLE_IF(NUM_ARGS <= detail::max_packed_args)>
2583
  constexpr FMT_ALWAYS_INLINE basic_format_args(
2584
      const store<NUM_ARGS, NUM_NAMED_ARGS, DESC>& s)
2585
2.09k
      : desc_(DESC | (NUM_NAMED_ARGS != 0 ? +detail::has_named_args_bit : 0)),
2586
2.09k
        values_(s.args) {}
_ZN3fmt3v1217basic_format_argsINS0_7contextEEC2ILi1ELi0ELy10ETnNSt3__19enable_ifIXleT_LNS0_6detail3$_0E15EEiE4typeELi0EEERKNS7_16format_arg_storeIS2_XT_EXT0_EXT1_EEE
Line
Count
Source
2585
2.09k
      : desc_(DESC | (NUM_NAMED_ARGS != 0 ? +detail::has_named_args_bit : 0)),
2586
2.09k
        values_(s.args) {}
Unexecuted instantiation: _ZN3fmt3v1217basic_format_argsINS0_7contextEEC2ILi0ELi0ELy0ETnNSt3__19enable_ifIXleT_LNS0_6detail3$_3E15EEiE4typeELi0EEERKNS7_16format_arg_storeIS2_XT_EXT0_EXT1_EEE
Unexecuted instantiation: _ZN3fmt3v1217basic_format_argsINS0_7contextEEC2ILi2ELi0ELy205ETnNSt3__19enable_ifIXleT_LNS0_6detail3$_3E15EEiE4typeELi0EEERKNS7_16format_arg_storeIS2_XT_EXT0_EXT1_EEE
Unexecuted instantiation: _ZN3fmt3v1217basic_format_argsINS0_7contextEEC2ILi2ELi0ELy28ETnNSt3__19enable_ifIXleT_LNS0_6detail3$_3E15EEiE4typeELi0EEERKNS7_16format_arg_storeIS2_XT_EXT0_EXT1_EEE
2587
2588
  template <int NUM_ARGS, int NUM_NAMED_ARGS, ullong DESC,
2589
            FMT_ENABLE_IF(NUM_ARGS > detail::max_packed_args)>
2590
  constexpr basic_format_args(const store<NUM_ARGS, NUM_NAMED_ARGS, DESC>& s)
2591
      : desc_(DESC | (NUM_NAMED_ARGS != 0 ? +detail::has_named_args_bit : 0)),
2592
        args_(s.args) {}
2593
2594
  /// Constructs a `basic_format_args` object from a dynamic list of arguments.
2595
  constexpr basic_format_args(const format_arg* args, int count,
2596
                              bool has_named = false)
2597
      : desc_(detail::is_unpacked_bit | detail::to_unsigned(count) |
2598
              (has_named ? +detail::has_named_args_bit : 0)),
2599
        args_(args) {}
2600
2601
  /// Returns the argument with the specified id.
2602
2.09k
  FMT_CONSTEXPR auto get(int id) const -> format_arg {
2603
2.09k
    auto arg = format_arg();
2604
2.09k
    if (!is_packed()) {
2605
0
      if (unsigned(id) < unsigned(max_size())) arg = args_[id];
2606
0
      return arg;
2607
0
    }
2608
2.09k
    if (unsigned(id) >= detail::max_packed_args) return arg;
2609
2.09k
    arg.type_ = type(id);
2610
2.09k
    if (arg.type_ != detail::type::none_type) arg.value_ = values_[id];
2611
2.09k
    return arg;
2612
2.09k
  }
2613
2614
  template <typename Char>
2615
0
  auto get(basic_string_view<Char> name) const -> format_arg {
2616
0
    int id = get_id(name);
2617
0
    return id >= 0 ? get(id) : format_arg();
2618
0
  }
2619
2620
  template <typename Char>
2621
0
  FMT_CONSTEXPR auto get_id(basic_string_view<Char> name) const -> int {
2622
0
    if (!has_named_args()) return -1;
2623
0
    const auto& named_args =
2624
0
        (is_packed() ? values_[-1] : args_[-1].value_).named_args;
2625
0
    for (size_t i = 0; i < named_args.size; ++i) {
2626
0
      if (named_args.data[i].name == name) return named_args.data[i].id;
2627
0
    }
2628
0
    return -1;
2629
0
  }
2630
2631
0
  auto max_size() const -> int {
2632
0
    return int(is_packed() ? ullong(detail::max_packed_args)
2633
0
                           : desc_ & ~detail::is_unpacked_bit);
2634
0
  }
2635
};
2636
2637
// A formatting context.
2638
class context {
2639
 private:
2640
  appender out_;
2641
  format_args args_;
2642
  FMT_NO_UNIQUE_ADDRESS locale_ref loc_;
2643
2644
 public:
2645
  using char_type = char;  ///< The character type for the output.
2646
  using iterator = appender;
2647
  using format_arg = basic_format_arg<context>;
2648
  enum { builtin_types = FMT_BUILTIN_TYPES };
2649
2650
  /// Constructs a `context` object. References to the arguments are stored
2651
  /// in the object so make sure they have appropriate lifetimes.
2652
  constexpr context(iterator out, format_args args, locale_ref loc = {})
2653
1.04k
      : out_(out), args_(args), loc_(loc) {}
2654
  context(context&&) = default;
2655
  context(const context&) = delete;
2656
  void operator=(const context&) = delete;
2657
2658
1.04k
  FMT_CONSTEXPR auto arg(int id) const -> format_arg { return args_.get(id); }
2659
0
  inline auto arg(string_view name) const -> format_arg {
2660
0
    return args_.get(name);
2661
0
  }
2662
0
  FMT_CONSTEXPR auto arg_id(string_view name) const -> int {
2663
0
    return args_.get_id(name);
2664
0
  }
2665
0
  auto args() const -> const format_args& { return args_; }
2666
2667
  // Returns an iterator to the beginning of the output range.
2668
3.13k
  constexpr auto out() const -> iterator { return out_; }
2669
2670
  // Advances the begin iterator to `it`.
2671
0
  FMT_CONSTEXPR void advance_to(iterator) {}
2672
2673
1.04k
  constexpr auto locale() const -> locale_ref { return loc_; }
2674
};
2675
2676
template <typename Char = char> struct runtime_format_string {
2677
  basic_string_view<Char> str;
2678
};
2679
2680
/**
2681
 * Creates a runtime format string.
2682
 *
2683
 * **Example**:
2684
 *
2685
 *     // Check format string at runtime instead of compile-time.
2686
 *     fmt::print(fmt::runtime("{:d}"), "I am not a number");
2687
 */
2688
0
inline auto runtime(string_view s) -> runtime_format_string<> { return {{s}}; }
2689
2690
/// A compile-time format string. Use `format_string` in the public API to
2691
/// prevent type deduction.
2692
template <typename... T> struct fstring {
2693
 private:
2694
  static constexpr int num_static_named_args =
2695
      detail::count_static_named_args<T...>();
2696
2697
  using checker = detail::format_string_checker<
2698
      char, int(sizeof...(T)), num_static_named_args,
2699
      num_static_named_args != detail::count_named_args<T...>()>;
2700
2701
  using arg_pack = detail::arg_pack<T...>;
2702
2703
 public:
2704
  string_view str;
2705
  using t = fstring;
2706
2707
  // Reports a compile-time error if S is not a valid format string for T.
2708
  template <size_t N>
2709
  FMT_CONSTEVAL FMT_ALWAYS_INLINE fstring(const char (&s)[N]) : str(s, N - 1) {
2710
    using namespace detail;
2711
    static_assert(count<(is_view<remove_cvref_t<T>>::value &&
2712
                         std::is_reference<T>::value)...>() == 0,
2713
                  "passing views as lvalues is disallowed");
2714
    if (FMT_USE_CONSTEVAL)
2715
      parse_format_string<char>(str, checker(str, arg_pack()));
2716
    constexpr bool unused = detail::enforce_compile_checks<sizeof(s) != 0>();
2717
    (void)unused;
2718
  }
2719
  template <typename S,
2720
            FMT_ENABLE_IF(std::is_convertible<const S&, string_view>::value)>
2721
2.09k
  FMT_CONSTEVAL FMT_ALWAYS_INLINE fstring(const S& s) : str(s) {
2722
2.09k
    if (FMT_USE_CONSTEVAL)
2723
0
      detail::parse_format_string<char>(str, checker(str, arg_pack()));
2724
2.09k
    constexpr bool unused = detail::enforce_compile_checks<sizeof(s) != 0>();
2725
2.09k
    (void)unused;
2726
2.09k
  }
2727
  template <typename S,
2728
            FMT_ENABLE_IF(std::is_base_of<detail::compile_string, S>::value&&
2729
                              std::is_same<typename S::char_type, char>::value)>
2730
0
  FMT_ALWAYS_INLINE fstring(const S&) : str(S()) {
2731
0
    FMT_CONSTEXPR auto sv = string_view(S());
2732
0
    FMT_CONSTEXPR int x = (parse_format_string(sv, checker(sv, arg_pack())), 0);
2733
0
    detail::ignore_unused(x);
2734
0
  }
Unexecuted instantiation: _ZN3fmt3v127fstringIJEEC2IZZNS0_6detail10fwrite_allEPKvmP8_IO_FILEENKUlvE_clEvE18FMT_COMPILE_STRINGTnNSt3__19enable_ifIXaasr3std10is_base_ofINS4_14compile_stringET_EE5valuesr3std7is_sameINSE_9char_typeEcEE5valueEiE4typeELi0EEERKSE_
Unexecuted instantiation: format.cc:_ZN3fmt3v127fstringIJRNS0_17basic_string_viewIcEERA3_KcEEC2IZZNS0_6detail17format_error_codeERNSA_6bufferIcEEiS3_ENK3$_0clEvE18FMT_COMPILE_STRINGTnNSt3__19enable_ifIXaasr3std10is_base_ofINSA_14compile_stringET_EE5valuesr3std7is_sameINSJ_9char_typeEcEE5valueEiE4typeELi0EEERKSJ_
Unexecuted instantiation: format.cc:_ZN3fmt3v127fstringIJRA7_KcRiEEC2IZZNS0_6detail17format_error_codeERNS8_6bufferIcEEiNS0_17basic_string_viewIcEEENK3$_1clEvE18FMT_COMPILE_STRINGTnNSt3__19enable_ifIXaasr3std10is_base_ofINS8_14compile_stringET_EE5valuesr3std7is_sameINSJ_9char_typeEcEE5valueEiE4typeELi0EEERKSJ_
Unexecuted instantiation: _ZN3fmt3v127fstringIJEEC2IZZNS0_6detail10glibc_fileI8_IO_FILEE5flushEvENKUlvE_clEvE18FMT_COMPILE_STRINGTnNSt3__19enable_ifIXaasr3std10is_base_ofINS4_14compile_stringET_EE5valuesr3std7is_sameINSD_9char_typeEcEE5valueEiE4typeELi0EEERKSD_
2735
  fstring(runtime_format_string<> fmt) : str(fmt.str) {}
2736
2737
  FMT_DEPRECATED operator const string_view&() const { return str; }
2738
  auto get() const -> string_view { return str; }
2739
};
2740
2741
template <typename... T> using format_string = typename fstring<T...>::t;
2742
2743
template <typename T, typename Char = char>
2744
using is_formattable = bool_constant<!std::is_same<
2745
    detail::mapped_t<conditional_t<std::is_void<T>::value, int*, T>, Char>,
2746
    void>::value>;
2747
#if defined(__cpp_concepts) && __cpp_concepts >= 201907L
2748
template <typename T, typename Char = char>
2749
concept formattable = is_formattable<remove_reference_t<T>, Char>::value;
2750
#endif
2751
2752
// A formatter specialization for natively supported types.
2753
template <typename T, typename Char>
2754
struct formatter<T, Char,
2755
                 enable_if_t<detail::type_constant<T, Char>::value !=
2756
                             detail::type::custom_type>>
2757
    : detail::native_formatter<T, Char, detail::type_constant<T, Char>::value> {
2758
};
2759
2760
/**
2761
 * Constructs an object that stores references to arguments and can be
2762
 * implicitly converted to `format_args`. `Context` can be omitted in which case
2763
 * it defaults to `context`. See `arg` for lifetime considerations.
2764
 */
2765
// Take arguments by lvalue references to avoid some lifetime issues, e.g.
2766
//   auto args = make_format_args(std::string());
2767
template <typename Context = context, typename... T,
2768
          int NUM_ARGS = int(sizeof...(T)),
2769
          int NUM_NAMED_ARGS = detail::count_named_args<T...>(),
2770
          ullong DESC = detail::make_descriptor<Context, T...>()>
2771
constexpr FMT_ALWAYS_INLINE auto make_format_args(T&... args)
2772
    -> detail::format_arg_store<Context, NUM_ARGS, NUM_NAMED_ARGS, DESC> {
2773
  return {{args...}};
2774
}
2775
2776
template <typename... T>
2777
using vargs =
2778
    detail::format_arg_store<context, int(sizeof...(T)),
2779
                             detail::count_named_args<T...>(),
2780
                             detail::make_descriptor<context, T...>()>;
2781
2782
/**
2783
 * Returns a named argument to be used in a formatting function.
2784
 * It should only be used in a call to a formatting function.
2785
 *
2786
 * **Example**:
2787
 *
2788
 *     fmt::print("The answer is {answer}.", fmt::arg("answer", 42));
2789
 *
2790
 * Named arguments passed with `fmt::arg` are not supported
2791
 * in compile-time checks, but `"answer"_a=42` are compile-time checked in
2792
 * sufficiently new compilers. See `operator""_a()`.
2793
 */
2794
template <typename T>
2795
inline auto arg(const char* name, const T& arg) -> named_arg<T> {
2796
  return {name, arg};
2797
}
2798
2799
/// Formats a string and writes the output to `out`.
2800
template <typename OutputIt,
2801
          FMT_ENABLE_IF(detail::is_output_iterator<remove_cvref_t<OutputIt>,
2802
                                                   char>::value)>
2803
// DEPRECATED! Passing out as a forwarding reference.
2804
auto vformat_to(OutputIt&& out, string_view fmt, format_args args)
2805
2.09k
    -> remove_cvref_t<OutputIt> {
2806
2.09k
  auto&& buf = detail::get_buffer<char>(out);
2807
2.09k
  detail::vformat_to(buf, fmt, args, {});
2808
2.09k
  return detail::get_iterator(buf, out);
2809
2.09k
}
_ZN3fmt3v1210vformat_toIRNSt3__120back_insert_iteratorINS0_19basic_memory_bufferIcLm500ENS0_6detail9allocatorIcEEEEEETnNS2_9enable_ifIXsr6detail18is_output_iteratorINS2_9remove_cvINS2_16remove_referenceIT_E4typeEE4typeEcEE5valueEiE4typeELi0EEESI_OSE_NS0_17basic_string_viewIcEENS0_17basic_format_argsINS0_7contextEEE
Line
Count
Source
2805
2.09k
    -> remove_cvref_t<OutputIt> {
2806
2.09k
  auto&& buf = detail::get_buffer<char>(out);
2807
2.09k
  detail::vformat_to(buf, fmt, args, {});
2808
2.09k
  return detail::get_iterator(buf, out);
2809
2.09k
}
Unexecuted instantiation: _ZN3fmt3v1210vformat_toIRNS0_14basic_appenderIcEETnNSt3__19enable_ifIXsr6detail18is_output_iteratorINS5_9remove_cvINS5_16remove_referenceIT_E4typeEE4typeEcEE5valueEiE4typeELi0EEESD_OS9_NS0_17basic_string_viewIcEENS0_17basic_format_argsINS0_7contextEEE
2810
2811
/**
2812
 * Formats `args` according to specifications in `fmt`, writes the result to
2813
 * the output iterator `out` and returns the iterator past the end of the output
2814
 * range. `format_to` does not append a terminating null character.
2815
 *
2816
 * **Example**:
2817
 *
2818
 *     auto out = std::vector<char>();
2819
 *     fmt::format_to(std::back_inserter(out), "{}", 42);
2820
 */
2821
template <typename OutputIt, typename... T,
2822
          FMT_ENABLE_IF(detail::is_output_iterator<remove_cvref_t<OutputIt>,
2823
                                                   char>::value)>
2824
FMT_INLINE auto format_to(OutputIt&& out, format_string<T...> fmt, T&&... args)
2825
2.09k
    -> remove_cvref_t<OutputIt> {
2826
2.09k
  return vformat_to(out, fmt.str, vargs<T...>{{args...}});
2827
2.09k
}
_ZN3fmt3v129format_toINSt3__120back_insert_iteratorINS0_19basic_memory_bufferIcLm500ENS0_6detail9allocatorIcEEEEEEJRdETnNS2_9enable_ifIXsr6detail18is_output_iteratorINS2_9remove_cvINS2_16remove_referenceIT_E4typeEE4typeEcEE5valueEiE4typeELi0EEESI_OSE_NS0_7fstringIJDpT0_EE1tEDpOSN_
Line
Count
Source
2825
2.09k
    -> remove_cvref_t<OutputIt> {
2826
2.09k
  return vformat_to(out, fmt.str, vargs<T...>{{args...}});
2827
2.09k
}
Unexecuted instantiation: _ZN3fmt3v129format_toIRNS0_14basic_appenderIcEEJRNS0_17basic_string_viewIcEERA3_KcETnNSt3__19enable_ifIXsr6detail18is_output_iteratorINSB_9remove_cvINSB_16remove_referenceIT_E4typeEE4typeEcEE5valueEiE4typeELi0EEESJ_OSF_NS0_7fstringIJDpT0_EE1tEDpOSO_
Unexecuted instantiation: _ZN3fmt3v129format_toIRNS0_14basic_appenderIcEEJRA7_KcRiETnNSt3__19enable_ifIXsr6detail18is_output_iteratorINS9_9remove_cvINS9_16remove_referenceIT_E4typeEE4typeEcEE5valueEiE4typeELi0EEESH_OSD_NS0_7fstringIJDpT0_EE1tEDpOSM_
Unexecuted instantiation: _ZN3fmt3v129format_toIRNS0_14basic_appenderIcEEJRjETnNSt3__19enable_ifIXsr6detail18is_output_iteratorINS6_9remove_cvINS6_16remove_referenceIT_E4typeEE4typeEcEE5valueEiE4typeELi0EEESE_OSA_NS0_7fstringIJDpT0_EE1tEDpOSJ_
Unexecuted instantiation: _ZN3fmt3v129format_toIRNS0_14basic_appenderIcEEJiETnNSt3__19enable_ifIXsr6detail18is_output_iteratorINS5_9remove_cvINS5_16remove_referenceIT_E4typeEE4typeEcEE5valueEiE4typeELi0EEESD_OS9_NS0_7fstringIJDpT0_EE1tEDpOSI_
2828
2829
template <typename OutputIt> struct format_to_n_result {
2830
  OutputIt out;  ///< Iterator past the end of the output range.
2831
  size_t size;   ///< Total (not truncated) output size.
2832
};
2833
2834
template <typename OutputIt, typename... T,
2835
          FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
2836
auto vformat_to_n(OutputIt out, size_t n, string_view fmt, format_args args)
2837
    -> format_to_n_result<OutputIt> {
2838
  using traits = detail::fixed_buffer_traits;
2839
  auto buf = detail::iterator_buffer<OutputIt, char, traits>(out, n);
2840
  detail::vformat_to(buf, fmt, args, {});
2841
  return {buf.out(), buf.count()};
2842
}
2843
2844
/**
2845
 * Formats `args` according to specifications in `fmt`, writes up to `n`
2846
 * characters of the result to the output iterator `out` and returns the total
2847
 * (not truncated) output size and the iterator past the end of the output
2848
 * range. `format_to_n` does not append a terminating null character.
2849
 */
2850
template <typename OutputIt, typename... T,
2851
          FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
2852
FMT_INLINE auto format_to_n(OutputIt out, size_t n, format_string<T...> fmt,
2853
                            T&&... args) -> format_to_n_result<OutputIt> {
2854
  return vformat_to_n(out, n, fmt.str, vargs<T...>{{args...}});
2855
}
2856
2857
struct format_to_result {
2858
  char* out;       ///< Pointer to just after the last successful write.
2859
  bool truncated;  ///< Specifies if the output was truncated.
2860
2861
0
  FMT_CONSTEXPR operator char*() const {
2862
0
    // Report truncation to prevent silent data loss.
2863
0
    if (truncated) report_error("output is truncated");
2864
0
    return out;
2865
0
  }
2866
};
2867
2868
template <size_t N>
2869
FMT_DEPRECATED auto vformat_to(char (&out)[N], string_view fmt,
2870
                               format_args args) -> format_to_result {
2871
  auto result = vformat_to_n(out, N, fmt, args);
2872
  return {result.out, result.size > N};
2873
}
2874
2875
template <size_t N, typename... T>
2876
FMT_INLINE auto format_to(char (&out)[N], format_string<T...> fmt, T&&... args)
2877
    -> format_to_result {
2878
  auto result = vformat_to_n(out, N, fmt.str, vargs<T...>{{args...}});
2879
  return {result.out, result.size > N};
2880
}
2881
2882
/// Returns the number of chars in the output of `format(fmt, args...)`.
2883
template <typename... T>
2884
FMT_NODISCARD FMT_INLINE auto formatted_size(format_string<T...> fmt,
2885
                                             T&&... args) -> size_t {
2886
  auto buf = detail::counting_buffer<>();
2887
  detail::vformat_to(buf, fmt.str, vargs<T...>{{args...}}, {});
2888
  return buf.count();
2889
}
2890
2891
FMT_API void vprint(string_view fmt, format_args args);
2892
FMT_API void vprint(FILE* f, string_view fmt, format_args args);
2893
FMT_API void vprintln(FILE* f, string_view fmt, format_args args);
2894
FMT_API void vprint_buffered(FILE* f, string_view fmt, format_args args);
2895
2896
/**
2897
 * Formats `args` according to specifications in `fmt` and writes the output
2898
 * to `stdout`.
2899
 *
2900
 * **Example**:
2901
 *
2902
 *     fmt::print("The answer is {}.", 42);
2903
 */
2904
template <typename... T>
2905
FMT_INLINE void print(format_string<T...> fmt, T&&... args) {
2906
  vargs<T...> va = {{args...}};
2907
  if FMT_CONSTEXPR20 (!detail::use_utf8)
2908
    return detail::vprint_mojibake(stdout, fmt.str, va, false);
2909
  detail::is_locking<T...>() ? vprint_buffered(stdout, fmt.str, va)
2910
                             : vprint(fmt.str, va);
2911
}
2912
2913
/**
2914
 * Formats `args` according to specifications in `fmt` and writes the
2915
 * output to the file `f`.
2916
 *
2917
 * **Example**:
2918
 *
2919
 *     fmt::print(stderr, "Don't {}!", "panic");
2920
 */
2921
template <typename... T>
2922
FMT_INLINE void print(FILE* f, format_string<T...> fmt, T&&... args) {
2923
  vargs<T...> va = {{args...}};
2924
  if FMT_CONSTEXPR20 (!detail::use_utf8)
2925
    return detail::vprint_mojibake(f, fmt.str, va, false);
2926
  detail::is_locking<T...>() ? vprint_buffered(f, fmt.str, va)
2927
                             : vprint(f, fmt.str, va);
2928
}
2929
2930
/// Formats `args` according to specifications in `fmt` and writes the output
2931
/// to the file `f` followed by a newline.
2932
template <typename... T>
2933
FMT_INLINE void println(FILE* f, format_string<T...> fmt, T&&... args) {
2934
  vargs<T...> va = {{args...}};
2935
  if FMT_CONSTEXPR20 (detail::use_utf8) return vprintln(f, fmt.str, va);
2936
  detail::vprint_mojibake(f, fmt.str, va, true);
2937
}
2938
2939
/// Formats `args` according to specifications in `fmt` and writes the output
2940
/// to `stdout` followed by a newline.
2941
template <typename... T>
2942
FMT_INLINE void println(format_string<T...> fmt, T&&... args) {
2943
  fmt::println(stdout, fmt, static_cast<T&&>(args)...);
2944
}
2945
2946
FMT_PRAGMA_GCC(pop_options)
2947
FMT_PRAGMA_MSVC(warning(pop))
2948
FMT_END_EXPORT
2949
FMT_END_NAMESPACE
2950
2951
#ifdef FMT_HEADER_ONLY
2952
#  include "format.h"
2953
#endif
2954
#endif  // FMT_BASE_H_