spdlog
Loading...
Searching...
No Matches
core.h
Go to the documentation of this file.
1// Formatting library for C++ - the core API for char/UTF-8
2//
3// Copyright (c) 2012 - present, Victor Zverovich
4// All rights reserved.
5//
6// For the license information refer to format.h.
7
8#ifndef FMT_CORE_H_
9#define FMT_CORE_H_
10
11#include <cstdio> // std::FILE
12#include <cstring>
13#include <iterator>
14#include <limits>
15#include <string>
16#include <type_traits>
17
18// The fmt library version in the form major * 10000 + minor * 100 + patch.
19#define FMT_VERSION 80001
20
21#ifdef __clang__
22# define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
23#else
24# define FMT_CLANG_VERSION 0
25#endif
26
27#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
28# define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
29# define FMT_GCC_PRAGMA(arg) _Pragma(arg)
30#else
31# define FMT_GCC_VERSION 0
32# define FMT_GCC_PRAGMA(arg)
33#endif
34
35#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
36# define FMT_HAS_GXX_CXX11 FMT_GCC_VERSION
37#else
38# define FMT_HAS_GXX_CXX11 0
39#endif
40
41#if defined(__INTEL_COMPILER)
42# define FMT_ICC_VERSION __INTEL_COMPILER
43#else
44# define FMT_ICC_VERSION 0
45#endif
46
47#ifdef __NVCC__
48# define FMT_NVCC __NVCC__
49#else
50# define FMT_NVCC 0
51#endif
52
53#ifdef _MSC_VER
54# define FMT_MSC_VER _MSC_VER
55# define FMT_MSC_WARNING(...) __pragma(warning(__VA_ARGS__))
56#else
57# define FMT_MSC_VER 0
58# define FMT_MSC_WARNING(...)
59#endif
60
61#ifdef __has_feature
62# define FMT_HAS_FEATURE(x) __has_feature(x)
63#else
64# define FMT_HAS_FEATURE(x) 0
65#endif
66
67#if defined(__has_include) && \
68 (!defined(__INTELLISENSE__) || FMT_MSC_VER > 1900) && \
69 (!FMT_ICC_VERSION || FMT_ICC_VERSION >= 1600)
70# define FMT_HAS_INCLUDE(x) __has_include(x)
71#else
72# define FMT_HAS_INCLUDE(x) 0
73#endif
74
75#ifdef __has_cpp_attribute
76# define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
77#else
78# define FMT_HAS_CPP_ATTRIBUTE(x) 0
79#endif
80
81#define FMT_HAS_CPP14_ATTRIBUTE(attribute) \
82 (__cplusplus >= 201402L && FMT_HAS_CPP_ATTRIBUTE(attribute))
83
84#define FMT_HAS_CPP17_ATTRIBUTE(attribute) \
85 (__cplusplus >= 201703L && FMT_HAS_CPP_ATTRIBUTE(attribute))
86
87// Check if relaxed C++14 constexpr is supported.
88// GCC doesn't allow throw in constexpr until version 6 (bug 67371).
89#ifndef FMT_USE_CONSTEXPR
90# define FMT_USE_CONSTEXPR \
91 (FMT_HAS_FEATURE(cxx_relaxed_constexpr) || FMT_MSC_VER >= 1910 || \
92 (FMT_GCC_VERSION >= 600 && __cplusplus >= 201402L)) && \
93 !FMT_NVCC && !FMT_ICC_VERSION
94#endif
95#if FMT_USE_CONSTEXPR
96# define FMT_CONSTEXPR constexpr
97# define FMT_CONSTEXPR_DECL constexpr
98#else
99# define FMT_CONSTEXPR
100# define FMT_CONSTEXPR_DECL
101#endif
102
103// Check if constexpr std::char_traits<>::compare,length is supported.
104#if defined(__GLIBCXX__)
105# if __cplusplus >= 201703L && defined(_GLIBCXX_RELEASE) && \
106 _GLIBCXX_RELEASE >= 7 // GCC 7+ libstdc++ has _GLIBCXX_RELEASE.
107# define FMT_CONSTEXPR_CHAR_TRAITS constexpr
108# endif
109#elif defined(_LIBCPP_VERSION) && __cplusplus >= 201703L && \
110 _LIBCPP_VERSION >= 4000
111# define FMT_CONSTEXPR_CHAR_TRAITS constexpr
112#elif FMT_MSC_VER >= 1914 && _MSVC_LANG >= 201703L
113# define FMT_CONSTEXPR_CHAR_TRAITS constexpr
114#endif
115#ifndef FMT_CONSTEXPR_CHAR_TRAITS
116# define FMT_CONSTEXPR_CHAR_TRAITS
117#endif
118
119#ifndef FMT_OVERRIDE
120# if FMT_HAS_FEATURE(cxx_override_control) || \
121 (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900
122# define FMT_OVERRIDE override
123# else
124# define FMT_OVERRIDE
125# endif
126#endif
127
128// Check if exceptions are disabled.
129#ifndef FMT_EXCEPTIONS
130# if (defined(__GNUC__) && !defined(__EXCEPTIONS)) || \
131 FMT_MSC_VER && !_HAS_EXCEPTIONS
132# define FMT_EXCEPTIONS 0
133# else
134# define FMT_EXCEPTIONS 1
135# endif
136#endif
137
138// Define FMT_USE_NOEXCEPT to make fmt use noexcept (C++11 feature).
139#ifndef FMT_USE_NOEXCEPT
140# define FMT_USE_NOEXCEPT 0
141#endif
142
143#if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \
144 (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900
145# define FMT_DETECTED_NOEXCEPT noexcept
146# define FMT_HAS_CXX11_NOEXCEPT 1
147#else
148# define FMT_DETECTED_NOEXCEPT throw()
149# define FMT_HAS_CXX11_NOEXCEPT 0
150#endif
151
152#ifndef FMT_NOEXCEPT
153# if FMT_EXCEPTIONS || FMT_HAS_CXX11_NOEXCEPT
154# define FMT_NOEXCEPT FMT_DETECTED_NOEXCEPT
155# else
156# define FMT_NOEXCEPT
157# endif
158#endif
159
160// [[noreturn]] is disabled on MSVC and NVCC because of bogus unreachable code
161// warnings.
162#if FMT_EXCEPTIONS && FMT_HAS_CPP_ATTRIBUTE(noreturn) && !FMT_MSC_VER && \
163 !FMT_NVCC
164# define FMT_NORETURN [[noreturn]]
165#else
166# define FMT_NORETURN
167#endif
168
169#ifndef FMT_MAYBE_UNUSED
170# if FMT_HAS_CPP17_ATTRIBUTE(maybe_unused)
171# define FMT_MAYBE_UNUSED [[maybe_unused]]
172# else
173# define FMT_MAYBE_UNUSED
174# endif
175#endif
176
177#if __cplusplus == 201103L || __cplusplus == 201402L
178# if defined(__INTEL_COMPILER) || defined(__PGI)
179# define FMT_FALLTHROUGH
180# elif defined(__clang__)
181# define FMT_FALLTHROUGH [[clang::fallthrough]]
182# elif FMT_GCC_VERSION >= 700 && \
183 (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 520)
184# define FMT_FALLTHROUGH [[gnu::fallthrough]]
185# else
186# define FMT_FALLTHROUGH
187# endif
188#elif FMT_HAS_CPP17_ATTRIBUTE(fallthrough) || \
189 (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
190# define FMT_FALLTHROUGH [[fallthrough]]
191#else
192# define FMT_FALLTHROUGH
193#endif
194
195#ifndef FMT_USE_FLOAT
196# define FMT_USE_FLOAT 1
197#endif
198#ifndef FMT_USE_DOUBLE
199# define FMT_USE_DOUBLE 1
200#endif
201#ifndef FMT_USE_LONG_DOUBLE
202# define FMT_USE_LONG_DOUBLE 1
203#endif
204
205#ifndef FMT_INLINE
206# if FMT_GCC_VERSION || FMT_CLANG_VERSION
207# define FMT_INLINE inline __attribute__((always_inline))
208# else
209# define FMT_INLINE inline
210# endif
211#endif
212
213#ifndef FMT_USE_INLINE_NAMESPACES
214# if FMT_HAS_FEATURE(cxx_inline_namespaces) || FMT_GCC_VERSION >= 404 || \
215 (FMT_MSC_VER >= 1900 && (!defined(_MANAGED) || !_MANAGED))
216# define FMT_USE_INLINE_NAMESPACES 1
217# else
218# define FMT_USE_INLINE_NAMESPACES 0
219# endif
220#endif
221
222#ifndef FMT_BEGIN_NAMESPACE
223# if FMT_USE_INLINE_NAMESPACES
224# define FMT_INLINE_NAMESPACE inline namespace
225# define FMT_END_NAMESPACE \
226 } \
227 }
228# else
229# define FMT_INLINE_NAMESPACE namespace
230# define FMT_END_NAMESPACE \
231 } \
232 using namespace v8; \
233 }
234# endif
235# define FMT_BEGIN_NAMESPACE \
236 namespace fmt { \
237 FMT_INLINE_NAMESPACE v8 {
238#endif
239
240#ifndef FMT_MODULE_EXPORT
241# define FMT_MODULE_EXPORT
242# define FMT_MODULE_EXPORT_BEGIN
243# define FMT_MODULE_EXPORT_END
244# define FMT_BEGIN_DETAIL_NAMESPACE namespace detail {
245# define FMT_END_DETAIL_NAMESPACE }
246#endif
247
248#if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
249# define FMT_CLASS_API FMT_MSC_WARNING(suppress : 4275)
250# ifdef FMT_EXPORT
251# define FMT_API __declspec(dllexport)
252# elif defined(FMT_SHARED)
253# define FMT_API __declspec(dllimport)
254# endif
255#else
256# define FMT_CLASS_API
257# if defined(FMT_EXPORT) || defined(FMT_SHARED)
258# if defined(__GNUC__) || defined(__clang__)
259# define FMT_API __attribute__((visibility("default")))
260# endif
261# endif
262#endif
263#ifndef FMT_API
264# define FMT_API
265#endif
266
267#if FMT_GCC_VERSION
268# define FMT_GCC_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
269#else
270# define FMT_GCC_VISIBILITY_HIDDEN
271#endif
272
273// libc++ supports string_view in pre-c++17.
274#if (FMT_HAS_INCLUDE(<string_view>) && \
275 (__cplusplus > 201402L || defined(_LIBCPP_VERSION))) || \
276 (defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910)
277# include <string_view>
278# define FMT_USE_STRING_VIEW
279#elif FMT_HAS_INCLUDE("experimental/string_view") && __cplusplus >= 201402L
280# include <experimental/string_view>
281# define FMT_USE_EXPERIMENTAL_STRING_VIEW
282#endif
283
284#ifndef FMT_UNICODE
285# define FMT_UNICODE !FMT_MSC_VER
286#endif
287
288#ifndef FMT_CONSTEVAL
289# if ((FMT_GCC_VERSION >= 1000 || FMT_CLANG_VERSION >= 1101) && \
290 __cplusplus > 201703L) || \
291 (defined(__cpp_consteval) && \
292 !FMT_MSC_VER) // consteval is broken in MSVC.
293# define FMT_CONSTEVAL consteval
294# define FMT_HAS_CONSTEVAL
295# else
296# define FMT_CONSTEVAL
297# endif
298#endif
299
300#ifndef FMT_USE_NONTYPE_TEMPLATE_PARAMETERS
301# if defined(__cpp_nontype_template_args) && \
302 ((FMT_GCC_VERSION >= 903 && __cplusplus >= 201709L) || \
303 __cpp_nontype_template_args >= 201911L)
304# define FMT_USE_NONTYPE_TEMPLATE_PARAMETERS 1
305# else
306# define FMT_USE_NONTYPE_TEMPLATE_PARAMETERS 0
307# endif
308#endif
309
310// Enable minimal optimizations for more compact code in debug mode.
311FMT_GCC_PRAGMA("GCC push_options")
312#ifndef __OPTIMIZE__
313FMT_GCC_PRAGMA("GCC optimize(\"Og\")")
314#endif
315
318
319// Implementations of enable_if_t and other metafunctions for older systems.
320template <bool B, typename T = void>
321using enable_if_t = typename std::enable_if<B, T>::type;
322template <bool B, typename T, typename F>
325template <typename T>
327template <typename T>
329template <typename T> struct type_identity { using type = T; };
330template <typename T> using type_identity_t = typename type_identity<T>::type;
331
332struct monostate {
333 constexpr monostate() {}
334};
335
336// Suppress "unused variable" warnings with the method described in
337// https://herbsutter.com/2009/10/18/mailbag-shutting-up-compiler-warnings/.
338// (void)var does not work on many Intel compilers.
339template <typename... T> FMT_CONSTEXPR void ignore_unused(const T&...) {}
340
341// An enable_if helper to be used in template parameters which results in much
342// shorter symbols: https://godbolt.org/z/sWw4vP. Extra parentheses are needed
343// to workaround a bug in MSVC 2019 (see #1140 and #1186).
344#ifdef FMT_DOC
345# define FMT_ENABLE_IF(...)
346#else
347# define FMT_ENABLE_IF(...) enable_if_t<(__VA_ARGS__), int> = 0
348#endif
349
351
353#ifdef __cpp_lib_is_constant_evaluated
355#else
356 return false;
357#endif
358}
359
360// A function to suppress "conditional expression is constant" warnings.
361template <typename T> constexpr auto const_check(T value) -> T { return value; }
362
363FMT_NORETURN FMT_API void assert_fail(const char* file, int line,
364 const char* message);
365
366#ifndef FMT_ASSERT
367# ifdef NDEBUG
368// FMT_ASSERT is not empty to avoid -Werror=empty-body.
369# define FMT_ASSERT(condition, message) \
370 ::fmt::ignore_unused((condition), (message))
371# else
372# define FMT_ASSERT(condition, message) \
373 ((condition) /* void() fails with -Winvalid-constexpr on clang 4.0.1 */ \
374 ? (void)0 \
375 : ::fmt::detail::assert_fail(__FILE__, __LINE__, (message)))
376# endif
377#endif
378
379#if defined(FMT_USE_STRING_VIEW)
380template <typename Char> using std_string_view = std::basic_string_view<Char>;
381#elif defined(FMT_USE_EXPERIMENTAL_STRING_VIEW)
382template <typename Char>
384#else
385template <typename T> struct std_string_view {};
386#endif
387
388#ifdef FMT_USE_INT128
389// Do nothing.
390#elif defined(__SIZEOF_INT128__) && !FMT_NVCC && \
391 !(FMT_CLANG_VERSION && FMT_MSC_VER)
392# define FMT_USE_INT128 1
393using int128_t = __int128_t;
394using uint128_t = __uint128_t;
395template <typename T> inline auto convert_for_visit(T value) -> T {
396 return value;
397}
398#else
399# define FMT_USE_INT128 0
400#endif
401#if !FMT_USE_INT128
402enum class int128_t {};
403enum class uint128_t {};
404// Reduce template instantiations.
405template <typename T> inline auto convert_for_visit(T) -> monostate {
406 return {};
407}
408#endif
409
410// Casts a nonnegative integer to unsigned.
411template <typename Int>
414 FMT_ASSERT(value >= 0, "negative value");
415 return static_cast<typename std::make_unsigned<Int>::type>(value);
416}
417
418FMT_MSC_WARNING(suppress : 4566) constexpr unsigned char micro[] = "\u00B5";
419
420constexpr auto is_utf8() -> bool {
421 // Avoid buggy sign extensions in MSVC's constant evaluation mode.
422 // https://developercommunity.visualstudio.com/t/C-difference-in-behavior-for-unsigned/1233612
423 using uchar = unsigned char;
424 return FMT_UNICODE || (sizeof(micro) == 3 && uchar(micro[0]) == 0xC2 &&
425 uchar(micro[1]) == 0xB5);
426}
428
429/**
430 An implementation of ``std::basic_string_view`` for pre-C++17. It provides a
431 subset of the API. ``fmt::basic_string_view`` is used for format strings even
432 if ``std::string_view`` is available to prevent issues when a library is
433 compiled with a different ``-std`` option than the client code (which is not
434 recommended).
435 */
436template <typename Char> class basic_string_view {
437 private:
438 const Char* data_;
439 size_t size_;
440
441 public:
442 using value_type = Char;
443 using iterator = const Char*;
444
445 constexpr basic_string_view() FMT_NOEXCEPT : data_(nullptr), size_(0) {}
446
447 /** Constructs a string reference object from a C string and a size. */
448 constexpr basic_string_view(const Char* s, size_t count) FMT_NOEXCEPT
449 : data_(s),
450 size_(count) {}
451
452 /**
453 \rst
454 Constructs a string reference object from a C string computing
455 the size with ``std::char_traits<Char>::length``.
456 \endrst
457 */
460 basic_string_view(const Char* s) : data_(s) {
461 if (detail::const_check(std::is_same<Char, char>::value &&
462 !detail::is_constant_evaluated()))
463 size_ = std::strlen(reinterpret_cast<const char*>(s));
464 else
466 }
467
468 /** Constructs a string reference from a ``std::basic_string`` object. */
469 template <typename Traits, typename Alloc>
474
475 template <typename S, FMT_ENABLE_IF(std::is_same<
476 S, detail::std_string_view<Char>>::value)>
478 size_(s.size()) {}
479
480 /** Returns a pointer to the string data. */
481 constexpr auto data() const -> const Char* { return data_; }
482
483 /** Returns the string size. */
484 constexpr auto size() const -> size_t { return size_; }
485
486 constexpr auto begin() const -> iterator { return data_; }
487 constexpr auto end() const -> iterator { return data_ + size_; }
488
489 constexpr auto operator[](size_t pos) const -> const Char& {
490 return data_[pos];
491 }
492
494 data_ += n;
495 size_ -= n;
496 }
497
498 // Lexicographically compare this string reference to other.
500 size_t str_size = size_ < other.size_ ? size_ : other.size_;
501 int result = std::char_traits<Char>::compare(data_, other.data_, str_size);
502 if (result == 0)
503 result = size_ == other.size_ ? 0 : (size_ < other.size_ ? -1 : 1);
504 return result;
505 }
506
509 -> bool {
510 return lhs.compare(rhs) == 0;
511 }
512 friend auto operator!=(basic_string_view lhs, basic_string_view rhs) -> bool {
513 return lhs.compare(rhs) != 0;
514 }
515 friend auto operator<(basic_string_view lhs, basic_string_view rhs) -> bool {
516 return lhs.compare(rhs) < 0;
517 }
518 friend auto operator<=(basic_string_view lhs, basic_string_view rhs) -> bool {
519 return lhs.compare(rhs) <= 0;
520 }
521 friend auto operator>(basic_string_view lhs, basic_string_view rhs) -> bool {
522 return lhs.compare(rhs) > 0;
523 }
524 friend auto operator>=(basic_string_view lhs, basic_string_view rhs) -> bool {
525 return lhs.compare(rhs) >= 0;
526 }
527};
528
530
531/** Specifies if ``T`` is a character type. Can be specialized by users. */
532template <typename T> struct is_char : std::false_type {};
533template <> struct is_char<char> : std::true_type {};
534
535// Returns a string view of `s`.
536template <typename Char, FMT_ENABLE_IF(is_char<Char>::value)>
537FMT_INLINE auto to_string_view(const Char* s) -> basic_string_view<Char> {
538 return s;
539}
540template <typename Char, typename Traits, typename Alloc>
541inline auto to_string_view(const std::basic_string<Char, Traits, Alloc>& s)
543 return s;
544}
545template <typename Char>
546constexpr auto to_string_view(basic_string_view<Char> s)
548 return s;
549}
550template <typename Char,
551 FMT_ENABLE_IF(!std::is_empty<detail::std_string_view<Char>>::value)>
552inline auto to_string_view(detail::std_string_view<Char> s)
554 return s;
555}
556
557// A base class for compile-time strings. It is defined in the fmt namespace to
558// make formatting functions visible via ADL, e.g. format(FMT_STRING("{}"), 42).
560
561template <typename S>
562struct is_compile_string : std::is_base_of<compile_string, S> {};
563
564template <typename S, FMT_ENABLE_IF(is_compile_string<S>::value)>
565constexpr auto to_string_view(const S& s)
568}
569
571
572void to_string_view(...);
573using fmt::v8::to_string_view;
574
575// Specifies whether S is a string type convertible to fmt::basic_string_view.
576// It should be a constexpr function but MSVC 2017 fails to compile it in
577// enable_if and MSVC 2015 fails to compile it as an alias template.
578template <typename S>
579struct is_string : std::is_class<decltype(to_string_view(std::declval<S>()))> {
580};
581
582template <typename S, typename = void> struct char_t_impl {};
583template <typename S> struct char_t_impl<S, enable_if_t<is_string<S>::value>> {
584 using result = decltype(to_string_view(std::declval<S>()));
585 using type = typename result::value_type;
586};
587
588// Reports a compile-time error if S is not a valid format string.
589template <typename..., typename S, FMT_ENABLE_IF(!is_compile_string<S>::value)>
591#ifdef FMT_ENFORCE_COMPILE_STRING
592 static_assert(is_compile_string<S>::value,
593 "FMT_ENFORCE_COMPILE_STRING requires all format strings to use "
594 "FMT_STRING.");
595#endif
596}
597template <typename..., typename S, FMT_ENABLE_IF(is_compile_string<S>::value)>
598void check_format_string(S);
599
601 constexpr error_handler() = default;
602 constexpr error_handler(const error_handler&) = default;
603
604 // This function is intentionally not constexpr to give a compile-time error.
605 FMT_NORETURN FMT_API void on_error(const char* message);
606};
608
609/** String's character type. */
610template <typename S> using char_t = typename detail::char_t_impl<S>::type;
611
612/**
613 \rst
614 Parsing context consisting of a format string range being parsed and an
615 argument counter for automatic indexing.
616 You can use the ``format_parse_context`` type alias for ``char`` instead.
617 \endrst
618 */
619template <typename Char, typename ErrorHandler = detail::error_handler>
620class basic_format_parse_context : private ErrorHandler {
621 private:
624
625 public:
626 using char_type = Char;
628
629 explicit constexpr basic_format_parse_context(
630 basic_string_view<Char> format_str, ErrorHandler eh = {},
631 int next_arg_id = 0)
632 : ErrorHandler(eh), format_str_(format_str), next_arg_id_(next_arg_id) {}
633
634 /**
635 Returns an iterator to the beginning of the format string range being
636 parsed.
637 */
638 constexpr auto begin() const FMT_NOEXCEPT -> iterator {
639 return format_str_.begin();
640 }
641
642 /**
643 Returns an iterator past the end of the format string range being parsed.
644 */
645 constexpr auto end() const FMT_NOEXCEPT -> iterator {
646 return format_str_.end();
647 }
648
649 /** Advances the begin iterator to ``it``. */
651 format_str_.remove_prefix(detail::to_unsigned(it - begin()));
652 }
653
654 /**
655 Reports an error if using the manual argument indexing; otherwise returns
656 the next argument index and switches to the automatic indexing.
657 */
659 // Don't check if the argument id is valid to avoid overhead and because it
660 // will be checked during formatting anyway.
661 if (next_arg_id_ >= 0) return next_arg_id_++;
662 on_error("cannot switch from manual to automatic argument indexing");
663 return 0;
664 }
665
666 /**
667 Reports an error if using the automatic argument indexing; otherwise
668 switches to the manual indexing.
669 */
671 if (next_arg_id_ > 0)
672 on_error("cannot switch from automatic to manual argument indexing");
673 else
674 next_arg_id_ = -1;
675 }
676
678
679 FMT_CONSTEXPR void on_error(const char* message) {
680 ErrorHandler::on_error(message);
681 }
682
683 constexpr auto error_handler() const -> ErrorHandler { return *this; }
684};
685
687
688template <typename Context> class basic_format_arg;
689template <typename Context> class basic_format_args;
690template <typename Context> class dynamic_format_arg_store;
691
692// A formatter for objects of type T.
693template <typename T, typename Char = char, typename Enable = void>
694struct formatter {
695 // A deleted default constructor indicates a disabled formatter.
696 formatter() = delete;
697};
698
699// Specifies if T has an enabled formatter specialization. A type can be
700// formattable even if it doesn't have a formatter e.g. via a conversion.
701template <typename T, typename Context>
704
705// Checks whether T is a container with contiguous storage.
706template <typename T> struct is_contiguous : std::false_type {};
707template <typename Char>
708struct is_contiguous<std::basic_string<Char>> : std::true_type {};
709
710class appender;
711
713
714// Extracts a reference to the container from back_insert_iterator.
715template <typename Container>
717 -> Container& {
718 using bi_iterator = std::back_insert_iterator<Container>;
719 struct accessor : bi_iterator {
720 accessor(bi_iterator iter) : bi_iterator(iter) {}
721 using bi_iterator::container;
722 };
723 return *accessor(it).container;
724}
725
726template <typename Char, typename InputIt, typename OutputIt>
727FMT_CONSTEXPR auto copy_str(InputIt begin, InputIt end, OutputIt out)
728 -> OutputIt {
729 while (begin != end) *out++ = static_cast<Char>(*begin++);
730 return out;
731}
732
733template <typename Char, FMT_ENABLE_IF(std::is_same<Char, char>::value)>
734FMT_CONSTEXPR auto copy_str(const Char* begin, const Char* end, Char* out)
735 -> Char* {
737 return copy_str<Char, const Char*, Char*>(begin, end, out);
738 auto size = to_unsigned(end - begin);
739 memcpy(out, begin, size);
740 return out + size;
741}
742
743/**
744 \rst
745 A contiguous memory buffer with an optional growing ability. It is an internal
746 class and shouldn't be used directly, only via `~fmt::basic_memory_buffer`.
747 \endrst
748 */
749template <typename T> class buffer {
750 private:
752 size_t size_;
753 size_t capacity_;
754
755 protected:
756 // Don't initialize ptr_ since it is not accessed to save a few cycles.
757 FMT_MSC_WARNING(suppress : 26495)
758 buffer(size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz) {}
759
760 buffer(T* p = nullptr, size_t sz = 0, size_t cap = 0) FMT_NOEXCEPT
761 : ptr_(p),
762 size_(sz),
763 capacity_(cap) {}
764
765 ~buffer() = default;
766 buffer(buffer&&) = default;
767
768 /** Sets the buffer data and capacity. */
769 void set(T* buf_data, size_t buf_capacity) FMT_NOEXCEPT {
770 ptr_ = buf_data;
771 capacity_ = buf_capacity;
772 }
773
774 /** Increases the buffer capacity to hold at least *capacity* elements. */
775 virtual void grow(size_t capacity) = 0;
776
777 public:
778 using value_type = T;
779 using const_reference = const T&;
780
781 buffer(const buffer&) = delete;
782 void operator=(const buffer&) = delete;
783
784 auto begin() FMT_NOEXCEPT -> T* { return ptr_; }
785 auto end() FMT_NOEXCEPT -> T* { return ptr_ + size_; }
786
787 auto begin() const FMT_NOEXCEPT -> const T* { return ptr_; }
788 auto end() const FMT_NOEXCEPT -> const T* { return ptr_ + size_; }
789
790 /** Returns the size of this buffer. */
791 auto size() const FMT_NOEXCEPT -> size_t { return size_; }
792
793 /** Returns the capacity of this buffer. */
794 auto capacity() const FMT_NOEXCEPT -> size_t { return capacity_; }
795
796 /** Returns a pointer to the buffer data. */
797 auto data() FMT_NOEXCEPT -> T* { return ptr_; }
798
799 /** Returns a pointer to the buffer data. */
800 auto data() const FMT_NOEXCEPT -> const T* { return ptr_; }
801
802 /** Clears this buffer. */
803 void clear() { size_ = 0; }
804
805 // Tries resizing the buffer to contain *count* elements. If T is a POD type
806 // the new elements may not be initialized.
807 void try_resize(size_t count) {
810 }
811
812 // Tries increasing the buffer capacity to *new_capacity*. It can increase the
813 // capacity by a smaller amount than requested but guarantees there is space
814 // for at least one additional element either by increasing the capacity or by
815 // flushing the buffer if it is full.
816 void try_reserve(size_t new_capacity) {
817 if (new_capacity > capacity_) grow(new_capacity);
818 }
819
820 void push_back(const T& value) {
821 try_reserve(size_ + 1);
822 ptr_[size_++] = value;
823 }
824
825 /** Appends data to the end of the buffer. */
826 template <typename U> void append(const U* begin, const U* end);
827
828 template <typename I> auto operator[](I index) -> T& { return ptr_[index]; }
829 template <typename I> auto operator[](I index) const -> const T& {
830 return ptr_[index];
831 }
832};
833
835 explicit buffer_traits(size_t) {}
836 auto count() const -> size_t { return 0; }
837 auto limit(size_t size) -> size_t { return size; }
838};
839
841 private:
842 size_t count_ = 0;
843 size_t limit_;
844
845 public:
846 explicit fixed_buffer_traits(size_t limit) : limit_(limit) {}
847 auto count() const -> size_t { return count_; }
848 auto limit(size_t size) -> size_t {
849 size_t n = limit_ > count_ ? limit_ - count_ : 0;
850 count_ += size;
851 return size < n ? size : n;
852 }
853};
854
855// A buffer that writes to an output iterator when flushed.
856template <typename OutputIt, typename T, typename Traits = buffer_traits>
857class iterator_buffer final : public Traits, public buffer<T> {
858 private:
859 OutputIt out_;
860 enum { buffer_size = 256 };
862
863 protected:
864 void grow(size_t) final FMT_OVERRIDE {
865 if (this->size() == buffer_size) flush();
866 }
867
868 void flush() {
869 auto size = this->size();
870 this->clear();
871 out_ = copy_str<T>(data_, data_ + this->limit(size), out_);
872 }
873
874 public:
875 explicit iterator_buffer(OutputIt out, size_t n = buffer_size)
876 : Traits(n), buffer<T>(data_, 0, buffer_size), out_(out) {}
878 : Traits(other), buffer<T>(data_, 0, buffer_size), out_(other.out_) {}
880
881 auto out() -> OutputIt {
882 flush();
883 return out_;
884 }
885 auto count() const -> size_t { return Traits::count() + this->size(); }
886};
887
888template <typename T> class iterator_buffer<T*, T> final : public buffer<T> {
889 protected:
890 void grow(size_t) final FMT_OVERRIDE {}
891
892 public:
893 explicit iterator_buffer(T* out, size_t = 0) : buffer<T>(out, 0, ~size_t()) {}
894
895 auto out() -> T* { return &*this->end(); }
896};
897
898// A buffer that writes to a container with the contiguous storage.
899template <typename Container>
900class iterator_buffer<std::back_insert_iterator<Container>,
901 enable_if_t<is_contiguous<Container>::value,
902 typename Container::value_type>>
903 final : public buffer<typename Container::value_type> {
904 private:
905 Container& container_;
906
907 protected:
908 void grow(size_t capacity) final FMT_OVERRIDE {
909 container_.resize(capacity);
910 this->set(&container_[0], capacity);
911 }
912
913 public:
914 explicit iterator_buffer(Container& c)
915 : buffer<typename Container::value_type>(c.size()), container_(c) {}
919 return std::back_inserter(container_);
920 }
921};
922
923// A buffer that counts the number of code units written discarding the output.
924template <typename T = char> class counting_buffer final : public buffer<T> {
925 private:
926 enum { buffer_size = 256 };
928 size_t count_ = 0;
929
930 protected:
931 void grow(size_t) final FMT_OVERRIDE {
932 if (this->size() != buffer_size) return;
933 count_ += this->size();
934 this->clear();
935 }
936
937 public:
939
940 auto count() -> size_t { return count_ + this->size(); }
941};
942
943template <typename T>
946
947// Maps an output iterator to a buffer.
948template <typename T, typename OutputIt>
951}
952
953template <typename Buffer>
954auto get_iterator(Buffer& buf) -> decltype(buf.out()) {
955 return buf.out();
956}
957template <typename T> auto get_iterator(buffer<T>& buf) -> buffer_appender<T> {
958 return buffer_appender<T>(buf);
959}
960
961template <typename T, typename Char = char, typename Enable = void>
965
966// Specifies if T has an enabled fallback_formatter specialization.
967template <typename T, typename Char>
970
971struct view {};
972
973template <typename Char, typename T> struct named_arg : view {
974 const Char* name;
975 const T& value;
976 named_arg(const Char* n, const T& v) : name(n), value(v) {}
977};
978
979template <typename Char> struct named_arg_info {
980 const Char* name;
981 int id;
982};
983
984template <typename T, typename Char, size_t NUM_ARGS, size_t NUM_NAMED_ARGS>
985struct arg_data {
986 // args_[0].named_args points to named_args_ to avoid bloating format_args.
987 // +1 to workaround a bug in gcc 7.5 that causes duplicated-branches warning.
988 T args_[1 + (NUM_ARGS != 0 ? NUM_ARGS : +1)];
990
991 template <typename... U>
992 arg_data(const U&... init) : args_{T(named_args_, NUM_NAMED_ARGS), init...} {}
993 arg_data(const arg_data& other) = delete;
994 auto args() const -> const T* { return args_ + 1; }
996};
997
998template <typename T, typename Char, size_t NUM_ARGS>
999struct arg_data<T, Char, NUM_ARGS, 0> {
1000 // +1 to workaround a bug in gcc 7.5 that causes duplicated-branches warning.
1001 T args_[NUM_ARGS != 0 ? NUM_ARGS : +1];
1002
1003 template <typename... U>
1004 FMT_CONSTEXPR FMT_INLINE arg_data(const U&... init) : args_{init...} {}
1005 FMT_CONSTEXPR FMT_INLINE auto args() const -> const T* { return args_; }
1007 return nullptr;
1008 }
1009};
1010
1011template <typename Char>
1012inline void init_named_args(named_arg_info<Char>*, int, int) {}
1013
1014template <typename T> struct is_named_arg : std::false_type {};
1015template <typename T> struct is_statically_named_arg : std::false_type {};
1016
1017template <typename T, typename Char>
1019
1020template <typename Char, typename T, typename... Tail,
1022void init_named_args(named_arg_info<Char>* named_args, int arg_count,
1023 int named_arg_count, const T&, const Tail&... args) {
1024 init_named_args(named_args, arg_count + 1, named_arg_count, args...);
1025}
1026
1027template <typename Char, typename T, typename... Tail,
1029void init_named_args(named_arg_info<Char>* named_args, int arg_count,
1030 int named_arg_count, const T& arg, const Tail&... args) {
1031 named_args[named_arg_count++] = {arg.name, arg_count};
1032 init_named_args(named_args, arg_count + 1, named_arg_count, args...);
1033}
1034
1035template <typename... Args>
1037 const Args&...) {}
1038
1039template <bool B = false> constexpr auto count() -> size_t { return B ? 1 : 0; }
1040template <bool B1, bool B2, bool... Tail> constexpr auto count() -> size_t {
1041 return (B1 ? 1 : 0) + count<B2, Tail...>();
1042}
1043
1044template <typename... Args> constexpr auto count_named_args() -> size_t {
1045 return count<is_named_arg<Args>::value...>();
1046}
1047
1048enum class type {
1049 none_type,
1050 // Integer types should go first,
1051 int_type,
1052 uint_type,
1057 bool_type,
1058 char_type,
1060 // followed by floating-point types.
1061 float_type,
1069};
1070
1071// Maps core type T to the corresponding type enum constant.
1072template <typename T, typename Char>
1073struct type_constant : std::integral_constant<type, type::custom_type> {};
1074
1075#define FMT_TYPE_CONSTANT(Type, constant) \
1076 template <typename Char> \
1077 struct type_constant<Type, Char> \
1078 : std::integral_constant<type, type::constant> {}
1079
1094
1095constexpr bool is_integral_type(type t) {
1096 return t > type::none_type && t <= type::last_integer_type;
1097}
1098
1099constexpr bool is_arithmetic_type(type t) {
1100 return t > type::none_type && t <= type::last_numeric_type;
1101}
1102
1103template <typename Char> struct string_value {
1104 const Char* data;
1105 size_t size;
1106};
1107
1108template <typename Char> struct named_arg_value {
1110 size_t size;
1111};
1112
1113template <typename Context> struct custom_value {
1114 using parse_context = typename Context::parse_context_type;
1115 const void* value;
1116 void (*format)(const void* arg, parse_context& parse_ctx, Context& ctx);
1117};
1118
1119// A formatting argument value.
1120template <typename Context> class value {
1121 public:
1122 using char_type = typename Context::char_type;
1123
1124 union {
1127 unsigned uint_value;
1129 unsigned long long ulong_long_value;
1137 const void* pointer;
1141 };
1142
1143 constexpr FMT_INLINE value() : no_value() {}
1144 constexpr FMT_INLINE value(int val) : int_value(val) {}
1145 constexpr FMT_INLINE value(unsigned val) : uint_value(val) {}
1146 constexpr FMT_INLINE value(long long val) : long_long_value(val) {}
1147 constexpr FMT_INLINE value(unsigned long long val) : ulong_long_value(val) {}
1150 FMT_INLINE value(float val) : float_value(val) {}
1151 FMT_INLINE value(double val) : double_value(val) {}
1152 FMT_INLINE value(long double val) : long_double_value(val) {}
1153 constexpr FMT_INLINE value(bool val) : bool_value(val) {}
1154 constexpr FMT_INLINE value(char_type val) : char_value(val) {}
1156 string.data = val;
1157 if (is_constant_evaluated()) string.size = {};
1158 }
1160 string.data = val.data();
1161 string.size = val.size();
1162 }
1163 FMT_INLINE value(const void* val) : pointer(val) {}
1165 : named_args{args, size} {}
1166
1167 template <typename T> FMT_CONSTEXPR FMT_INLINE value(const T& val) {
1168 custom.value = &val;
1169 // Get the formatter type through the context to allow different contexts
1170 // have different extension points, e.g. `formatter<T>` for `format` and
1171 // `printf_formatter<T>` for `printf`.
1172 custom.format = format_custom_arg<
1174 typename Context::template formatter_type<T>,
1176 }
1177
1178 private:
1179 // Formats an argument of a custom type, such as a user-defined class.
1180 template <typename T, typename Formatter>
1181 static void format_custom_arg(const void* arg,
1182 typename Context::parse_context_type& parse_ctx,
1183 Context& ctx) {
1184 Formatter f;
1185 parse_ctx.advance_to(f.parse(parse_ctx));
1186 ctx.advance_to(f.format(*static_cast<const T*>(arg), ctx));
1187 }
1188};
1189
1190template <typename Context, typename T>
1192
1193// To minimize the number of types we need to deal with, long is translated
1194// either to int or to long long depending on its size.
1195enum { long_short = sizeof(long) == sizeof(int) };
1198
1200
1201// Maps formatting arguments to core types.
1202template <typename Context> struct arg_mapper {
1203 using char_type = typename Context::char_type;
1204
1205 FMT_CONSTEXPR FMT_INLINE auto map(signed char val) -> int { return val; }
1206 FMT_CONSTEXPR FMT_INLINE auto map(unsigned char val) -> unsigned {
1207 return val;
1208 }
1209 FMT_CONSTEXPR FMT_INLINE auto map(short val) -> int { return val; }
1210 FMT_CONSTEXPR FMT_INLINE auto map(unsigned short val) -> unsigned {
1211 return val;
1212 }
1213 FMT_CONSTEXPR FMT_INLINE auto map(int val) -> int { return val; }
1214 FMT_CONSTEXPR FMT_INLINE auto map(unsigned val) -> unsigned { return val; }
1215 FMT_CONSTEXPR FMT_INLINE auto map(long val) -> long_type { return val; }
1216 FMT_CONSTEXPR FMT_INLINE auto map(unsigned long val) -> ulong_type {
1217 return val;
1218 }
1219 FMT_CONSTEXPR FMT_INLINE auto map(long long val) -> long long { return val; }
1220 FMT_CONSTEXPR FMT_INLINE auto map(unsigned long long val)
1221 -> unsigned long long {
1222 return val;
1223 }
1224 FMT_CONSTEXPR FMT_INLINE auto map(int128_t val) -> int128_t { return val; }
1225 FMT_CONSTEXPR FMT_INLINE auto map(uint128_t val) -> uint128_t { return val; }
1226 FMT_CONSTEXPR FMT_INLINE auto map(bool val) -> bool { return val; }
1227
1228 template <typename T, FMT_ENABLE_IF(is_char<T>::value)>
1230 static_assert(
1232 "mixing character types is disallowed");
1233 return val;
1234 }
1235
1236 FMT_CONSTEXPR FMT_INLINE auto map(float val) -> float { return val; }
1237 FMT_CONSTEXPR FMT_INLINE auto map(double val) -> double { return val; }
1238 FMT_CONSTEXPR FMT_INLINE auto map(long double val) -> long double {
1239 return val;
1240 }
1241
1243 return val;
1244 }
1245 FMT_CONSTEXPR FMT_INLINE auto map(const char_type* val) -> const char_type* {
1246 return val;
1247 }
1248 template <typename T, FMT_ENABLE_IF(is_string<T>::value)>
1252 "mixing character types is disallowed");
1253 return to_string_view(val);
1254 }
1255 template <typename T,
1262 return basic_string_view<char_type>(val);
1263 }
1264 template <
1265 typename T,
1273 return std_string_view<char_type>(val);
1274 }
1275 FMT_CONSTEXPR FMT_INLINE auto map(const signed char* val) -> const char* {
1276 static_assert(std::is_same<char_type, char>::value, "invalid string type");
1277 return reinterpret_cast<const char*>(val);
1278 }
1279 FMT_CONSTEXPR FMT_INLINE auto map(const unsigned char* val) -> const char* {
1280 static_assert(std::is_same<char_type, char>::value, "invalid string type");
1281 return reinterpret_cast<const char*>(val);
1282 }
1283 FMT_CONSTEXPR FMT_INLINE auto map(signed char* val) -> const char* {
1284 const auto* const_val = val;
1285 return map(const_val);
1286 }
1287 FMT_CONSTEXPR FMT_INLINE auto map(unsigned char* val) -> const char* {
1288 const auto* const_val = val;
1289 return map(const_val);
1290 }
1291
1292 FMT_CONSTEXPR FMT_INLINE auto map(void* val) -> const void* { return val; }
1293 FMT_CONSTEXPR FMT_INLINE auto map(const void* val) -> const void* {
1294 return val;
1295 }
1296 FMT_CONSTEXPR FMT_INLINE auto map(std::nullptr_t val) -> const void* {
1297 return val;
1298 }
1299
1300 // We use SFINAE instead of a const T* parameter to avoid conflicting with
1301 // the C array overload.
1302 template <typename T>
1303 FMT_CONSTEXPR auto map(T) -> enable_if_t<std::is_pointer<T>::value, int> {
1304 // Formatting of arbitrary pointers is disallowed. If you want to output
1305 // a pointer cast it to "void *" or "const void *". In particular, this
1306 // forbids formatting of "[const] volatile char *" which is printed as bool
1307 // by iostreams.
1308 static_assert(!sizeof(T), "formatting of non-void pointers is disallowed");
1309 return 0;
1310 }
1311
1312 template <typename T, std::size_t N>
1313 FMT_CONSTEXPR FMT_INLINE auto map(const T (&values)[N]) -> const T (&)[N] {
1314 return values;
1315 }
1316
1317 template <typename T,
1322 -> decltype(std::declval<arg_mapper>().map(
1323 static_cast<typename std::underlying_type<T>::type>(val))) {
1324 return map(static_cast<typename std::underlying_type<T>::type>(val));
1325 }
1326 template <typename T,
1330 FMT_CONSTEXPR FMT_INLINE auto map(const T& val) -> const T& {
1331 return val;
1332 }
1333
1334 template <typename T, FMT_ENABLE_IF(is_named_arg<T>::value)>
1336 -> decltype(std::declval<arg_mapper>().map(named_arg.value)) {
1337 return map(named_arg.value);
1338 }
1339
1340 auto map(...) -> unformattable { return {}; }
1341};
1342
1343// A type constant after applying arg_mapper<Context>.
1344template <typename T, typename Context>
1347 typename Context::char_type>;
1348
1349enum { packed_arg_bits = 4 };
1350// Maximum number of arguments with packed types.
1352enum : unsigned long long { is_unpacked_bit = 1ULL << 63 };
1353enum : unsigned long long { has_named_args_bit = 1ULL << 62 };
1354
1356
1357// An output iterator that appends to a buffer.
1358// It is used to reduce symbol sizes for the common case.
1359class appender : public std::back_insert_iterator<detail::buffer<char>> {
1361
1362 template <typename T>
1363 friend auto get_buffer(appender out) -> detail::buffer<char>& {
1364 return detail::get_container(out);
1365 }
1366
1367 public:
1368 using std::back_insert_iterator<detail::buffer<char>>::back_insert_iterator;
1369 appender(base it) : base(it) {}
1370 using _Unchecked_type = appender; // Mark iterator as checked.
1371
1374 return *this;
1375 }
1376
1377 auto operator++(int) -> appender {
1378 auto tmp = *this;
1379 ++*this;
1380 return tmp;
1381 }
1382};
1383
1384// A formatting argument. It is a trivially copyable/constructible type to
1385// allow storage in basic_memory_buffer.
1386template <typename Context> class basic_format_arg {
1387 private:
1388 detail::value<Context> value_;
1389 detail::type type_;
1390
1391 template <typename ContextType, typename T>
1394
1395 template <typename Visitor, typename Ctx>
1396 friend FMT_CONSTEXPR auto visit_format_arg(Visitor&& vis,
1398 -> decltype(vis(0));
1399
1400 friend class basic_format_args<Context>;
1401 friend class dynamic_format_arg_store<Context>;
1402
1403 using char_type = typename Context::char_type;
1404
1405 template <typename T, typename Char, size_t NUM_ARGS, size_t NUM_NAMED_ARGS>
1406 friend struct detail::arg_data;
1407
1408 basic_format_arg(const detail::named_arg_info<char_type>* args, size_t size)
1409 : value_(args, size) {}
1410
1411 public:
1412 class handle {
1413 public:
1414 explicit handle(detail::custom_value<Context> custom) : custom_(custom) {}
1415
1416 void format(typename Context::parse_context_type& parse_ctx,
1417 Context& ctx) const {
1418 custom_.format(custom_.value, parse_ctx, ctx);
1419 }
1420
1421 private:
1422 detail::custom_value<Context> custom_;
1423 };
1424
1426
1427 constexpr explicit operator bool() const FMT_NOEXCEPT {
1428 return type_ != detail::type::none_type;
1429 }
1430
1431 auto type() const -> detail::type { return type_; }
1432
1433 auto is_integral() const -> bool { return detail::is_integral_type(type_); }
1434 auto is_arithmetic() const -> bool {
1435 return detail::is_arithmetic_type(type_);
1436 }
1437};
1438
1439/**
1440 \rst
1441 Visits an argument dispatching to the appropriate visit method based on
1442 the argument type. For example, if the argument type is ``double`` then
1443 ``vis(value)`` will be called with the value of type ``double``.
1444 \endrst
1445 */
1446template <typename Visitor, typename Context>
1448 Visitor&& vis, const basic_format_arg<Context>& arg) -> decltype(vis(0)) {
1449 switch (arg.type_) {
1450 case detail::type::none_type:
1451 break;
1452 case detail::type::int_type:
1453 return vis(arg.value_.int_value);
1454 case detail::type::uint_type:
1455 return vis(arg.value_.uint_value);
1456 case detail::type::long_long_type:
1457 return vis(arg.value_.long_long_value);
1458 case detail::type::ulong_long_type:
1459 return vis(arg.value_.ulong_long_value);
1460 case detail::type::int128_type:
1461 return vis(detail::convert_for_visit(arg.value_.int128_value));
1462 case detail::type::uint128_type:
1463 return vis(detail::convert_for_visit(arg.value_.uint128_value));
1464 case detail::type::bool_type:
1465 return vis(arg.value_.bool_value);
1466 case detail::type::char_type:
1467 return vis(arg.value_.char_value);
1468 case detail::type::float_type:
1469 return vis(arg.value_.float_value);
1470 case detail::type::double_type:
1471 return vis(arg.value_.double_value);
1472 case detail::type::long_double_type:
1473 return vis(arg.value_.long_double_value);
1474 case detail::type::cstring_type:
1475 return vis(arg.value_.string.data);
1476 case detail::type::string_type:
1478 return vis(sv(arg.value_.string.data, arg.value_.string.size));
1479 case detail::type::pointer_type:
1480 return vis(arg.value_.pointer);
1481 case detail::type::custom_type:
1482 return vis(typename basic_format_arg<Context>::handle(arg.value_.custom));
1483 }
1484 return vis(monostate());
1485}
1486
1488
1489template <typename Char, typename InputIt>
1490auto copy_str(InputIt begin, InputIt end, appender out) -> appender {
1491 get_container(out).append(begin, end);
1492 return out;
1493}
1494
1495#if FMT_GCC_VERSION && FMT_GCC_VERSION < 500
1496// A workaround for gcc 4.8 to make void_t work in a SFINAE context.
1497template <typename... Ts> struct void_t_impl { using type = void; };
1498template <typename... Ts>
1499using void_t = typename detail::void_t_impl<Ts...>::type;
1500#else
1501template <typename...> using void_t = void;
1502#endif
1503
1504template <typename It, typename T, typename Enable = void>
1506
1507template <typename It, typename T>
1513
1514template <typename OutputIt>
1516template <typename Container>
1519
1520template <typename OutputIt>
1522template <typename Container>
1523struct is_contiguous_back_insert_iterator<std::back_insert_iterator<Container>>
1524 : is_contiguous<Container> {};
1525template <>
1527
1528// A type-erased reference to an std::locale to avoid heavy <locale> include.
1530 private:
1531 const void* locale_; // A type-erased pointer to std::locale.
1532
1533 public:
1534 constexpr locale_ref() : locale_(nullptr) {}
1535 template <typename Locale> explicit locale_ref(const Locale& loc);
1536
1537 explicit operator bool() const FMT_NOEXCEPT { return locale_ != nullptr; }
1538
1539 template <typename Locale> auto get() const -> Locale;
1540};
1541
1542template <typename> constexpr auto encode_types() -> unsigned long long {
1543 return 0;
1544}
1545
1546template <typename Context, typename Arg, typename... Args>
1547constexpr auto encode_types() -> unsigned long long {
1548 return static_cast<unsigned>(mapped_type_constant<Arg, Context>::value) |
1549 (encode_types<Context, Args...>() << packed_arg_bits);
1550}
1551
1552template <typename Context, typename T>
1559
1560// The type template parameter is there to avoid an ODR violation when using
1561// a fallback formatter in one translation unit and an implicit conversion in
1562// another (not recommended).
1563template <bool IS_PACKED, typename Context, type, typename T,
1564 FMT_ENABLE_IF(IS_PACKED)>
1566 const auto& arg = arg_mapper<Context>().map(val);
1567 static_assert(
1568 !std::is_same<decltype(arg), const unformattable&>::value,
1569 "Cannot format an argument. To make type T formattable provide a "
1570 "formatter<T> specialization: https://fmt.dev/latest/api.html#udt");
1571 return {arg};
1572}
1573
1574template <bool IS_PACKED, typename Context, type, typename T,
1575 FMT_ENABLE_IF(!IS_PACKED)>
1577 return make_arg<Context>(value);
1578}
1580
1581// Formatting context.
1582template <typename OutputIt, typename Char> class basic_format_context {
1583 public:
1584 /** The character type for the output. */
1585 using char_type = Char;
1586
1587 private:
1588 OutputIt out_;
1590 detail::locale_ref loc_;
1591
1592 public:
1593 using iterator = OutputIt;
1596 template <typename T> using formatter_type = formatter<T, char_type>;
1597
1600 void operator=(const basic_format_context&) = delete;
1601 /**
1602 Constructs a ``basic_format_context`` object. References to the arguments are
1603 stored in the object so make sure they have appropriate lifetimes.
1604 */
1606 OutputIt out, basic_format_args<basic_format_context> ctx_args,
1607 detail::locale_ref loc = detail::locale_ref())
1608 : out_(out), args_(ctx_args), loc_(loc) {}
1609
1610 constexpr auto arg(int id) const -> format_arg { return args_.get(id); }
1615 return args_.get_id(name);
1616 }
1618 return args_;
1619 }
1620
1621 FMT_CONSTEXPR auto error_handler() -> detail::error_handler { return {}; }
1622 void on_error(const char* message) { error_handler().on_error(message); }
1623
1624 // Returns an iterator to the beginning of the output range.
1625 FMT_CONSTEXPR auto out() -> iterator { return out_; }
1626
1627 // Advances the begin iterator to ``it``.
1629 if (!detail::is_back_insert_iterator<iterator>()) out_ = it;
1630 }
1631
1632 FMT_CONSTEXPR auto locale() -> detail::locale_ref { return loc_; }
1633};
1634
1635template <typename Char>
1639
1640// Workaround an alias issue: https://stackoverflow.com/q/62767544/471164.
1641#define FMT_BUFFER_CONTEXT(Char) \
1642 basic_format_context<detail::buffer_appender<Char>, Char>
1643
1644template <typename T, typename Char = char>
1646 !std::is_same<decltype(detail::arg_mapper<buffer_context<Char>>().map(
1647 std::declval<T>())),
1648 detail::unformattable>::value &&
1649 !detail::has_fallback_formatter<T, Char>::value>;
1650
1651/**
1652 \rst
1653 An array of references to arguments. It can be implicitly converted into
1654 `~fmt::basic_format_args` for passing into type-erased formatting functions
1655 such as `~fmt::vformat`.
1656 \endrst
1657 */
1658template <typename Context, typename... Args>
1661 // Workaround a GCC template argument substitution bug.
1663#endif
1664{
1665 private:
1666 static const size_t num_args = sizeof...(Args);
1667 static const size_t num_named_args = detail::count_named_args<Args...>();
1668 static const bool is_packed = num_args <= detail::max_packed_args;
1669
1672
1673 detail::arg_data<value_type, typename Context::char_type, num_args,
1674 num_named_args>
1675 data_;
1676
1677 friend class basic_format_args<Context>;
1678
1679 static constexpr unsigned long long desc =
1680 (is_packed ? detail::encode_types<Context, Args...>()
1681 : detail::is_unpacked_bit | num_args) |
1682 (num_named_args != 0
1683 ? static_cast<unsigned long long>(detail::has_named_args_bit)
1684 : 0);
1685
1686 public:
1688 :
1690 basic_format_args<Context>(*this),
1691#endif
1692 data_{detail::make_arg<
1693 is_packed, Context,
1694 detail::mapped_type_constant<Args, Context>::value>(args)...} {
1695 detail::init_named_args(data_.named_args(), 0, 0, args...);
1696 }
1697};
1698
1699/**
1700 \rst
1701 Constructs a `~fmt::format_arg_store` object that contains references to
1702 arguments and can be implicitly converted to `~fmt::format_args`. `Context`
1703 can be omitted in which case it defaults to `~fmt::context`.
1704 See `~fmt::arg` for lifetime considerations.
1705 \endrst
1706 */
1707template <typename Context = format_context, typename... Args>
1708constexpr auto make_format_args(const Args&... args)
1709 -> format_arg_store<Context, Args...> {
1710 return {args...};
1711}
1712
1713/**
1714 \rst
1715 Returns a named argument to be used in a formatting function.
1716 It should only be used in a call to a formatting function or
1717 `dynamic_format_arg_store::push_back`.
1718
1719 **Example**::
1720
1721 fmt::print("Elapsed time: {s:.2f} seconds", fmt::arg("s", 1.23));
1722 \endrst
1723 */
1724template <typename Char, typename T>
1725inline auto arg(const Char* name, const T& arg) -> detail::named_arg<Char, T> {
1726 static_assert(!detail::is_named_arg<T>(), "nested named arguments");
1727 return {name, arg};
1728}
1729
1730/**
1731 \rst
1732 A view of a collection of formatting arguments. To avoid lifetime issues it
1733 should only be used as a parameter type in type-erased functions such as
1734 ``vformat``::
1735
1736 void vlog(string_view format_str, format_args args); // OK
1737 format_args args = make_format_args(42); // Error: dangling reference
1738 \endrst
1739 */
1740template <typename Context> class basic_format_args {
1741 public:
1744
1745 private:
1746 // A descriptor that contains information about formatting arguments.
1747 // If the number of arguments is less or equal to max_packed_args then
1748 // argument types are passed in the descriptor. This reduces binary code size
1749 // per formatting function call.
1750 unsigned long long desc_;
1751 union {
1752 // If is_packed() returns true then argument values are stored in values_;
1753 // otherwise they are stored in args_. This is done to improve cache
1754 // locality and reduce compiled code size since storing larger objects
1755 // may require more code (at least on x86-64) even if the same amount of
1756 // data is actually copied to stack. It saves ~10% on the bloat test.
1757 const detail::value<Context>* values_;
1759 };
1760
1761 constexpr auto is_packed() const -> bool {
1762 return (desc_ & detail::is_unpacked_bit) == 0;
1763 }
1764 auto has_named_args() const -> bool {
1765 return (desc_ & detail::has_named_args_bit) != 0;
1766 }
1767
1768 FMT_CONSTEXPR auto type(int index) const -> detail::type {
1769 int shift = index * detail::packed_arg_bits;
1770 unsigned int mask = (1 << detail::packed_arg_bits) - 1;
1771 return static_cast<detail::type>((desc_ >> shift) & mask);
1772 }
1773
1774 constexpr FMT_INLINE basic_format_args(unsigned long long desc,
1775 const detail::value<Context>* values)
1776 : desc_(desc), values_(values) {}
1777 constexpr basic_format_args(unsigned long long desc, const format_arg* args)
1778 : desc_(desc), args_(args) {}
1779
1780 public:
1781 constexpr basic_format_args() : desc_(0), args_(nullptr) {}
1782
1783 /**
1784 \rst
1785 Constructs a `basic_format_args` object from `~fmt::format_arg_store`.
1786 \endrst
1787 */
1788 template <typename... Args>
1791 : basic_format_args(format_arg_store<Context, Args...>::desc,
1792 store.data_.args()) {}
1793
1794 /**
1795 \rst
1796 Constructs a `basic_format_args` object from
1797 `~fmt::dynamic_format_arg_store`.
1798 \endrst
1799 */
1802 : basic_format_args(store.get_types(), store.data()) {}
1803
1804 /**
1805 \rst
1806 Constructs a `basic_format_args` object from a dynamic set of arguments.
1807 \endrst
1808 */
1809 constexpr basic_format_args(const format_arg* args, int count)
1811 args) {}
1812
1813 /** Returns the argument with the specified id. */
1814 FMT_CONSTEXPR auto get(int id) const -> format_arg {
1816 if (!is_packed()) {
1817 if (id < max_size()) arg = args_[id];
1818 return arg;
1819 }
1820 if (id >= detail::max_packed_args) return arg;
1821 arg.type_ = type(id);
1822 if (arg.type_ == detail::type::none_type) return arg;
1823 arg.value_ = values_[id];
1824 return arg;
1825 }
1826
1827 template <typename Char>
1829 int id = get_id(name);
1830 return id >= 0 ? get(id) : format_arg();
1831 }
1832
1833 template <typename Char>
1835 if (!has_named_args()) return -1;
1836 const auto& named_args =
1837 (is_packed() ? values_[-1] : args_[-1].value_).named_args;
1838 for (size_t i = 0; i < named_args.size; ++i) {
1839 if (named_args.data[i].name == name) return named_args.data[i].id;
1840 }
1841 return -1;
1842 }
1843
1844 auto max_size() const -> int {
1845 unsigned long long max_packed = detail::max_packed_args;
1846 return static_cast<int>(is_packed() ? max_packed
1847 : desc_ & ~detail::is_unpacked_bit);
1848 }
1849};
1850
1851/** An alias to ``basic_format_args<format_context>``. */
1852// A separate type would result in shorter symbols but break ABI compatibility
1853// between clang and gcc on ARM (#1919).
1855
1856// We cannot use enum classes as bit fields because of a gcc bug
1857// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61414.
1858namespace align {
1860}
1862namespace sign {
1864}
1866
1868
1869void throw_format_error(const char* message);
1870
1871// Workaround an array initialization issue in gcc 4.8.
1872template <typename Char> struct fill_t {
1873 private:
1874 enum { max_size = 4 };
1875 Char data_[max_size] = {Char(' '), Char(0), Char(0), Char(0)};
1876 unsigned char size_ = 1;
1877
1878 public:
1880 auto size = s.size();
1881 if (size > max_size) return throw_format_error("invalid fill");
1882 for (size_t i = 0; i < size; ++i) data_[i] = s[i];
1883 size_ = static_cast<unsigned char>(size);
1884 }
1885
1886 constexpr auto size() const -> size_t { return size_; }
1887 constexpr auto data() const -> const Char* { return data_; }
1888
1889 FMT_CONSTEXPR auto operator[](size_t index) -> Char& { return data_[index]; }
1890 FMT_CONSTEXPR auto operator[](size_t index) const -> const Char& {
1891 return data_[index];
1892 }
1893};
1895
1896// Format specifiers for built-in and string types.
1897template <typename Char> struct basic_format_specs {
1900 char type;
1903 bool alt : 1; // Alternate form ('#').
1904 bool localized : 1;
1905 detail::fill_t<Char> fill;
1906
1908 : width(0),
1909 precision(-1),
1910 type(0),
1911 align(align::none),
1912 sign(sign::none),
1913 alt(false),
1914 localized(false) {}
1915};
1916
1918
1920
1921enum class arg_id_kind { none, index, name };
1922
1923// An argument reference.
1924template <typename Char> struct arg_ref {
1926
1928 : kind(arg_id_kind::index), val(index) {}
1931
1932 FMT_CONSTEXPR auto operator=(int idx) -> arg_ref& {
1933 kind = arg_id_kind::index;
1934 val.index = idx;
1935 return *this;
1936 }
1937
1946};
1947
1948// Format specifiers with width and precision resolved at formatting rather
1949// than parsing time to allow re-using the same parsed specifiers with
1950// different sets of arguments (precompilation of format strings).
1951template <typename Char>
1956
1957struct auto_id {};
1958
1959// A format specifier handler that sets fields in basic_format_specs.
1960template <typename Char> class specs_setter {
1961 protected:
1963
1964 public:
1966 : specs_(specs) {}
1967
1969 : specs_(other.specs_) {}
1970
1975 FMT_CONSTEXPR void on_sign(sign_t s) { specs_.sign = s; }
1976 FMT_CONSTEXPR void on_hash() { specs_.alt = true; }
1977 FMT_CONSTEXPR void on_localized() { specs_.localized = true; }
1978
1980 if (specs_.align == align::none) specs_.align = align::numeric;
1981 specs_.fill[0] = Char('0');
1982 }
1983
1984 FMT_CONSTEXPR void on_width(int width) { specs_.width = width; }
1985 FMT_CONSTEXPR void on_precision(int precision) {
1986 specs_.precision = precision;
1987 }
1989
1991 specs_.type = static_cast<char>(type);
1992 }
1993};
1994
1995// Format spec handler that saves references to arguments representing dynamic
1996// width and precision to be resolved at formatting time.
1997template <typename ParseContext>
1999 : public specs_setter<typename ParseContext::char_type> {
2000 public:
2001 using char_type = typename ParseContext::char_type;
2002
2004 ParseContext& ctx)
2005 : specs_setter<char_type>(specs), specs_(specs), context_(ctx) {}
2006
2008 : specs_setter<char_type>(other),
2009 specs_(other.specs_),
2010 context_(other.context_) {}
2011
2012 template <typename Id> FMT_CONSTEXPR void on_dynamic_width(Id arg_id) {
2013 specs_.width_ref = make_arg_ref(arg_id);
2014 }
2015
2016 template <typename Id> FMT_CONSTEXPR void on_dynamic_precision(Id arg_id) {
2017 specs_.precision_ref = make_arg_ref(arg_id);
2018 }
2019
2020 FMT_CONSTEXPR void on_error(const char* message) {
2021 context_.on_error(message);
2022 }
2023
2024 private:
2026 ParseContext& context_;
2027
2029
2031 context_.check_arg_id(arg_id);
2032 return arg_ref_type(arg_id);
2033 }
2034
2036 return arg_ref_type(context_.next_arg_id());
2037 }
2038
2040 -> arg_ref_type {
2041 context_.check_arg_id(arg_id);
2043 context_.begin(), to_unsigned(context_.end() - context_.begin()));
2044 return arg_ref_type(arg_id);
2045 }
2046};
2047
2048template <typename Char> constexpr bool is_ascii_letter(Char c) {
2049 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
2050}
2051
2052// Converts a character to ASCII. Returns a number > 127 on conversion failure.
2053template <typename Char, FMT_ENABLE_IF(std::is_integral<Char>::value)>
2054constexpr auto to_ascii(Char value) -> Char {
2055 return value;
2056}
2057template <typename Char, FMT_ENABLE_IF(std::is_enum<Char>::value)>
2058constexpr auto to_ascii(Char value) ->
2060 return value;
2061}
2062
2063template <typename Char>
2064FMT_CONSTEXPR auto code_point_length(const Char* begin) -> int {
2065 if (const_check(sizeof(Char) != 1)) return 1;
2066 constexpr char lengths[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2067 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 4, 0};
2068 int len = lengths[static_cast<unsigned char>(*begin) >> 3];
2069
2070 // Compute the pointer to the next character early so that the next
2071 // iteration can start working on the next character. Neither Clang
2072 // nor GCC figure out this reordering on their own.
2073 return len + !len;
2074}
2075
2076// Return the result via the out param to workaround gcc bug 77539.
2077template <bool IS_CONSTEXPR, typename T, typename Ptr = const T*>
2078FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr& out) -> bool {
2079 for (out = first; out != last; ++out) {
2080 if (*out == value) return true;
2081 }
2082 return false;
2083}
2084
2085template <>
2086inline auto find<false, char>(const char* first, const char* last, char value,
2087 const char*& out) -> bool {
2088 out = static_cast<const char*>(
2089 std::memchr(first, value, to_unsigned(last - first)));
2090 return out != nullptr;
2091}
2092
2093// Parses the range [begin, end) as an unsigned integer. This function assumes
2094// that the range is non-empty and the first character is a digit.
2095template <typename Char>
2096FMT_CONSTEXPR auto parse_nonnegative_int(const Char*& begin, const Char* end,
2097 int error_value) noexcept -> int {
2098 FMT_ASSERT(begin != end && '0' <= *begin && *begin <= '9', "");
2099 unsigned value = 0, prev = 0;
2100 auto p = begin;
2101 do {
2102 prev = value;
2103 value = value * 10 + unsigned(*p - '0');
2104 ++p;
2105 } while (p != end && '0' <= *p && *p <= '9');
2106 auto num_digits = p - begin;
2107 begin = p;
2108 if (num_digits <= std::numeric_limits<int>::digits10)
2109 return static_cast<int>(value);
2110 // Check for overflow.
2111 const unsigned max = to_unsigned((std::numeric_limits<int>::max)());
2112 return num_digits == std::numeric_limits<int>::digits10 + 1 &&
2113 prev * 10ull + unsigned(p[-1] - '0') <= max
2114 ? static_cast<int>(value)
2115 : error_value;
2116}
2117
2118// Parses fill and alignment.
2119template <typename Char, typename Handler>
2120FMT_CONSTEXPR auto parse_align(const Char* begin, const Char* end,
2121 Handler&& handler) -> const Char* {
2122 FMT_ASSERT(begin != end, "");
2123 auto align = align::none;
2124 auto p = begin + code_point_length(begin);
2125 if (p >= end) p = begin;
2126 for (;;) {
2127 switch (to_ascii(*p)) {
2128 case '<':
2130 break;
2131 case '>':
2133 break;
2134 case '^':
2136 break;
2137 default:
2138 break;
2139 }
2140 if (align != align::none) {
2141 if (p != begin) {
2142 auto c = *begin;
2143 if (c == '{')
2144 return handler.on_error("invalid fill character '{'"), begin;
2145 handler.on_fill(basic_string_view<Char>(begin, to_unsigned(p - begin)));
2146 begin = p + 1;
2147 } else
2148 ++begin;
2149 handler.on_align(align);
2150 break;
2151 } else if (p == begin) {
2152 break;
2153 }
2154 p = begin;
2155 }
2156 return begin;
2157}
2158
2159template <typename Char> FMT_CONSTEXPR bool is_name_start(Char c) {
2160 return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || '_' == c;
2161}
2162
2163template <typename Char, typename IDHandler>
2164FMT_CONSTEXPR auto do_parse_arg_id(const Char* begin, const Char* end,
2165 IDHandler&& handler) -> const Char* {
2166 FMT_ASSERT(begin != end, "");
2167 Char c = *begin;
2168 if (c >= '0' && c <= '9') {
2169 int index = 0;
2170 if (c != '0')
2171 index =
2173 else
2174 ++begin;
2175 if (begin == end || (*begin != '}' && *begin != ':'))
2176 handler.on_error("invalid format string");
2177 else
2178 handler(index);
2179 return begin;
2180 }
2181 if (!is_name_start(c)) {
2182 handler.on_error("invalid format string");
2183 return begin;
2184 }
2185 auto it = begin;
2186 do {
2187 ++it;
2188 } while (it != end && (is_name_start(c = *it) || ('0' <= c && c <= '9')));
2189 handler(basic_string_view<Char>(begin, to_unsigned(it - begin)));
2190 return it;
2191}
2192
2193template <typename Char, typename IDHandler>
2194FMT_CONSTEXPR FMT_INLINE auto parse_arg_id(const Char* begin, const Char* end,
2195 IDHandler&& handler) -> const Char* {
2196 Char c = *begin;
2197 if (c != '}' && c != ':') return do_parse_arg_id(begin, end, handler);
2198 handler();
2199 return begin;
2200}
2201
2202template <typename Char, typename Handler>
2203FMT_CONSTEXPR auto parse_width(const Char* begin, const Char* end,
2204 Handler&& handler) -> const Char* {
2205 using detail::auto_id;
2206 struct width_adapter {
2207 Handler& handler;
2208
2209 FMT_CONSTEXPR void operator()() { handler.on_dynamic_width(auto_id()); }
2210 FMT_CONSTEXPR void operator()(int id) { handler.on_dynamic_width(id); }
2211 FMT_CONSTEXPR void operator()(basic_string_view<Char> id) {
2212 handler.on_dynamic_width(id);
2213 }
2214 FMT_CONSTEXPR void on_error(const char* message) {
2215 if (message) handler.on_error(message);
2216 }
2217 };
2218
2219 FMT_ASSERT(begin != end, "");
2220 if ('0' <= *begin && *begin <= '9') {
2221 int width = parse_nonnegative_int(begin, end, -1);
2222 if (width != -1)
2223 handler.on_width(width);
2224 else
2225 handler.on_error("number is too big");
2226 } else if (*begin == '{') {
2227 ++begin;
2228 if (begin != end) begin = parse_arg_id(begin, end, width_adapter{handler});
2229 if (begin == end || *begin != '}')
2230 return handler.on_error("invalid format string"), begin;
2231 ++begin;
2232 }
2233 return begin;
2234}
2235
2236template <typename Char, typename Handler>
2237FMT_CONSTEXPR auto parse_precision(const Char* begin, const Char* end,
2238 Handler&& handler) -> const Char* {
2239 using detail::auto_id;
2240 struct precision_adapter {
2241 Handler& handler;
2242
2243 FMT_CONSTEXPR void operator()() { handler.on_dynamic_precision(auto_id()); }
2244 FMT_CONSTEXPR void operator()(int id) { handler.on_dynamic_precision(id); }
2245 FMT_CONSTEXPR void operator()(basic_string_view<Char> id) {
2246 handler.on_dynamic_precision(id);
2247 }
2248 FMT_CONSTEXPR void on_error(const char* message) {
2249 if (message) handler.on_error(message);
2250 }
2251 };
2252
2253 ++begin;
2254 auto c = begin != end ? *begin : Char();
2255 if ('0' <= c && c <= '9') {
2256 auto precision = parse_nonnegative_int(begin, end, -1);
2257 if (precision != -1)
2258 handler.on_precision(precision);
2259 else
2260 handler.on_error("number is too big");
2261 } else if (c == '{') {
2262 ++begin;
2263 if (begin != end)
2264 begin = parse_arg_id(begin, end, precision_adapter{handler});
2265 if (begin == end || *begin++ != '}')
2266 return handler.on_error("invalid format string"), begin;
2267 } else {
2268 return handler.on_error("missing precision specifier"), begin;
2269 }
2270 handler.end_precision();
2271 return begin;
2272}
2273
2274// Parses standard format specifiers and sends notifications about parsed
2275// components to handler.
2276template <typename Char, typename SpecHandler>
2278 const Char* end,
2279 SpecHandler&& handler)
2280 -> const Char* {
2281 if (begin + 1 < end && begin[1] == '}' && is_ascii_letter(*begin) &&
2282 *begin != 'L') {
2283 handler.on_type(*begin++);
2284 return begin;
2285 }
2286
2287 if (begin == end) return begin;
2288
2289 begin = parse_align(begin, end, handler);
2290 if (begin == end) return begin;
2291
2292 // Parse sign.
2293 switch (to_ascii(*begin)) {
2294 case '+':
2295 handler.on_sign(sign::plus);
2296 ++begin;
2297 break;
2298 case '-':
2299 handler.on_sign(sign::minus);
2300 ++begin;
2301 break;
2302 case ' ':
2303 handler.on_sign(sign::space);
2304 ++begin;
2305 break;
2306 default:
2307 break;
2308 }
2309 if (begin == end) return begin;
2310
2311 if (*begin == '#') {
2312 handler.on_hash();
2313 if (++begin == end) return begin;
2314 }
2315
2316 // Parse zero flag.
2317 if (*begin == '0') {
2318 handler.on_zero();
2319 if (++begin == end) return begin;
2320 }
2321
2322 begin = parse_width(begin, end, handler);
2323 if (begin == end) return begin;
2324
2325 // Parse precision.
2326 if (*begin == '.') {
2327 begin = parse_precision(begin, end, handler);
2328 if (begin == end) return begin;
2329 }
2330
2331 if (*begin == 'L') {
2332 handler.on_localized();
2333 ++begin;
2334 }
2335
2336 // Parse type.
2337 if (begin != end && *begin != '}') handler.on_type(*begin++);
2338 return begin;
2339}
2340
2341template <typename Char, typename Handler>
2342FMT_CONSTEXPR auto parse_replacement_field(const Char* begin, const Char* end,
2343 Handler&& handler) -> const Char* {
2344 struct id_adapter {
2345 Handler& handler;
2346 int arg_id;
2347
2348 FMT_CONSTEXPR void operator()() { arg_id = handler.on_arg_id(); }
2349 FMT_CONSTEXPR void operator()(int id) { arg_id = handler.on_arg_id(id); }
2350 FMT_CONSTEXPR void operator()(basic_string_view<Char> id) {
2351 arg_id = handler.on_arg_id(id);
2352 }
2353 FMT_CONSTEXPR void on_error(const char* message) {
2354 if (message) handler.on_error(message);
2355 }
2356 };
2357
2358 ++begin;
2359 if (begin == end) return handler.on_error("invalid format string"), end;
2360 if (*begin == '}') {
2361 handler.on_replacement_field(handler.on_arg_id(), begin);
2362 } else if (*begin == '{') {
2363 handler.on_text(begin, begin + 1);
2364 } else {
2365 auto adapter = id_adapter{handler, 0};
2366 begin = parse_arg_id(begin, end, adapter);
2367 Char c = begin != end ? *begin : Char();
2368 if (c == '}') {
2369 handler.on_replacement_field(adapter.arg_id, begin);
2370 } else if (c == ':') {
2371 begin = handler.on_format_specs(adapter.arg_id, begin + 1, end);
2372 if (begin == end || *begin != '}')
2373 return handler.on_error("unknown format specifier"), end;
2374 } else {
2375 return handler.on_error("missing '}' in format string"), end;
2376 }
2377 }
2378 return begin + 1;
2379}
2380
2381template <bool IS_CONSTEXPR, typename Char, typename Handler>
2383 basic_string_view<Char> format_str, Handler&& handler) {
2384 // this is most likely a name-lookup defect in msvc's modules implementation
2385 using detail::find;
2386
2387 auto begin = format_str.data();
2388 auto end = begin + format_str.size();
2389 if (end - begin < 32) {
2390 // Use a simple loop instead of memchr for small strings.
2391 const Char* p = begin;
2392 while (p != end) {
2393 auto c = *p++;
2394 if (c == '{') {
2395 handler.on_text(begin, p - 1);
2396 begin = p = parse_replacement_field(p - 1, end, handler);
2397 } else if (c == '}') {
2398 if (p == end || *p != '}')
2399 return handler.on_error("unmatched '}' in format string");
2400 handler.on_text(begin, p);
2401 begin = ++p;
2402 }
2403 }
2404 handler.on_text(begin, end);
2405 return;
2406 }
2407 struct writer {
2408 FMT_CONSTEXPR void operator()(const Char* pbegin, const Char* pend) {
2409 if (pbegin == pend) return;
2410 for (;;) {
2411 const Char* p = nullptr;
2412 if (!find<IS_CONSTEXPR>(pbegin, pend, Char('}'), p))
2413 return handler_.on_text(pbegin, pend);
2414 ++p;
2415 if (p == pend || *p != '}')
2416 return handler_.on_error("unmatched '}' in format string");
2417 handler_.on_text(pbegin, p);
2418 pbegin = p + 1;
2419 }
2420 }
2421 Handler& handler_;
2422 } write{handler};
2423 while (begin != end) {
2424 // Doing two passes with memchr (one for '{' and another for '}') is up to
2425 // 2.5x faster than the naive one-pass implementation on big format strings.
2426 const Char* p = begin;
2427 if (*begin != '{' && !find<IS_CONSTEXPR>(begin + 1, end, Char('{'), p))
2428 return write(begin, end);
2429 write(begin, p);
2430 begin = parse_replacement_field(p, end, handler);
2431 }
2432}
2433
2434template <typename T, typename ParseContext>
2435FMT_CONSTEXPR auto parse_format_specs(ParseContext& ctx)
2436 -> decltype(ctx.begin()) {
2437 using char_type = typename ParseContext::char_type;
2438 using context = buffer_context<char_type>;
2439 using mapped_type = conditional_t<
2445 return f.parse(ctx);
2446}
2447
2448// A parse context with extra argument id checks. It is only used at compile
2449// time because adding checks at runtime would introduce substantial overhead
2450// and would be redundant since argument ids are checked when arguments are
2451// retrieved anyway.
2452template <typename Char, typename ErrorHandler = error_handler>
2454 : public basic_format_parse_context<Char, ErrorHandler> {
2455 private:
2458
2459 public:
2461 basic_string_view<Char> format_str,
2462 int num_args = (std::numeric_limits<int>::max)(), ErrorHandler eh = {})
2463 : base(format_str, eh), num_args_(num_args) {}
2464
2466 int id = base::next_arg_id();
2467 if (id >= num_args_) this->on_error("argument not found");
2468 return id;
2469 }
2470
2472 base::check_arg_id(id);
2473 if (id >= num_args_) this->on_error("argument not found");
2474 }
2475 using base::check_arg_id;
2476};
2477
2478template <typename ErrorHandler>
2479FMT_CONSTEXPR void check_int_type_spec(char spec, ErrorHandler&& eh) {
2480 switch (spec) {
2481 case 0:
2482 case 'd':
2483 case 'x':
2484 case 'X':
2485 case 'b':
2486 case 'B':
2487 case 'o':
2488 case 'c':
2489 break;
2490 default:
2491 eh.on_error("invalid type specifier");
2492 break;
2493 }
2494}
2495
2496// Checks char specs and returns true if the type spec is char (and not int).
2497template <typename Char, typename ErrorHandler = error_handler>
2499 ErrorHandler&& eh = {}) -> bool {
2500 if (specs.type && specs.type != 'c') {
2501 check_int_type_spec(specs.type, eh);
2502 return false;
2503 }
2504 if (specs.align == align::numeric || specs.sign != sign::none || specs.alt)
2505 eh.on_error("invalid format specifier for char");
2506 return true;
2507}
2508
2509// A floating-point presentation format.
2510enum class float_format : unsigned char {
2511 general, // General: exponent notation or fixed point based on magnitude.
2512 exp, // Exponent notation with the default precision of 6, e.g. 1.2e-3.
2513 fixed, // Fixed point with the default precision of 6, e.g. 0.0012.
2514 hex
2515};
2516
2521 bool upper : 1;
2522 bool locale : 1;
2523 bool binary32 : 1;
2524 bool use_grisu : 1;
2525 bool showpoint : 1;
2526};
2527
2528template <typename ErrorHandler = error_handler, typename Char>
2530 ErrorHandler&& eh = {})
2531 -> float_specs {
2532 auto result = float_specs();
2533 result.showpoint = specs.alt;
2534 result.locale = specs.localized;
2535 switch (specs.type) {
2536 case 0:
2538 break;
2539 case 'G':
2540 result.upper = true;
2542 case 'g':
2544 break;
2545 case 'E':
2546 result.upper = true;
2548 case 'e':
2549 result.format = float_format::exp;
2550 result.showpoint |= specs.precision != 0;
2551 break;
2552 case 'F':
2553 result.upper = true;
2555 case 'f':
2556 result.format = float_format::fixed;
2557 result.showpoint |= specs.precision != 0;
2558 break;
2559 case 'A':
2560 result.upper = true;
2562 case 'a':
2563 result.format = float_format::hex;
2564 break;
2565 default:
2566 eh.on_error("invalid type specifier");
2567 break;
2568 }
2569 return result;
2570}
2571
2572template <typename Char, typename ErrorHandler = error_handler>
2573FMT_CONSTEXPR auto check_cstring_type_spec(Char spec, ErrorHandler&& eh = {})
2574 -> bool {
2575 if (spec == 0 || spec == 's') return true;
2576 if (spec != 'p') eh.on_error("invalid type specifier");
2577 return false;
2578}
2579
2580template <typename Char, typename ErrorHandler = error_handler>
2581FMT_CONSTEXPR void check_string_type_spec(Char spec, ErrorHandler&& eh = {}) {
2582 if (spec != 0 && spec != 's') eh.on_error("invalid type specifier");
2583}
2584
2585template <typename Char, typename ErrorHandler>
2586FMT_CONSTEXPR void check_pointer_type_spec(Char spec, ErrorHandler&& eh) {
2587 if (spec != 0 && spec != 'p') eh.on_error("invalid type specifier");
2588}
2589
2590// A parse_format_specs handler that checks if specifiers are consistent with
2591// the argument type.
2592template <typename Handler> class specs_checker : public Handler {
2593 private:
2594 detail::type arg_type_;
2595
2597 if (!is_arithmetic_type(arg_type_))
2598 this->on_error("format specifier requires numeric argument");
2599 }
2600
2601 public:
2602 FMT_CONSTEXPR specs_checker(const Handler& handler, detail::type arg_type)
2603 : Handler(handler), arg_type_(arg_type) {}
2604
2606 if (align == align::numeric) require_numeric_argument();
2607 Handler::on_align(align);
2608 }
2609
2611 require_numeric_argument();
2612 if (is_integral_type(arg_type_) && arg_type_ != type::int_type &&
2613 arg_type_ != type::long_long_type && arg_type_ != type::char_type) {
2614 this->on_error("format specifier requires signed argument");
2615 }
2616 Handler::on_sign(s);
2617 }
2618
2620 require_numeric_argument();
2621 Handler::on_hash();
2622 }
2623
2625 require_numeric_argument();
2626 Handler::on_localized();
2627 }
2628
2630 require_numeric_argument();
2631 Handler::on_zero();
2632 }
2633
2635 if (is_integral_type(arg_type_) || arg_type_ == type::pointer_type)
2636 this->on_error("precision not allowed for this argument type");
2637 }
2638};
2639
2640constexpr int invalid_arg_index = -1;
2641
2642#if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS
2643template <int N, typename T, typename... Args, typename Char>
2644constexpr auto get_arg_index_by_name(basic_string_view<Char> name) -> int {
2645 if constexpr (detail::is_statically_named_arg<T>()) {
2646 if (name == T::name) return N;
2647 }
2648 if constexpr (sizeof...(Args) > 0) {
2649 return get_arg_index_by_name<N + 1, Args...>(name);
2650 } else {
2651 (void)name; // Workaround an MSVC bug about "unused" parameter.
2652 return invalid_arg_index;
2653 }
2654}
2655#endif
2656
2657template <typename... Args, typename Char>
2659#if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS
2660 if constexpr (sizeof...(Args) > 0) {
2661 return get_arg_index_by_name<0, Args...>(name);
2662 } else {
2663 (void)name;
2664 return invalid_arg_index;
2665 }
2666#else
2667 (void)name;
2668 return invalid_arg_index;
2669#endif
2670}
2671
2672template <typename Char, typename ErrorHandler, typename... Args>
2674 private:
2676 enum { num_args = sizeof...(Args) };
2677
2678 // Format specifier parsing function.
2679 using parse_func = const Char* (*)(parse_context_type&);
2680
2682 parse_func parse_funcs_[num_args > 0 ? num_args : 1];
2683
2684 public:
2686 basic_string_view<Char> format_str, ErrorHandler eh)
2687 : context_(format_str, num_args, eh),
2688 parse_funcs_{&parse_format_specs<Args, parse_context_type>...} {}
2689
2690 FMT_CONSTEXPR void on_text(const Char*, const Char*) {}
2691
2692 FMT_CONSTEXPR auto on_arg_id() -> int { return context_.next_arg_id(); }
2693 FMT_CONSTEXPR auto on_arg_id(int id) -> int {
2694 return context_.check_arg_id(id), id;
2695 }
2697#if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS
2698 auto index = get_arg_index_by_name<Args...>(id);
2699 if (index == invalid_arg_index) on_error("named argument is not found");
2700 return context_.check_arg_id(index), index;
2701#else
2702 (void)id;
2703 on_error("compile-time checks for named arguments require C++20 support");
2704 return 0;
2705#endif
2706 }
2707
2708 FMT_CONSTEXPR void on_replacement_field(int, const Char*) {}
2709
2710 FMT_CONSTEXPR auto on_format_specs(int id, const Char* begin, const Char*)
2711 -> const Char* {
2712 context_.advance_to(context_.begin() + (begin - &*context_.begin()));
2713 // id >= 0 check is a workaround for gcc 10 bug (#2065).
2714 return id >= 0 && id < num_args ? parse_funcs_[id](context_) : begin;
2715 }
2716
2717 FMT_CONSTEXPR void on_error(const char* message) {
2718 context_.on_error(message);
2719 }
2720};
2721
2722template <typename... Args, typename S,
2723 enable_if_t<(is_compile_string<S>::value), int>>
2724void check_format_string(S format_str) {
2725 FMT_CONSTEXPR auto s = to_string_view(format_str);
2726 using checker = format_string_checker<typename S::char_type, error_handler,
2728 FMT_CONSTEXPR bool invalid_format =
2729 (parse_format_string<true>(s, checker(s, {})), true);
2730 ignore_unused(invalid_format);
2731}
2732
2733template <typename Char>
2734void vformat_to(
2737 locale_ref loc = {});
2738
2740#ifndef _WIN32
2742#endif
2744
2745// A formatter specialization for the core types corresponding to detail::type
2746// constants.
2747template <typename T, typename Char>
2748struct formatter<T, Char,
2749 enable_if_t<detail::type_constant<T, Char>::value !=
2750 detail::type::custom_type>> {
2751 private:
2752 detail::dynamic_format_specs<Char> specs_;
2753
2754 public:
2755 // Parses format specifiers stopping either at the end of the range or at the
2756 // terminating '}'.
2757 template <typename ParseContext>
2758 FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
2759 auto begin = ctx.begin(), end = ctx.end();
2760 if (begin == end) return begin;
2761 using handler_type = detail::dynamic_specs_handler<ParseContext>;
2762 auto type = detail::type_constant<T, Char>::value;
2763 auto checker =
2764 detail::specs_checker<handler_type>(handler_type(specs_, ctx), type);
2765 auto it = detail::parse_format_specs(begin, end, checker);
2766 auto eh = ctx.error_handler();
2767 switch (type) {
2768 case detail::type::none_type:
2769 FMT_ASSERT(false, "invalid argument type");
2770 break;
2771 case detail::type::bool_type:
2772 if (!specs_.type || specs_.type == 's') break;
2774 case detail::type::int_type:
2775 case detail::type::uint_type:
2776 case detail::type::long_long_type:
2777 case detail::type::ulong_long_type:
2778 case detail::type::int128_type:
2779 case detail::type::uint128_type:
2780 detail::check_int_type_spec(specs_.type, eh);
2781 break;
2782 case detail::type::char_type:
2783 detail::check_char_specs(specs_, eh);
2784 break;
2785 case detail::type::float_type:
2786 if (detail::const_check(FMT_USE_FLOAT))
2787 detail::parse_float_type_spec(specs_, eh);
2788 else
2789 FMT_ASSERT(false, "float support disabled");
2790 break;
2791 case detail::type::double_type:
2792 if (detail::const_check(FMT_USE_DOUBLE))
2793 detail::parse_float_type_spec(specs_, eh);
2794 else
2795 FMT_ASSERT(false, "double support disabled");
2796 break;
2797 case detail::type::long_double_type:
2798 if (detail::const_check(FMT_USE_LONG_DOUBLE))
2799 detail::parse_float_type_spec(specs_, eh);
2800 else
2801 FMT_ASSERT(false, "long double support disabled");
2802 break;
2803 case detail::type::cstring_type:
2804 detail::check_cstring_type_spec(specs_.type, eh);
2805 break;
2806 case detail::type::string_type:
2807 detail::check_string_type_spec(specs_.type, eh);
2808 break;
2809 case detail::type::pointer_type:
2810 detail::check_pointer_type_spec(specs_.type, eh);
2811 break;
2812 case detail::type::custom_type:
2813 // Custom format specifiers are checked in parse functions of
2814 // formatter specializations.
2815 break;
2816 }
2817 return it;
2818 }
2819
2820 template <typename FormatContext>
2821 FMT_CONSTEXPR auto format(const T& val, FormatContext& ctx) const
2822 -> decltype(ctx.out());
2823};
2824
2825template <typename Char> struct basic_runtime { basic_string_view<Char> str; };
2826
2827template <typename Char, typename... Args> class basic_format_string {
2828 private:
2830
2831 public:
2832 template <typename S,
2835 FMT_CONSTEVAL basic_format_string(const S& s) : str_(s) {
2836 static_assert(
2837 detail::count<
2840 "passing views as lvalues is disallowed");
2841#ifdef FMT_HAS_CONSTEVAL
2842 if constexpr (detail::count_named_args<Args...>() == 0) {
2843 using checker = detail::format_string_checker<Char, detail::error_handler,
2845 detail::parse_format_string<true>(str_, checker(s, {}));
2846 }
2847#else
2848 detail::check_format_string<Args...>(s);
2849#endif
2850 }
2852
2853 FMT_INLINE operator basic_string_view<Char>() const { return str_; }
2854};
2855
2856#if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
2857// Workaround broken conversion on older gcc.
2858template <typename... Args> using format_string = string_view;
2859template <typename S> auto runtime(const S& s) -> basic_string_view<char_t<S>> {
2860 return s;
2861}
2862#else
2863template <typename... Args>
2865// Creates a runtime format string.
2866template <typename S> auto runtime(const S& s) -> basic_runtime<char_t<S>> {
2867 return {{s}};
2868}
2869#endif
2870
2872
2873/**
2874 \rst
2875 Formats ``args`` according to specifications in ``fmt`` and returns the result
2876 as a string.
2877
2878 **Example**::
2879
2880 #include <fmt/core.h>
2881 std::string message = fmt::format("The answer is {}", 42);
2882 \endrst
2883*/
2884template <typename... T>
2886 return vformat(fmt, fmt::make_format_args(args...));
2887}
2888
2889/** Formats a string and writes the output to ``out``. */
2890template <typename OutputIt,
2891 FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
2892auto vformat_to(OutputIt out, string_view fmt, format_args args) -> OutputIt {
2893 using detail::get_buffer;
2894 auto&& buf = get_buffer<char>(out);
2895 detail::vformat_to(buf, string_view(fmt), args, {});
2896 return detail::get_iterator(buf);
2897}
2898
2899/**
2900 \rst
2901 Formats ``args`` according to specifications in ``fmt``, writes the result to
2902 the output iterator ``out`` and returns the iterator past the end of the output
2903 range.
2904
2905 **Example**::
2906
2907 auto out = std::vector<char>();
2908 fmt::format_to(std::back_inserter(out), "{}", 42);
2909 \endrst
2910 */
2911template <typename OutputIt, typename... T,
2912 FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
2913FMT_INLINE auto format_to(OutputIt out, format_string<T...> fmt, T&&... args)
2914 -> OutputIt {
2915 return vformat_to(out, fmt, fmt::make_format_args(args...));
2916}
2917
2918template <typename OutputIt> struct format_to_n_result {
2919 /** Iterator past the end of the output range. */
2920 OutputIt out;
2921 /** Total (not truncated) output size. */
2922 size_t size;
2923};
2924
2925template <typename OutputIt, typename... T,
2926 FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
2927auto vformat_to_n(OutputIt out, size_t n, string_view fmt, format_args args)
2929 using buffer =
2930 detail::iterator_buffer<OutputIt, char, detail::fixed_buffer_traits>;
2931 auto buf = buffer(out, n);
2932 detail::vformat_to(buf, fmt, args, {});
2933 return {buf.out(), buf.count()};
2934}
2935
2936/**
2937 \rst
2938 Formats ``args`` according to specifications in ``fmt``, writes up to ``n``
2939 characters of the result to the output iterator ``out`` and returns the total
2940 (not truncated) output size and the iterator past the end of the output range.
2941 \endrst
2942 */
2943template <typename OutputIt, typename... T,
2944 FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
2945FMT_INLINE auto format_to_n(OutputIt out, size_t n, format_string<T...> fmt,
2946 const T&... args) -> format_to_n_result<OutputIt> {
2947 return vformat_to_n(out, n, fmt, fmt::make_format_args(args...));
2948}
2949
2950/** Returns the number of chars in the output of ``format(fmt, args...)``. */
2951template <typename... T>
2953 auto buf = detail::counting_buffer<>();
2954 detail::vformat_to(buf, string_view(fmt), fmt::make_format_args(args...), {});
2955 return buf.count();
2956}
2957
2960
2961/**
2962 \rst
2963 Formats ``args`` according to specifications in ``fmt`` and writes the output
2964 to ``stdout``.
2965
2966 **Example**::
2967
2968 fmt::print("Elapsed time: {0:.2f} seconds", 1.23);
2969 \endrst
2970 */
2971template <typename... T>
2973 const auto& vargs = fmt::make_format_args(args...);
2974 return detail::is_utf8() ? vprint(fmt, vargs)
2975 : detail::vprint_mojibake(stdout, fmt, vargs);
2976}
2977
2978/**
2979 \rst
2980 Formats ``args`` according to specifications in ``fmt`` and writes the
2981 output to the file ``f``.
2982
2983 **Example**::
2984
2985 fmt::print(stderr, "Don't {}!", "panic");
2986 \endrst
2987 */
2988template <typename... T>
2990 const auto& vargs = fmt::make_format_args(args...);
2991 return detail::is_utf8() ? vprint(f, fmt, vargs)
2992 : detail::vprint_mojibake(f, fmt, vargs);
2993}
2994
2996FMT_GCC_PRAGMA("GCC pop_options")
2998
2999#ifdef FMT_HEADER_ONLY
3000# include "format.h"
3001#endif
3002#endif // FMT_CORE_H_
T back_inserter(T... args)
auto operator++(int) -> appender
Definition core.h:1377
appender(base it)
Definition core.h:1369
auto operator++() -> appender &
Definition core.h:1372
friend auto get_buffer(appender out) -> detail::buffer< char > &
Definition core.h:1363
void format(typename Context::parse_context_type &parse_ctx, Context &ctx) const
Definition core.h:1416
handle(detail::custom_value< Context > custom)
Definition core.h:1414
detail::custom_value< Context > custom_
Definition core.h:1422
constexpr basic_format_arg()
Definition core.h:1425
detail::type type_
Definition core.h:1389
auto type() const -> detail::type
Definition core.h:1431
basic_format_arg(const detail::named_arg_info< char_type > *args, size_t size)
Definition core.h:1408
typename Context::char_type char_type
Definition core.h:1403
detail::value< Context > value_
Definition core.h:1388
friend struct detail::arg_data
Definition core.h:1406
friend FMT_CONSTEXPR auto visit_format_arg(Visitor &&vis, const basic_format_arg< Ctx > &arg) -> decltype(vis(0))
auto is_arithmetic() const -> bool
Definition core.h:1434
auto is_integral() const -> bool
Definition core.h:1433
friend FMT_CONSTEXPR auto detail::make_arg(const T &value) -> basic_format_arg< ContextType >
constexpr basic_format_args()
Definition core.h:1781
const format_arg * args_
Definition core.h:1758
constexpr basic_format_args(unsigned long long desc, const format_arg *args)
Definition core.h:1777
constexpr basic_format_args(const format_arg *args, int count)
Definition core.h:1809
FMT_CONSTEXPR auto get(int id) const -> format_arg
Definition core.h:1814
const detail::value< Context > * values_
Definition core.h:1757
constexpr FMT_INLINE basic_format_args(unsigned long long desc, const detail::value< Context > *values)
Definition core.h:1774
FMT_CONSTEXPR auto type(int index) const -> detail::type
Definition core.h:1768
constexpr FMT_INLINE basic_format_args(const dynamic_format_arg_store< Context > &store)
Definition core.h:1800
auto max_size() const -> int
Definition core.h:1844
auto has_named_args() const -> bool
Definition core.h:1764
constexpr auto is_packed() const -> bool
Definition core.h:1761
auto get(basic_string_view< Char > name) const -> format_arg
Definition core.h:1828
constexpr FMT_INLINE basic_format_args(const format_arg_store< Context, Args... > &store)
Definition core.h:1789
unsigned long long desc_
Definition core.h:1750
auto get_id(basic_string_view< Char > name) const -> int
Definition core.h:1834
basic_format_context(const basic_format_context &)=delete
detail::locale_ref loc_
Definition core.h:1590
OutputIt iterator
Definition core.h:1593
FMT_CONSTEXPR auto locale() -> detail::locale_ref
Definition core.h:1632
FMT_CONSTEXPR auto out() -> iterator
Definition core.h:1625
FMT_CONSTEXPR auto arg(basic_string_view< char_type > name) -> format_arg
Definition core.h:1611
FMT_CONSTEXPR auto arg_id(basic_string_view< char_type > name) -> int
Definition core.h:1614
void on_error(const char *message)
Definition core.h:1622
FMT_CONSTEXPR auto error_handler() -> detail::error_handler
Definition core.h:1621
constexpr auto arg(int id) const -> format_arg
Definition core.h:1610
auto args() const -> const basic_format_args< basic_format_context > &
Definition core.h:1617
void advance_to(iterator it)
Definition core.h:1628
constexpr basic_format_context(OutputIt out, basic_format_args< basic_format_context > ctx_args, detail::locale_ref loc=detail::locale_ref())
Definition core.h:1605
basic_format_context(basic_format_context &&)=default
void operator=(const basic_format_context &)=delete
basic_format_args< basic_format_context > args_
Definition core.h:1589
FMT_CONSTEXPR void check_arg_id(basic_string_view< Char >)
Definition core.h:677
constexpr auto error_handler() const -> ErrorHandler
Definition core.h:683
basic_string_view< Char > format_str_
Definition core.h:622
FMT_CONSTEXPR void on_error(const char *message)
Definition core.h:679
constexpr auto end() const FMT_NOEXCEPT -> iterator
Definition core.h:645
FMT_CONSTEXPR void check_arg_id(int)
Definition core.h:670
typename basic_string_view< Char >::iterator iterator
Definition core.h:627
FMT_CONSTEXPR auto next_arg_id() -> int
Definition core.h:658
FMT_CONSTEXPR void advance_to(iterator it)
Definition core.h:650
constexpr basic_format_parse_context(basic_string_view< Char > format_str, ErrorHandler eh={}, int next_arg_id=0)
Definition core.h:629
constexpr auto begin() const FMT_NOEXCEPT -> iterator
Definition core.h:638
basic_string_view< Char > str_
Definition core.h:2829
FMT_CONSTEVAL basic_format_string(const S &s)
Definition core.h:2835
basic_format_string(basic_runtime< Char > r)
Definition core.h:2851
constexpr basic_string_view(const Char *s, size_t count) FMT_NOEXCEPT
Definition core.h:448
const Char * data_
Definition core.h:438
const Char * iterator
Definition core.h:443
FMT_CONSTEXPR void remove_prefix(size_t n)
Definition core.h:493
FMT_CONSTEXPR basic_string_view(const std::basic_string< Char, Traits, Alloc > &s) FMT_NOEXCEPT
Definition core.h:470
FMT_CONSTEXPR_CHAR_TRAITS friend auto operator==(basic_string_view lhs, basic_string_view rhs) -> bool
Definition core.h:507
friend auto operator>(basic_string_view lhs, basic_string_view rhs) -> bool
Definition core.h:521
friend auto operator<(basic_string_view lhs, basic_string_view rhs) -> bool
Definition core.h:515
Char value_type
Definition core.h:442
constexpr basic_string_view() FMT_NOEXCEPT
Definition core.h:445
constexpr auto end() const -> iterator
Definition core.h:487
constexpr auto data() const -> const Char *
Definition core.h:481
FMT_CONSTEXPR basic_string_view(S s) FMT_NOEXCEPT
Definition core.h:477
constexpr auto operator[](size_t pos) const -> const Char &
Definition core.h:489
friend auto operator<=(basic_string_view lhs, basic_string_view rhs) -> bool
Definition core.h:518
FMT_CONSTEXPR_CHAR_TRAITS FMT_INLINE basic_string_view(const Char *s)
Definition core.h:460
constexpr auto size() const -> size_t
Definition core.h:484
friend auto operator!=(basic_string_view lhs, basic_string_view rhs) -> bool
Definition core.h:512
constexpr auto begin() const -> iterator
Definition core.h:486
friend auto operator>=(basic_string_view lhs, basic_string_view rhs) -> bool
Definition core.h:524
size_t size_
Definition core.h:439
FMT_CONSTEXPR_CHAR_TRAITS auto compare(basic_string_view other) const -> int
Definition core.h:499
Definition core.h:749
auto end() FMT_NOEXCEPT -> T *
Definition core.h:785
void append(const U *begin, const U *end)
auto size() const FMT_NOEXCEPT -> size_t
Definition core.h:791
size_t size_
Definition core.h:752
auto end() const FMT_NOEXCEPT -> const T *
Definition core.h:788
auto operator[](I index) -> T &
Definition core.h:828
buffer(const buffer &)=delete
~buffer()=default
void clear()
Definition core.h:803
auto operator[](I index) const -> const T &
Definition core.h:829
void set(T *buf_data, size_t buf_capacity) FMT_NOEXCEPT
Definition core.h:769
auto begin() FMT_NOEXCEPT -> T *
Definition core.h:784
void try_reserve(size_t new_capacity)
Definition core.h:816
auto data() const FMT_NOEXCEPT -> const T *
Definition core.h:800
const T & const_reference
Definition core.h:779
T value_type
Definition core.h:778
size_t capacity_
Definition core.h:753
void push_back(const T &value)
Definition core.h:820
buffer(T *p=nullptr, size_t sz=0, size_t cap=0) FMT_NOEXCEPT
Definition core.h:760
FMT_MSC_WARNING(suppress :26495) buffer(size_t sz) FMT_NOEXCEPT
Definition core.h:757
T * ptr_
Definition core.h:751
virtual void grow(size_t capacity)=0
void try_resize(size_t count)
Definition core.h:807
auto capacity() const FMT_NOEXCEPT -> size_t
Definition core.h:794
void operator=(const buffer &)=delete
buffer(buffer &&)=default
auto begin() const FMT_NOEXCEPT -> const T *
Definition core.h:787
auto data() FMT_NOEXCEPT -> T *
Definition core.h:797
FMT_CONSTEXPR void check_arg_id(int id)
Definition core.h:2471
FMT_CONSTEXPR compile_parse_context(basic_string_view< Char > format_str, int num_args=(std::numeric_limits< int >::max)(), ErrorHandler eh={})
Definition core.h:2460
FMT_CONSTEXPR auto next_arg_id() -> int
Definition core.h:2465
void grow(size_t) final FMT_OVERRIDE
Definition core.h:931
auto count() -> size_t
Definition core.h:940
T data_[buffer_size]
Definition core.h:927
size_t count_
Definition core.h:928
counting_buffer()
Definition core.h:938
typename ParseContext::char_type char_type
Definition core.h:2001
FMT_CONSTEXPR dynamic_specs_handler(const dynamic_specs_handler &other)
Definition core.h:2007
ParseContext & context_
Definition core.h:2026
dynamic_format_specs< char_type > & specs_
Definition core.h:2025
FMT_CONSTEXPR dynamic_specs_handler(dynamic_format_specs< char_type > &specs, ParseContext &ctx)
Definition core.h:2003
FMT_CONSTEXPR void on_dynamic_precision(Id arg_id)
Definition core.h:2016
FMT_CONSTEXPR auto make_arg_ref(int arg_id) -> arg_ref_type
Definition core.h:2030
FMT_CONSTEXPR void on_error(const char *message)
Definition core.h:2020
FMT_CONSTEXPR void on_dynamic_width(Id arg_id)
Definition core.h:2012
FMT_CONSTEXPR auto make_arg_ref(auto_id) -> arg_ref_type
Definition core.h:2035
FMT_CONSTEXPR auto make_arg_ref(basic_string_view< char_type > arg_id) -> arg_ref_type
Definition core.h:2039
fixed_buffer_traits(size_t limit)
Definition core.h:846
auto limit(size_t size) -> size_t
Definition core.h:848
auto count() const -> size_t
Definition core.h:847
FMT_CONSTEXPR FMT_INLINE format_arg_store(const Args &... args)
Definition core.h:1687
conditional_t< is_packed, detail::value< Context >, basic_format_arg< Context > > value_type
Definition core.h:1671
FMT_CONSTEXPR void on_error(const char *message)
Definition core.h:2717
FMT_CONSTEXPR format_string_checker(basic_string_view< Char > format_str, ErrorHandler eh)
Definition core.h:2685
FMT_CONSTEXPR void on_text(const Char *, const Char *)
Definition core.h:2690
const Char *(*)(parse_context_type &) parse_func
Definition core.h:2679
FMT_CONSTEXPR auto on_format_specs(int id, const Char *begin, const Char *) -> const Char *
Definition core.h:2710
parse_context_type context_
Definition core.h:2681
FMT_CONSTEXPR auto on_arg_id(int id) -> int
Definition core.h:2693
FMT_CONSTEXPR void on_replacement_field(int, const Char *)
Definition core.h:2708
FMT_CONSTEXPR auto on_arg_id(basic_string_view< Char > id) -> int
Definition core.h:2696
FMT_CONSTEXPR auto on_arg_id() -> int
Definition core.h:2692
iterator_buffer(T *out, size_t=0)
Definition core.h:893
auto out() -> T *
Definition core.h:895
void grow(size_t) final FMT_OVERRIDE
Definition core.h:890
auto out() -> OutputIt
Definition core.h:881
iterator_buffer(OutputIt out, size_t n=buffer_size)
Definition core.h:875
auto count() const -> size_t
Definition core.h:885
void flush()
Definition core.h:868
iterator_buffer(iterator_buffer &&other)
Definition core.h:877
OutputIt out_
Definition core.h:859
void grow(size_t) final FMT_OVERRIDE
Definition core.h:864
T data_[buffer_size]
Definition core.h:861
~iterator_buffer()
Definition core.h:879
const void * locale_
Definition core.h:1531
constexpr locale_ref()
Definition core.h:1534
auto get() const -> Locale
FMT_CONSTEXPR void end_precision()
Definition core.h:2634
FMT_CONSTEXPR void on_zero()
Definition core.h:2629
detail::type arg_type_
Definition core.h:2594
FMT_CONSTEXPR specs_checker(const Handler &handler, detail::type arg_type)
Definition core.h:2602
FMT_CONSTEXPR void on_align(align_t align)
Definition core.h:2605
FMT_CONSTEXPR void on_hash()
Definition core.h:2619
FMT_CONSTEXPR void require_numeric_argument()
Definition core.h:2596
FMT_CONSTEXPR void on_sign(sign_t s)
Definition core.h:2610
FMT_CONSTEXPR void on_localized()
Definition core.h:2624
FMT_CONSTEXPR void on_sign(sign_t s)
Definition core.h:1975
basic_format_specs< Char > & specs_
Definition core.h:1962
FMT_CONSTEXPR void on_precision(int precision)
Definition core.h:1985
FMT_CONSTEXPR specs_setter(basic_format_specs< Char > &specs)
Definition core.h:1965
FMT_CONSTEXPR void on_hash()
Definition core.h:1976
FMT_CONSTEXPR void on_zero()
Definition core.h:1979
FMT_CONSTEXPR void on_localized()
Definition core.h:1977
FMT_CONSTEXPR specs_setter(const specs_setter &other)
Definition core.h:1968
FMT_CONSTEXPR void on_width(int width)
Definition core.h:1984
FMT_CONSTEXPR void end_precision()
Definition core.h:1988
FMT_CONSTEXPR void on_type(Char type)
Definition core.h:1990
FMT_CONSTEXPR void on_align(align_t align)
Definition core.h:1971
FMT_CONSTEXPR void on_fill(basic_string_view< Char > fill)
Definition core.h:1972
Definition core.h:1120
FMT_CONSTEXPR FMT_INLINE value(const char_type *val)
Definition core.h:1155
long double long_double_value
Definition core.h:1136
int128_t int128_value
Definition core.h:1130
constexpr FMT_INLINE value(char_type val)
Definition core.h:1154
long long long_long_value
Definition core.h:1128
const void * pointer
Definition core.h:1137
constexpr FMT_INLINE value()
Definition core.h:1143
constexpr FMT_INLINE value(bool val)
Definition core.h:1153
constexpr FMT_INLINE value(int val)
Definition core.h:1144
constexpr FMT_INLINE value(unsigned long long val)
Definition core.h:1147
FMT_INLINE value(const named_arg_info< char_type > *args, size_t size)
Definition core.h:1164
constexpr FMT_INLINE value(unsigned val)
Definition core.h:1145
constexpr FMT_INLINE value(long long val)
Definition core.h:1146
bool bool_value
Definition core.h:1132
uint128_t uint128_value
Definition core.h:1131
monostate no_value
Definition core.h:1125
FMT_INLINE value(uint128_t val)
Definition core.h:1149
FMT_CONSTEXPR FMT_INLINE value(const T &val)
Definition core.h:1167
unsigned long long ulong_long_value
Definition core.h:1129
FMT_INLINE value(double val)
Definition core.h:1151
char_type char_value
Definition core.h:1133
FMT_INLINE value(int128_t val)
Definition core.h:1148
float float_value
Definition core.h:1134
typename Context::char_type char_type
Definition core.h:1122
int int_value
Definition core.h:1126
FMT_INLINE value(long double val)
Definition core.h:1152
FMT_INLINE value(const void *val)
Definition core.h:1163
FMT_INLINE value(float val)
Definition core.h:1150
unsigned uint_value
Definition core.h:1127
FMT_CONSTEXPR FMT_INLINE value(basic_string_view< char_type > val)
Definition core.h:1159
custom_value< Context > custom
Definition core.h:1139
named_arg_value< char_type > named_args
Definition core.h:1140
static void format_custom_arg(const void *arg, typename Context::parse_context_type &parse_ctx, Context &ctx)
Definition core.h:1181
string_value< char_type > string
Definition core.h:1138
double double_value
Definition core.h:1135
T compare(T... args)
FMT_CONSTEXPR bool is_name_start(Char c)
Definition core.h:2159
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
Definition core.h:2078
#define FMT_OVERRIDE
Definition core.h:124
FMT_CONSTEXPR void ignore_unused(const T &...)
Definition core.h:339
#define FMT_ASSERT(condition, message)
Definition core.h:372
FMT_CONSTEXPR FMT_INLINE auto visit_format_arg(Visitor &&vis, const basic_format_arg< Context > &arg) -> decltype(vis(0))
Definition core.h:1447
FMT_CONSTEXPR auto copy_str(InputIt begin, InputIt end, OutputIt out) -> OutputIt
Definition core.h:727
FMT_CONSTEXPR FMT_INLINE auto parse_format_specs(const Char *begin, const Char *end, SpecHandler &&handler) -> const Char *
Definition core.h:2277
FMT_CONSTEXPR auto code_point_length(const Char *begin) -> int
Definition core.h:2064
FMT_INLINE auto format_to_n(OutputIt out, size_t n, format_string< T... > fmt, const T &... args) -> format_to_n_result< OutputIt >
Definition core.h:2945
#define FMT_USE_LONG_DOUBLE
Definition core.h:202
#define FMT_CONSTEVAL
Definition core.h:296
#define FMT_TYPE_CONSTANT(Type, constant)
Definition core.h:1075
constexpr bool is_ascii_letter(Char c)
Definition core.h:2048
basic_string_view< char > string_view
Definition core.h:529
FMT_CONSTEXPR auto parse_replacement_field(const Char *begin, const Char *end, Handler &&handler) -> const Char *
Definition core.h:2342
#define FMT_UNICODE
Definition core.h:285
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Definition core.h:1725
conditional_t< long_short, unsigned, unsigned long long > ulong_type
Definition core.h:1197
FMT_CONSTEXPR auto check_char_specs(const basic_format_specs< Char > &specs, ErrorHandler &&eh={}) -> bool
Definition core.h:2498
FMT_CONSTEXPR void check_string_type_spec(Char spec, ErrorHandler &&eh={})
Definition core.h:2581
#define FMT_FALLTHROUGH
Definition core.h:192
void init_named_args(named_arg_info< Char > *, int, int)
Definition core.h:1012
typename std::remove_reference< T >::type remove_reference_t
Definition core.h:326
typename detail::char_t_impl< S >::type char_t
Definition core.h:610
#define FMT_END_DETAIL_NAMESPACE
Definition core.h:245
buffer_context< char > format_context
Definition core.h:1638
#define FMT_MODULE_EXPORT_BEGIN
Definition core.h:242
FMT_INLINE auto formatted_size(format_string< T... > fmt, T &&... args) -> size_t
Definition core.h:2952
FMT_API void vprint(string_view fmt, format_args args)
#define FMT_USE_FLOAT
Definition core.h:196
auto vformat_to_n(OutputIt out, size_t n, string_view fmt, format_args args) -> format_to_n_result< OutputIt >
Definition core.h:2927
FMT_CONSTEXPR auto parse_precision(const Char *begin, const Char *end, Handler &&handler) -> const Char *
Definition core.h:2237
auto runtime(const S &s) -> basic_runtime< char_t< S > >
Definition core.h:2866
FMT_API void vprint_mojibake(std::FILE *, string_view, format_args)
Definition core.h:2741
#define FMT_GCC_VERSION
Definition core.h:31
constexpr auto count() -> size_t
Definition core.h:1039
FMT_CONSTEXPR auto check_cstring_type_spec(Char spec, ErrorHandler &&eh={}) -> bool
Definition core.h:2573
FMT_INLINE void print(format_string< T... > fmt, T &&... args)
Definition core.h:2972
constexpr auto count_named_args() -> size_t
Definition core.h:1044
#define FMT_GCC_PRAGMA(arg)
Definition core.h:32
FMT_INLINE auto format(format_string< T... > fmt, T &&... args) -> std::string
Definition core.h:2885
@ has_named_args_bit
Definition core.h:1353
#define FMT_CONSTEXPR
Definition core.h:99
FMT_CONSTEXPR FMT_INLINE void parse_format_string(basic_string_view< Char > format_str, Handler &&handler)
Definition core.h:2382
constexpr auto to_ascii(Char value) -> Char
Definition core.h:2054
FMT_CONSTEXPR auto parse_width(const Char *begin, const Char *end, Handler &&handler) -> const Char *
Definition core.h:2203
type
Definition core.h:1048
@ int_type
@ custom_type
@ uint_type
@ uint128_type
@ string_type
@ bool_type
@ none_type
@ last_numeric_type
@ long_double_type
@ cstring_type
@ ulong_long_type
@ double_type
@ char_type
@ long_long_type
@ pointer_type
@ last_integer_type
@ int128_type
@ float_type
constexpr bool is_integral_type(type t)
Definition core.h:1095
@ is_unpacked_bit
Definition core.h:1352
arg_id_kind
Definition core.h:1921
FMT_CONSTEXPR void check_pointer_type_spec(Char spec, ErrorHandler &&eh)
Definition core.h:2586
float_format
Definition core.h:2510
FMT_NORETURN FMT_API void assert_fail(const char *file, int line, const char *message)
#define FMT_BEGIN_NAMESPACE
Definition core.h:235
conditional_t< long_short, int, long long > long_type
Definition core.h:1196
FMT_CONSTEXPR auto do_parse_arg_id(const Char *begin, const Char *end, IDHandler &&handler) -> const Char *
Definition core.h:2164
#define FMT_BEGIN_DETAIL_NAMESPACE
Definition core.h:244
constexpr auto const_check(T value) -> T
Definition core.h:361
@ packed_arg_bits
Definition core.h:1349
#define FMT_API
Definition core.h:264
FMT_INLINE void check_format_string(const S &)
Definition core.h:590
void vformat_to(buffer< Char > &buf, basic_string_view< Char > fmt, basic_format_args< FMT_BUFFER_CONTEXT(type_identity_t< Char >)> args, locale_ref loc={})
Definition format.h:2627
constexpr auto encode_types() -> unsigned long long
Definition core.h:1542
FMT_BEGIN_DETAIL_NAMESPACE auto get_container(std::back_insert_iterator< Container > it) -> Container &
Definition core.h:716
#define FMT_BUFFER_CONTEXT(Char)
Definition core.h:1641
constexpr auto is_utf8() -> bool
Definition core.h:420
conditional_t< std::is_same< T, char >::value, appender, std::back_insert_iterator< buffer< T > > > buffer_appender
Definition core.h:945
FMT_BEGIN_DETAIL_NAMESPACE void throw_format_error(const char *message)
Definition format.h:810
auto get_buffer(OutputIt out) -> iterator_buffer< OutputIt, T >
Definition core.h:949
#define FMT_ENABLE_IF(...)
Definition core.h:347
void void_t
Definition core.h:1501
#define FMT_CONSTEXPR_CHAR_TRAITS
Definition core.h:116
#define FMT_INLINE
Definition core.h:209
@ max_packed_args
Definition core.h:1351
auto get_iterator(Buffer &buf) -> decltype(buf.out())
Definition core.h:954
FMT_CONSTEXPR auto to_unsigned(Int value) -> typename std::make_unsigned< Int >::type
Definition core.h:412
auto convert_for_visit(T) -> monostate
Definition core.h:405
FMT_CONSTEXPR FMT_INLINE auto parse_arg_id(const Char *begin, const Char *end, IDHandler &&handler) -> const Char *
Definition core.h:2194
FMT_CONSTEXPR auto parse_nonnegative_int(const Char *&begin, const Char *end, int error_value) noexcept -> int
Definition core.h:2096
#define FMT_NORETURN
Definition core.h:166
#define FMT_MSC_WARNING(...)
Definition core.h:58
typename type_identity< T >::type type_identity_t
Definition core.h:330
FMT_BEGIN_DETAIL_NAMESPACE constexpr FMT_INLINE auto is_constant_evaluated() FMT_NOEXCEPT -> bool
Definition core.h:352
FMT_INLINE auto format_to(OutputIt out, format_string< T... > fmt, T &&... args) -> OutputIt
Definition core.h:2913
typename std::conditional< B, T, F >::type conditional_t
Definition core.h:323
FMT_CONSTEXPR void check_int_type_spec(char spec, ErrorHandler &&eh)
Definition core.h:2479
constexpr auto make_format_args(const Args &... args) -> format_arg_store< Context, Args... >
Definition core.h:1708
typename std::remove_cv< remove_reference_t< T > >::type remove_cvref_t
Definition core.h:328
constexpr int invalid_arg_index
Definition core.h:2640
#define FMT_USE_DOUBLE
Definition core.h:199
T
Definition core.h:320
@ long_short
Definition core.h:1195
#define FMT_END_NAMESPACE
Definition core.h:230
constexpr bool is_arithmetic_type(type t)
Definition core.h:1099
#define FMT_MODULE_EXPORT_END
Definition core.h:243
FMT_CONSTEXPR auto make_arg(const T &value) -> basic_format_arg< Context >
Definition core.h:1553
#define FMT_NOEXCEPT
Definition core.h:156
FMT_CONSTEXPR auto parse_float_type_spec(const basic_format_specs< Char > &specs, ErrorHandler &&eh={}) -> float_specs
Definition core.h:2529
int128_t
Definition core.h:402
uint128_t
Definition core.h:403
FMT_API auto vformat(string_view fmt, format_args args) -> std::string
auto find< false, char >(const char *first, const char *last, char value, const char *&out) -> bool
Definition core.h:2086
FMT_CONSTEXPR auto get_arg_index_by_name(basic_string_view< Char > name) -> int
Definition core.h:2658
FMT_CONSTEXPR auto parse_align(const Char *begin, const Char *end, Handler &&handler) -> const Char *
Definition core.h:2120
FMT_NOINLINE FMT_CONSTEXPR auto fill(OutputIt it, size_t n, const fill_t< Char > &fill) -> OutputIt
Definition format.h:1264
FMT_CONSTEXPR auto write(OutputIt out, Char value, const basic_format_specs< Char > &specs, locale_ref loc={}) -> OutputIt
Definition format.h:1338
T is_constant_evaluated(T... args)
T length(T... args)
T make_shared(T... args)
T memchr(T... args)
Definition core.h:1858
type
Definition core.h:1859
@ left
Definition core.h:1859
@ none
Definition core.h:1859
@ center
Definition core.h:1859
@ right
Definition core.h:1859
@ numeric
Definition core.h:1859
Definition args.h:19
Definition core.h:1862
type
Definition core.h:1863
@ plus
Definition core.h:1863
@ none
Definition core.h:1863
@ space
Definition core.h:1863
@ minus
Definition core.h:1863
T strlen(T... args)
FMT_CONSTEXPR FMT_INLINE auto named_args() -> std::nullptr_t
Definition core.h:1006
FMT_CONSTEXPR FMT_INLINE auto args() const -> const T *
Definition core.h:1005
FMT_CONSTEXPR FMT_INLINE arg_data(const U &... init)
Definition core.h:1004
T args_[1+(NUM_ARGS !=0 ? NUM_ARGS :+1)]
Definition core.h:988
arg_data(const arg_data &other)=delete
auto args() const -> const T *
Definition core.h:994
auto named_args() -> named_arg_info< Char > *
Definition core.h:995
named_arg_info< Char > named_args_[NUM_NAMED_ARGS]
Definition core.h:989
arg_data(const U &... init)
Definition core.h:992
FMT_CONSTEXPR FMT_INLINE auto map(float val) -> float
Definition core.h:1236
FMT_CONSTEXPR FMT_INLINE auto map(long double val) -> long double
Definition core.h:1238
FMT_CONSTEXPR FMT_INLINE auto map(int128_t val) -> int128_t
Definition core.h:1224
FMT_CONSTEXPR FMT_INLINE auto map(unsigned val) -> unsigned
Definition core.h:1214
typename Context::char_type char_type
Definition core.h:1203
auto map(...) -> unformattable
Definition core.h:1340
FMT_CONSTEXPR FMT_INLINE auto map(double val) -> double
Definition core.h:1237
FMT_CONSTEXPR FMT_INLINE auto map(unsigned long val) -> ulong_type
Definition core.h:1216
FMT_CONSTEXPR FMT_INLINE auto map(unsigned char *val) -> const char *
Definition core.h:1287
FMT_CONSTEXPR FMT_INLINE auto map(const char_type *val) -> const char_type *
Definition core.h:1245
FMT_CONSTEXPR FMT_INLINE auto map(int val) -> int
Definition core.h:1213
FMT_CONSTEXPR FMT_INLINE auto map(const unsigned char *val) -> const char *
Definition core.h:1279
FMT_CONSTEXPR FMT_INLINE auto map(long long val) -> long long
Definition core.h:1219
FMT_CONSTEXPR FMT_INLINE auto map(const T(&values)[N]) -> const T(&)[N]
Definition core.h:1313
FMT_CONSTEXPR FMT_INLINE auto map(char_type *val) -> const char_type *
Definition core.h:1242
FMT_CONSTEXPR FMT_INLINE auto map(signed char val) -> int
Definition core.h:1205
FMT_CONSTEXPR FMT_INLINE auto map(std::nullptr_t val) -> const void *
Definition core.h:1296
FMT_CONSTEXPR FMT_INLINE auto map(bool val) -> bool
Definition core.h:1226
FMT_CONSTEXPR FMT_INLINE auto map(const signed char *val) -> const char *
Definition core.h:1275
FMT_CONSTEXPR FMT_INLINE auto map(unsigned short val) -> unsigned
Definition core.h:1210
FMT_CONSTEXPR FMT_INLINE auto map(const T &val) -> basic_string_view< char_type >
Definition core.h:1249
FMT_CONSTEXPR FMT_INLINE auto map(const T &val) -> decltype(std::declval< arg_mapper >().map(static_cast< typename std::underlying_type< T >::type >(val)))
Definition core.h:1321
FMT_CONSTEXPR FMT_INLINE auto map(void *val) -> const void *
Definition core.h:1292
FMT_CONSTEXPR FMT_INLINE auto map(unsigned long long val) -> unsigned long long
Definition core.h:1220
FMT_CONSTEXPR FMT_INLINE auto map(long val) -> long_type
Definition core.h:1215
FMT_CONSTEXPR FMT_INLINE auto map(T val) -> char_type
Definition core.h:1229
FMT_CONSTEXPR FMT_INLINE auto map(short val) -> int
Definition core.h:1209
FMT_CONSTEXPR FMT_INLINE auto map(const T &val) -> const T &
Definition core.h:1330
FMT_CONSTEXPR FMT_INLINE auto map(const void *val) -> const void *
Definition core.h:1293
FMT_CONSTEXPR FMT_INLINE auto map(signed char *val) -> const char *
Definition core.h:1283
FMT_CONSTEXPR auto map(T) -> enable_if_t< std::is_pointer< T >::value, int >
Definition core.h:1303
FMT_CONSTEXPR FMT_INLINE auto map(unsigned char val) -> unsigned
Definition core.h:1206
FMT_CONSTEXPR FMT_INLINE auto map(uint128_t val) -> uint128_t
Definition core.h:1225
FMT_CONSTEXPR FMT_INLINE auto map(const T &named_arg) -> decltype(std::declval< arg_mapper >().map(named_arg.value))
Definition core.h:1335
FMT_CONSTEXPR arg_ref(basic_string_view< Char > name)
Definition core.h:1929
FMT_CONSTEXPR arg_ref()
Definition core.h:1925
FMT_CONSTEXPR auto operator=(int idx) -> arg_ref &
Definition core.h:1932
arg_id_kind kind
Definition core.h:1938
FMT_CONSTEXPR arg_ref(int index)
Definition core.h:1927
detail::fill_t< Char > fill
Definition core.h:1905
align_t align
Definition core.h:1901
constexpr basic_format_specs()
Definition core.h:1907
basic_string_view< Char > str
Definition core.h:2825
buffer_traits(size_t)
Definition core.h:835
auto limit(size_t size) -> size_t
Definition core.h:837
auto count() const -> size_t
Definition core.h:836
decltype(to_string_view(std::declval< S >())) result
Definition core.h:584
void(* format)(const void *arg, parse_context &parse_ctx, Context &ctx)
Definition core.h:1116
typename Context::parse_context_type parse_context
Definition core.h:1114
const void * value
Definition core.h:1115
Definition format.h:897
arg_ref< Char > precision_ref
Definition core.h:1954
arg_ref< Char > width_ref
Definition core.h:1953
constexpr error_handler()=default
FMT_NORETURN FMT_API void on_error(const char *message)
constexpr error_handler(const error_handler &)=default
fallback_formatter()=delete
FMT_CONSTEXPR void operator=(basic_string_view< Char > s)
Definition core.h:1879
FMT_CONSTEXPR auto operator[](size_t index) const -> const Char &
Definition core.h:1890
constexpr auto size() const -> size_t
Definition core.h:1886
constexpr auto data() const -> const Char *
Definition core.h:1887
FMT_CONSTEXPR auto operator[](size_t index) -> Char &
Definition core.h:1889
float_format format
Definition core.h:2519
int precision
Definition core.h:2518
bool upper
Definition core.h:2521
bool showpoint
Definition core.h:2525
sign_t sign
Definition core.h:2520
bool use_grisu
Definition core.h:2524
bool binary32
Definition core.h:2523
bool locale
Definition core.h:2522
OutputIt out
Definition core.h:2920
FMT_CONSTEXPR auto format(const T &val, FormatContext &ctx) const -> decltype(ctx.out())
formatter()=delete
constexpr monostate()
Definition core.h:333
const Char * name
Definition core.h:980
const named_arg_info< Char > * data
Definition core.h:1109
size_t size
Definition core.h:1110
const T & value
Definition core.h:975
const Char * name
Definition core.h:974
named_arg(const Char *n, const T &v)
Definition core.h:976
const Char * data
Definition core.h:1104
size_t size
Definition core.h:1105
Definition core.h:971
basic_string_view< Char > name
Definition core.h:1944
FMT_CONSTEXPR value(basic_string_view< Char > n)
Definition core.h:1941
FMT_CONSTEXPR value(int id=0)
Definition core.h:1940