core.h
Go to the documentation of this file.
1 // Formatting library for C++ - the core API
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 <functional>
14 #include <iterator>
15 #include <memory>
16 #include <string>
17 #include <type_traits>
18 #include <vector>
19 
20 // The fmt library version in the form major * 10000 + minor * 100 + patch.
21 #define FMT_VERSION 70003
22 
23 #ifdef __clang__
24 # define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
25 #else
26 # define FMT_CLANG_VERSION 0
27 #endif
28 
29 #if defined(__GNUC__) && !defined(__clang__)
30 # define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
31 #else
32 # define FMT_GCC_VERSION 0
33 #endif
34 
35 #if defined(__INTEL_COMPILER)
36 # define FMT_ICC_VERSION __INTEL_COMPILER
37 #else
38 # define FMT_ICC_VERSION 0
39 #endif
40 
41 #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
42 # define FMT_HAS_GXX_CXX11 FMT_GCC_VERSION
43 #else
44 # define FMT_HAS_GXX_CXX11 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_SUPPRESS_MSC_WARNING(n) __pragma(warning(suppress : n))
56 #else
57 # define FMT_MSC_VER 0
58 # define FMT_SUPPRESS_MSC_WARNING(n)
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) && !defined(__INTELLISENSE__) && \
68  (!FMT_ICC_VERSION || FMT_ICC_VERSION >= 1600)
69 # define FMT_HAS_INCLUDE(x) __has_include(x)
70 #else
71 # define FMT_HAS_INCLUDE(x) 0
72 #endif
73 
74 #ifdef __has_cpp_attribute
75 # define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
76 #else
77 # define FMT_HAS_CPP_ATTRIBUTE(x) 0
78 #endif
79 
80 #define FMT_HAS_CPP14_ATTRIBUTE(attribute) \
81  (__cplusplus >= 201402L && FMT_HAS_CPP_ATTRIBUTE(attribute))
82 
83 #define FMT_HAS_CPP17_ATTRIBUTE(attribute) \
84  (__cplusplus >= 201703L && FMT_HAS_CPP_ATTRIBUTE(attribute))
85 
86 // Check if relaxed C++14 constexpr is supported.
87 // GCC doesn't allow throw in constexpr until version 6 (bug 67371).
88 #ifndef FMT_USE_CONSTEXPR
89 # define FMT_USE_CONSTEXPR \
90  (FMT_HAS_FEATURE(cxx_relaxed_constexpr) || FMT_MSC_VER >= 1910 || \
91  (FMT_GCC_VERSION >= 600 && __cplusplus >= 201402L)) && \
92  !FMT_NVCC && !FMT_ICC_VERSION
93 #endif
94 #if FMT_USE_CONSTEXPR
95 # define FMT_CONSTEXPR constexpr
96 # define FMT_CONSTEXPR_DECL constexpr
97 #else
98 # define FMT_CONSTEXPR inline
99 # define FMT_CONSTEXPR_DECL
100 #endif
101 
102 #ifndef FMT_OVERRIDE
103 # if FMT_HAS_FEATURE(cxx_override_control) || \
104  (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900
105 # define FMT_OVERRIDE override
106 # else
107 # define FMT_OVERRIDE
108 # endif
109 #endif
110 
111 // Check if exceptions are disabled.
112 #ifndef FMT_EXCEPTIONS
113 # if (defined(__GNUC__) && !defined(__EXCEPTIONS)) || \
114  FMT_MSC_VER && !_HAS_EXCEPTIONS
115 # define FMT_EXCEPTIONS 0
116 # else
117 # define FMT_EXCEPTIONS 1
118 # endif
119 #endif
120 
121 // Define FMT_USE_NOEXCEPT to make fmt use noexcept (C++11 feature).
122 #ifndef FMT_USE_NOEXCEPT
123 # define FMT_USE_NOEXCEPT 0
124 #endif
125 
126 #if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \
127  (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900
128 # define FMT_DETECTED_NOEXCEPT noexcept
129 # define FMT_HAS_CXX11_NOEXCEPT 1
130 #else
131 # define FMT_DETECTED_NOEXCEPT throw()
132 # define FMT_HAS_CXX11_NOEXCEPT 0
133 #endif
134 
135 #ifndef FMT_NOEXCEPT
136 # if FMT_EXCEPTIONS || FMT_HAS_CXX11_NOEXCEPT
137 # define FMT_NOEXCEPT FMT_DETECTED_NOEXCEPT
138 # else
139 # define FMT_NOEXCEPT
140 # endif
141 #endif
142 
143 // [[noreturn]] is disabled on MSVC and NVCC because of bogus unreachable code
144 // warnings.
145 #if FMT_EXCEPTIONS && FMT_HAS_CPP_ATTRIBUTE(noreturn) && !FMT_MSC_VER && \
146  !FMT_NVCC
147 # define FMT_NORETURN [[noreturn]]
148 #else
149 # define FMT_NORETURN
150 #endif
151 
152 #ifndef FMT_DEPRECATED
153 # if FMT_HAS_CPP14_ATTRIBUTE(deprecated) || FMT_MSC_VER >= 1900
154 # define FMT_DEPRECATED [[deprecated]]
155 # else
156 # if (defined(__GNUC__) && !defined(__LCC__)) || defined(__clang__)
157 # define FMT_DEPRECATED __attribute__((deprecated))
158 # elif FMT_MSC_VER
159 # define FMT_DEPRECATED __declspec(deprecated)
160 # else
161 # define FMT_DEPRECATED /* deprecated */
162 # endif
163 # endif
164 #endif
165 
166 // Workaround broken [[deprecated]] in the Intel, PGI and NVCC compilers.
167 #if FMT_ICC_VERSION || defined(__PGI) || FMT_NVCC
168 # define FMT_DEPRECATED_ALIAS
169 #else
170 # define FMT_DEPRECATED_ALIAS FMT_DEPRECATED
171 #endif
172 
173 #ifndef FMT_INLINE
174 # if FMT_GCC_VERSION || FMT_CLANG_VERSION
175 # define FMT_INLINE inline __attribute__((always_inline))
176 # else
177 # define FMT_INLINE inline
178 # endif
179 #endif
180 
181 #ifndef FMT_BEGIN_NAMESPACE
182 # if FMT_HAS_FEATURE(cxx_inline_namespaces) || FMT_GCC_VERSION >= 404 || \
183  (FMT_MSC_VER >= 1900 && !_MANAGED)
184 # define FMT_INLINE_NAMESPACE inline namespace
185 # define FMT_END_NAMESPACE \
186  } \
187  }
188 # else
189 # define FMT_INLINE_NAMESPACE namespace
190 # define FMT_END_NAMESPACE \
191  } \
192  using namespace v7; \
193  }
194 # endif
195 # define FMT_BEGIN_NAMESPACE \
196  namespace fmt { \
197  FMT_INLINE_NAMESPACE v7 {
198 #endif
199 
200 #if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
201 # define FMT_CLASS_API FMT_SUPPRESS_MSC_WARNING(4275)
202 # ifdef FMT_EXPORT
203 # define FMT_API __declspec(dllexport)
204 # define FMT_EXTERN_TEMPLATE_API FMT_API
205 # define FMT_EXPORTED
206 # elif defined(FMT_SHARED)
207 # define FMT_API __declspec(dllimport)
208 # define FMT_EXTERN_TEMPLATE_API FMT_API
209 # endif
210 #else
211 # define FMT_CLASS_API
212 #endif
213 #ifndef FMT_API
214 # define FMT_API
215 #endif
216 #ifndef FMT_EXTERN_TEMPLATE_API
217 # define FMT_EXTERN_TEMPLATE_API
218 #endif
219 #ifndef FMT_INSTANTIATION_DEF_API
220 # define FMT_INSTANTIATION_DEF_API FMT_API
221 #endif
222 
223 #ifndef FMT_HEADER_ONLY
224 # define FMT_EXTERN extern
225 #else
226 # define FMT_EXTERN
227 #endif
228 
229 // libc++ supports string_view in pre-c++17.
230 #if (FMT_HAS_INCLUDE(<string_view>) && \
231  (__cplusplus > 201402L || defined(_LIBCPP_VERSION))) || \
232  (defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910)
233 # include <string_view>
234 # define FMT_USE_STRING_VIEW
235 #elif FMT_HAS_INCLUDE("experimental/string_view") && __cplusplus >= 201402L
236 # include <experimental/string_view>
237 # define FMT_USE_EXPERIMENTAL_STRING_VIEW
238 #endif
239 
240 #ifndef FMT_UNICODE
241 # define FMT_UNICODE !FMT_MSC_VER
242 #endif
243 #if FMT_UNICODE && FMT_MSC_VER
244 # pragma execution_character_set("utf-8")
245 #endif
246 
248 
249 // Implementations of enable_if_t and other metafunctions for older systems.
250 template <bool B, class T = void>
252 template <bool B, class T, class F>
254 template <bool B> using bool_constant = std::integral_constant<bool, B>;
255 template <typename T>
257 template <typename T>
259 template <typename T>
260 using remove_cvref_t = typename std::remove_cv<remove_reference_t<T>>::type;
261 template <typename T> struct type_identity { using type = T; };
262 template <typename T> using type_identity_t = typename type_identity<T>::type;
263 
264 struct monostate {};
265 
266 // An enable_if helper to be used in template parameters which results in much
267 // shorter symbols: https://godbolt.org/z/sWw4vP. Extra parentheses are needed
268 // to workaround a bug in MSVC 2019 (see #1140 and #1186).
269 #define FMT_ENABLE_IF(...) enable_if_t<(__VA_ARGS__), int> = 0
270 
271 namespace detail {
272 
273 // A helper function to suppress "conditional expression is constant" warnings.
274 template <typename T> constexpr T const_check(T value) { return value; }
275 
276 FMT_NORETURN FMT_API void assert_fail(const char* file, int line,
277  const char* message);
278 
279 #ifndef FMT_ASSERT
280 # ifdef NDEBUG
281 // FMT_ASSERT is not empty to avoid -Werror=empty-body.
282 # define FMT_ASSERT(condition, message) ((void)0)
283 # else
284 # define FMT_ASSERT(condition, message) \
285  ((condition) /* void() fails with -Winvalid-constexpr on clang 4.0.1 */ \
286  ? (void)0 \
287  : ::fmt::detail::assert_fail(__FILE__, __LINE__, (message)))
288 # endif
289 #endif
290 
291 #if defined(FMT_USE_STRING_VIEW)
292 template <typename Char> using std_string_view = std::basic_string_view<Char>;
293 #elif defined(FMT_USE_EXPERIMENTAL_STRING_VIEW)
294 template <typename Char>
295 using std_string_view = std::experimental::basic_string_view<Char>;
296 #else
297 template <typename T> struct std_string_view {};
298 #endif
299 
300 #ifdef FMT_USE_INT128
301 // Do nothing.
302 #elif defined(__SIZEOF_INT128__) && !FMT_NVCC && \
303  !(FMT_CLANG_VERSION && FMT_MSC_VER)
304 # define FMT_USE_INT128 1
305 using int128_t = __int128_t;
306 using uint128_t = __uint128_t;
307 #else
308 # define FMT_USE_INT128 0
309 #endif
310 #if !FMT_USE_INT128
311 struct int128_t {};
312 struct uint128_t {};
313 #endif
314 
315 // Casts a nonnegative integer to unsigned.
316 template <typename Int>
318  FMT_ASSERT(value >= 0, "negative value");
319  return static_cast<typename std::make_unsigned<Int>::type>(value);
320 }
321 
322 FMT_SUPPRESS_MSC_WARNING(4566) constexpr unsigned char micro[] = "\u00B5";
323 
324 template <typename Char> constexpr bool is_unicode() {
325  return FMT_UNICODE || sizeof(Char) != 1 ||
326  (sizeof(micro) == 3 && micro[0] == 0xC2 && micro[1] == 0xB5);
327 }
328 
329 #ifdef __cpp_char8_t
330 using char8_type = char8_t;
331 #else
332 enum char8_type : unsigned char {};
333 #endif
334 } // namespace detail
335 
336 #ifdef FMT_USE_INTERNAL
337 namespace internal = detail; // DEPRECATED
338 #endif
339 
347 template <typename Char> class basic_string_view {
348  private:
349  const Char* data_;
350  size_t size_;
351 
352  public:
353  using value_type = Char;
354  using iterator = const Char*;
355 
356  constexpr basic_string_view() FMT_NOEXCEPT : data_(nullptr), size_(0) {}
357 
359  constexpr basic_string_view(const Char* s, size_t count) FMT_NOEXCEPT
360  : data_(s),
361  size_(count) {}
362 
369 #if __cplusplus >= 201703L // C++17's char_traits::length() is constexpr.
371 #endif
372  basic_string_view(const Char* s)
373  : data_(s), size_(std::char_traits<Char>::length(s)) {}
374 
376  template <typename Traits, typename Alloc>
378  const std::basic_string<Char, Traits, Alloc>& s) FMT_NOEXCEPT
379  : data_(s.data()),
380  size_(s.size()) {}
381 
382  template <typename S, FMT_ENABLE_IF(std::is_same<
385  size_(s.size()) {}
386 
388  constexpr const Char* data() const { return data_; }
389 
391  constexpr size_t size() const { return size_; }
392 
393  constexpr iterator begin() const { return data_; }
394  constexpr iterator end() const { return data_ + size_; }
395 
396  constexpr const Char& operator[](size_t pos) const { return data_[pos]; }
397 
398  FMT_CONSTEXPR void remove_prefix(size_t n) {
399  data_ += n;
400  size_ -= n;
401  }
402 
403  // Lexicographically compare this string reference to other.
404  int compare(basic_string_view other) const {
405  size_t str_size = size_ < other.size_ ? size_ : other.size_;
406  int result = std::char_traits<Char>::compare(data_, other.data_, str_size);
407  if (result == 0)
408  result = size_ == other.size_ ? 0 : (size_ < other.size_ ? -1 : 1);
409  return result;
410  }
411 
413  return lhs.compare(rhs) == 0;
414  }
416  return lhs.compare(rhs) != 0;
417  }
419  return lhs.compare(rhs) < 0;
420  }
422  return lhs.compare(rhs) <= 0;
423  }
425  return lhs.compare(rhs) > 0;
426  }
428  return lhs.compare(rhs) >= 0;
429  }
430 };
431 
434 
436 template <typename T> struct is_char : std::false_type {};
437 template <> struct is_char<char> : std::true_type {};
438 template <> struct is_char<wchar_t> : std::true_type {};
439 template <> struct is_char<detail::char8_type> : std::true_type {};
440 template <> struct is_char<char16_t> : std::true_type {};
441 template <> struct is_char<char32_t> : std::true_type {};
442 
461  return s;
462 }
463 
464 template <typename Char, typename Traits, typename Alloc>
466  const std::basic_string<Char, Traits, Alloc>& s) {
467  return s;
468 }
469 
470 template <typename Char>
472  return s;
473 }
474 
475 template <typename Char,
478  return s;
479 }
480 
481 // A base class for compile-time strings. It is defined in the fmt namespace to
482 // make formatting functions visible via ADL, e.g. format(FMT_STRING("{}"), 42).
483 struct compile_string {};
484 
485 template <typename S>
486 struct is_compile_string : std::is_base_of<compile_string, S> {};
487 
490  return s;
491 }
492 
493 namespace detail {
494 void to_string_view(...);
496 
497 // Specifies whether S is a string type convertible to fmt::basic_string_view.
498 // It should be a constexpr function but MSVC 2017 fails to compile it in
499 // enable_if and MSVC 2015 fails to compile it as an alias template.
500 template <typename S>
501 struct is_string : std::is_class<decltype(to_string_view(std::declval<S>()))> {
502 };
503 
504 template <typename S, typename = void> struct char_t_impl {};
505 template <typename S> struct char_t_impl<S, enable_if_t<is_string<S>::value>> {
506  using result = decltype(to_string_view(std::declval<S>()));
507  using type = typename result::value_type;
508 };
509 
510 // Reports a compile-time error if S is not a valid format string.
511 template <typename..., typename S, FMT_ENABLE_IF(!is_compile_string<S>::value)>
513 #ifdef FMT_ENFORCE_COMPILE_STRING
514  static_assert(is_compile_string<S>::value,
515  "FMT_ENFORCE_COMPILE_STRING requires all format strings to use "
516  "FMT_STRING.");
517 #endif
518 }
519 template <typename..., typename S, FMT_ENABLE_IF(is_compile_string<S>::value)>
520 void check_format_string(S);
521 
523  constexpr error_handler() = default;
524  constexpr error_handler(const error_handler&) = default;
525 
526  // This function is intentionally not constexpr to give a compile-time error.
527  FMT_NORETURN FMT_API void on_error(const char* message);
528 };
529 } // namespace detail
530 
532 template <typename S> using char_t = typename detail::char_t_impl<S>::type;
533 
550 template <typename Char, typename ErrorHandler = detail::error_handler>
551 class basic_format_parse_context : private ErrorHandler {
552  private:
555 
556  public:
557  using char_type = Char;
559 
560  explicit constexpr basic_format_parse_context(
561  basic_string_view<Char> format_str, ErrorHandler eh = {},
562  int next_arg_id = 0)
563  : ErrorHandler(eh), format_str_(format_str), next_arg_id_(next_arg_id) {}
564 
569  constexpr iterator begin() const FMT_NOEXCEPT { return format_str_.begin(); }
570 
574  constexpr iterator end() const FMT_NOEXCEPT { return format_str_.end(); }
575 
578  format_str_.remove_prefix(detail::to_unsigned(it - begin()));
579  }
580 
586  // Don't check if the argument id is valid to avoid overhead and because it
587  // will be checked during formatting anyway.
588  if (next_arg_id_ >= 0) return next_arg_id_++;
589  on_error("cannot switch from manual to automatic argument indexing");
590  return 0;
591  }
592 
598  if (next_arg_id_ > 0)
599  on_error("cannot switch from automatic to manual argument indexing");
600  else
601  next_arg_id_ = -1;
602  }
603 
605 
606  FMT_CONSTEXPR void on_error(const char* message) {
607  ErrorHandler::on_error(message);
608  }
609 
610  constexpr ErrorHandler error_handler() const { return *this; }
611 };
612 
615 
616 template <typename Context> class basic_format_arg;
617 template <typename Context> class basic_format_args;
618 template <typename Context> class dynamic_format_arg_store;
619 
620 // A formatter for objects of type T.
621 template <typename T, typename Char = char, typename Enable = void>
622 struct formatter {
623  // A deleted default constructor indicates a disabled formatter.
624  formatter() = delete;
625 };
626 
627 // Specifies if T has an enabled formatter specialization. A type can be
628 // formattable even if it doesn't have a formatter e.g. via a conversion.
629 template <typename T, typename Context>
630 using has_formatter =
631  std::is_constructible<typename Context::template formatter_type<T>>;
632 
633 // Checks whether T is a container with contiguous storage.
634 template <typename T> struct is_contiguous : std::false_type {};
635 template <typename Char>
636 struct is_contiguous<std::basic_string<Char>> : std::true_type {};
637 
638 namespace detail {
639 
640 // Extracts a reference to the container from back_insert_iterator.
641 template <typename Container>
642 inline Container& get_container(std::back_insert_iterator<Container> it) {
643  using bi_iterator = std::back_insert_iterator<Container>;
644  struct accessor : bi_iterator {
645  accessor(bi_iterator iter) : bi_iterator(iter) {}
646  using bi_iterator::container;
647  };
648  return *accessor(it).container;
649 }
650 
657 template <typename T> class buffer {
658  private:
659  T* ptr_;
660  size_t size_;
661  size_t capacity_;
662 
663  protected:
664  // Don't initialize ptr_ since it is not accessed to save a few cycles.
666  buffer(size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz) {}
667 
668  buffer(T* p = nullptr, size_t sz = 0, size_t cap = 0) FMT_NOEXCEPT
669  : ptr_(p),
670  size_(sz),
671  capacity_(cap) {}
672 
673  ~buffer() = default;
674 
676  void set(T* buf_data, size_t buf_capacity) FMT_NOEXCEPT {
677  ptr_ = buf_data;
678  capacity_ = buf_capacity;
679  }
680 
682  virtual void grow(size_t capacity) = 0;
683 
684  public:
685  using value_type = T;
686  using const_reference = const T&;
687 
688  buffer(const buffer&) = delete;
689  void operator=(const buffer&) = delete;
690 
691  T* begin() FMT_NOEXCEPT { return ptr_; }
692  T* end() FMT_NOEXCEPT { return ptr_ + size_; }
693 
694  const T* begin() const FMT_NOEXCEPT { return ptr_; }
695  const T* end() const FMT_NOEXCEPT { return ptr_ + size_; }
696 
698  size_t size() const FMT_NOEXCEPT { return size_; }
699 
701  size_t capacity() const FMT_NOEXCEPT { return capacity_; }
702 
704  T* data() FMT_NOEXCEPT { return ptr_; }
705 
707  const T* data() const FMT_NOEXCEPT { return ptr_; }
708 
710  void clear() { size_ = 0; }
711 
712  // Tries resizing the buffer to contain *count* elements. If T is a POD type
713  // the new elements may not be initialized.
714  void try_resize(size_t count) {
715  try_reserve(count);
716  size_ = count <= capacity_ ? count : capacity_;
717  }
718 
719  // Tries increasing the buffer capacity to *new_capacity*. It can increase the
720  // capacity by a smaller amount than requested but guarantees there is space
721  // for at least one additional element either by increasing the capacity or by
722  // flushing the buffer if it is full.
723  void try_reserve(size_t new_capacity) {
724  if (new_capacity > capacity_) grow(new_capacity);
725  }
726 
727  void push_back(const T& value) {
728  try_reserve(size_ + 1);
729  ptr_[size_++] = value;
730  }
731 
733  template <typename U> void append(const U* begin, const U* end);
734 
735  template <typename I> T& operator[](I index) { return ptr_[index]; }
736  template <typename I> const T& operator[](I index) const {
737  return ptr_[index];
738  }
739 };
740 
742  explicit buffer_traits(size_t) {}
743  size_t count() const { return 0; }
744  size_t limit(size_t size) { return size; }
745 };
746 
748  private:
749  size_t count_ = 0;
750  size_t limit_;
751 
752  public:
753  explicit fixed_buffer_traits(size_t limit) : limit_(limit) {}
754  size_t count() const { return count_; }
755  size_t limit(size_t size) {
756  size_t n = limit_ - count_;
757  count_ += size;
758  return size < n ? size : n;
759  }
760 };
761 
762 // A buffer that writes to an output iterator when flushed.
763 template <typename OutputIt, typename T, typename Traits = buffer_traits>
764 class iterator_buffer final : public Traits, public buffer<T> {
765  private:
766  OutputIt out_;
767  enum { buffer_size = 256 };
768  T data_[buffer_size];
769 
770  protected:
771  void grow(size_t) final FMT_OVERRIDE {
772  if (this->size() == buffer_size) flush();
773  }
774  void flush();
775 
776  public:
777  explicit iterator_buffer(OutputIt out, size_t n = buffer_size)
778  : Traits(n),
779  buffer<T>(data_, 0, n < size_t(buffer_size) ? n : size_t(buffer_size)),
780  out_(out) {}
781  ~iterator_buffer() { flush(); }
782 
783  OutputIt out() {
784  flush();
785  return out_;
786  }
787  size_t count() const { return Traits::count() + this->size(); }
788 };
789 
790 template <typename T> class iterator_buffer<T*, T> final : public buffer<T> {
791  protected:
792  void grow(size_t) final FMT_OVERRIDE {}
793 
794  public:
795  explicit iterator_buffer(T* out, size_t = 0) : buffer<T>(out, 0, ~size_t()) {}
796 
797  T* out() { return &*this->end(); }
798 };
799 
800 // A buffer that writes to a container with the contiguous storage.
801 template <typename Container>
802 class iterator_buffer<std::back_insert_iterator<Container>,
803  enable_if_t<is_contiguous<Container>::value,
804  typename Container::value_type>> final
805  : public buffer<typename Container::value_type> {
806  private:
807  Container& container_;
808 
809  protected:
810  void grow(size_t capacity) final FMT_OVERRIDE {
811  container_.resize(capacity);
812  this->set(&container_[0], capacity);
813  }
814 
815  public:
816  explicit iterator_buffer(Container& c)
817  : buffer<typename Container::value_type>(c.size()), container_(c) {}
818  explicit iterator_buffer(std::back_insert_iterator<Container> out, size_t = 0)
819  : iterator_buffer(get_container(out)) {}
820  std::back_insert_iterator<Container> out() {
821  return std::back_inserter(container_);
822  }
823 };
824 
825 // A buffer that counts the number of code units written discarding the output.
826 template <typename T = char> class counting_buffer final : public buffer<T> {
827  private:
828  enum { buffer_size = 256 };
829  T data_[buffer_size];
830  size_t count_ = 0;
831 
832  protected:
833  void grow(size_t) final FMT_OVERRIDE {
834  if (this->size() != buffer_size) return;
835  count_ += this->size();
836  this->clear();
837  }
838 
839  public:
840  counting_buffer() : buffer<T>(data_, 0, buffer_size) {}
841 
842  size_t count() { return count_ + this->size(); }
843 };
844 
845 // An output iterator that appends to the buffer.
846 // It is used to reduce symbol sizes for the common case.
847 template <typename T>
848 class buffer_appender : public std::back_insert_iterator<buffer<T>> {
849  using base = std::back_insert_iterator<buffer<T>>;
850 
851  public:
852  explicit buffer_appender(buffer<T>& buf) : base(buf) {}
853  buffer_appender(base it) : base(it) {}
854 
856  base::operator++();
857  return *this;
858  }
859 
861  buffer_appender tmp = *this;
862  ++*this;
863  return tmp;
864  }
865 };
866 
867 // Maps an output iterator into a buffer.
868 template <typename T, typename OutputIt>
870 template <typename T> buffer<T>& get_buffer(buffer_appender<T>);
871 
872 template <typename OutputIt> OutputIt get_buffer_init(OutputIt out) {
873  return out;
874 }
875 template <typename T> buffer<T>& get_buffer_init(buffer_appender<T> out) {
876  return get_container(out);
877 }
878 
879 template <typename Buffer>
880 auto get_iterator(Buffer& buf) -> decltype(buf.out()) {
881  return buf.out();
882 }
883 template <typename T> buffer_appender<T> get_iterator(buffer<T>& buf) {
884  return buffer_appender<T>(buf);
885 }
886 
887 template <typename T, typename Char = char, typename Enable = void>
889  fallback_formatter() = delete;
890 };
891 
892 // Specifies if T has an enabled fallback_formatter specialization.
893 template <typename T, typename Context>
895  std::is_constructible<fallback_formatter<T, typename Context::char_type>>;
896 
897 struct view {};
898 
899 template <typename Char, typename T> struct named_arg : view {
900  const Char* name;
901  const T& value;
902  named_arg(const Char* n, const T& v) : name(n), value(v) {}
903 };
904 
905 template <typename Char> struct named_arg_info {
906  const Char* name;
907  int id;
908 };
909 
910 template <typename T, typename Char, size_t NUM_ARGS, size_t NUM_NAMED_ARGS>
911 struct arg_data {
912  // args_[0].named_args points to named_args_ to avoid bloating format_args.
913  // +1 to workaround a bug in gcc 7.5 that causes duplicated-branches warning.
914  T args_[1 + (NUM_ARGS != 0 ? NUM_ARGS : +1)];
915  named_arg_info<Char> named_args_[NUM_NAMED_ARGS];
916 
917  template <typename... U>
918  arg_data(const U&... init) : args_{T(named_args_, NUM_NAMED_ARGS), init...} {}
919  arg_data(const arg_data& other) = delete;
920  const T* args() const { return args_ + 1; }
921  named_arg_info<Char>* named_args() { return named_args_; }
922 };
923 
924 template <typename T, typename Char, size_t NUM_ARGS>
925 struct arg_data<T, Char, NUM_ARGS, 0> {
926  // +1 to workaround a bug in gcc 7.5 that causes duplicated-branches warning.
927  T args_[NUM_ARGS != 0 ? NUM_ARGS : +1];
928 
929  template <typename... U>
930  FMT_INLINE arg_data(const U&... init) : args_{init...} {}
931  FMT_INLINE const T* args() const { return args_; }
932  FMT_INLINE std::nullptr_t named_args() { return nullptr; }
933 };
934 
935 template <typename Char>
936 inline void init_named_args(named_arg_info<Char>*, int, int) {}
937 
938 template <typename Char, typename T, typename... Tail>
939 void init_named_args(named_arg_info<Char>* named_args, int arg_count,
940  int named_arg_count, const T&, const Tail&... args) {
941  init_named_args(named_args, arg_count + 1, named_arg_count, args...);
942 }
943 
944 template <typename Char, typename T, typename... Tail>
945 void init_named_args(named_arg_info<Char>* named_args, int arg_count,
946  int named_arg_count, const named_arg<Char, T>& arg,
947  const Tail&... args) {
948  named_args[named_arg_count++] = {arg.name, arg_count};
949  init_named_args(named_args, arg_count + 1, named_arg_count, args...);
950 }
951 
952 template <typename... Args>
953 FMT_INLINE void init_named_args(std::nullptr_t, int, int, const Args&...) {}
954 
955 template <typename T> struct is_named_arg : std::false_type {};
956 
957 template <typename T, typename Char>
958 struct is_named_arg<named_arg<Char, T>> : std::true_type {};
959 
960 template <bool B = false> constexpr size_t count() { return B ? 1 : 0; }
961 template <bool B1, bool B2, bool... Tail> constexpr size_t count() {
962  return (B1 ? 1 : 0) + count<B2, Tail...>();
963 }
964 
965 template <typename... Args> constexpr size_t count_named_args() {
966  return count<is_named_arg<Args>::value...>();
967 }
968 
969 enum class type {
970  none_type,
971  // Integer types should go first,
972  int_type,
973  uint_type,
976  int128_type,
977  uint128_type,
978  bool_type,
979  char_type,
980  last_integer_type = char_type,
981  // followed by floating-point types.
982  float_type,
983  double_type,
985  last_numeric_type = long_double_type,
986  cstring_type,
987  string_type,
988  pointer_type,
990 };
991 
992 // Maps core type T to the corresponding type enum constant.
993 template <typename T, typename Char>
994 struct type_constant : std::integral_constant<type, type::custom_type> {};
995 
996 #define FMT_TYPE_CONSTANT(Type, constant) \
997  template <typename Char> \
998  struct type_constant<Type, Char> \
999  : std::integral_constant<type, type::constant> {}
1000 
1001 FMT_TYPE_CONSTANT(int, int_type);
1002 FMT_TYPE_CONSTANT(unsigned, uint_type);
1003 FMT_TYPE_CONSTANT(long long, long_long_type);
1004 FMT_TYPE_CONSTANT(unsigned long long, ulong_long_type);
1005 FMT_TYPE_CONSTANT(int128_t, int128_type);
1006 FMT_TYPE_CONSTANT(uint128_t, uint128_type);
1007 FMT_TYPE_CONSTANT(bool, bool_type);
1008 FMT_TYPE_CONSTANT(Char, char_type);
1009 FMT_TYPE_CONSTANT(float, float_type);
1010 FMT_TYPE_CONSTANT(double, double_type);
1011 FMT_TYPE_CONSTANT(long double, long_double_type);
1012 FMT_TYPE_CONSTANT(const Char*, cstring_type);
1014 FMT_TYPE_CONSTANT(const void*, pointer_type);
1015 
1016 constexpr bool is_integral_type(type t) {
1017  return t > type::none_type && t <= type::last_integer_type;
1018 }
1019 
1020 constexpr bool is_arithmetic_type(type t) {
1021  return t > type::none_type && t <= type::last_numeric_type;
1022 }
1023 
1024 template <typename Char> struct string_value {
1025  const Char* data;
1026  size_t size;
1027 };
1028 
1029 template <typename Char> struct named_arg_value {
1031  size_t size;
1032 };
1033 
1034 template <typename Context> struct custom_value {
1035  using parse_context = typename Context::parse_context_type;
1036  const void* value;
1037  void (*format)(const void* arg, parse_context& parse_ctx, Context& ctx);
1038 };
1039 
1040 // A formatting argument value.
1041 template <typename Context> class value {
1042  public:
1043  using char_type = typename Context::char_type;
1044 
1045  union {
1047  unsigned uint_value;
1048  long long long_long_value;
1049  unsigned long long ulong_long_value;
1056  long double long_double_value;
1057  const void* pointer;
1061  };
1062 
1063  constexpr FMT_INLINE value(int val = 0) : int_value(val) {}
1064  constexpr FMT_INLINE value(unsigned val) : uint_value(val) {}
1065  FMT_INLINE value(long long val) : long_long_value(val) {}
1066  FMT_INLINE value(unsigned long long val) : ulong_long_value(val) {}
1067  FMT_INLINE value(int128_t val) : int128_value(val) {}
1068  FMT_INLINE value(uint128_t val) : uint128_value(val) {}
1069  FMT_INLINE value(float val) : float_value(val) {}
1070  FMT_INLINE value(double val) : double_value(val) {}
1071  FMT_INLINE value(long double val) : long_double_value(val) {}
1072  FMT_INLINE value(bool val) : bool_value(val) {}
1073  FMT_INLINE value(char_type val) : char_value(val) {}
1074  FMT_INLINE value(const char_type* val) { string.data = val; }
1076  string.data = val.data();
1077  string.size = val.size();
1078  }
1079  FMT_INLINE value(const void* val) : pointer(val) {}
1080  FMT_INLINE value(const named_arg_info<char_type>* args, size_t size)
1081  : named_args{args, size} {}
1082 
1083  template <typename T> FMT_INLINE value(const T& val) {
1084  custom.value = &val;
1085  // Get the formatter type through the context to allow different contexts
1086  // have different extension points, e.g. `formatter<T>` for `format` and
1087  // `printf_formatter<T>` for `printf`.
1088  custom.format = format_custom_arg<
1090  typename Context::template formatter_type<T>,
1092  }
1093 
1094  private:
1095  // Formats an argument of a custom type, such as a user-defined class.
1096  template <typename T, typename Formatter>
1097  static void format_custom_arg(const void* arg,
1098  typename Context::parse_context_type& parse_ctx,
1099  Context& ctx) {
1100  Formatter f;
1101  parse_ctx.advance_to(f.parse(parse_ctx));
1102  ctx.advance_to(f.format(*static_cast<const T*>(arg), ctx));
1103  }
1104 };
1105 
1106 template <typename Context, typename T>
1108 
1109 // To minimize the number of types we need to deal with, long is translated
1110 // either to int or to long long depending on its size.
1111 enum { long_short = sizeof(long) == sizeof(int) };
1114 
1115 struct unformattable {};
1116 
1117 // Maps formatting arguments to core types.
1118 template <typename Context> struct arg_mapper {
1119  using char_type = typename Context::char_type;
1120 
1121  FMT_CONSTEXPR int map(signed char val) { return val; }
1122  FMT_CONSTEXPR unsigned map(unsigned char val) { return val; }
1123  FMT_CONSTEXPR int map(short val) { return val; }
1124  FMT_CONSTEXPR unsigned map(unsigned short val) { return val; }
1125  FMT_CONSTEXPR int map(int val) { return val; }
1126  FMT_CONSTEXPR unsigned map(unsigned val) { return val; }
1127  FMT_CONSTEXPR long_type map(long val) { return val; }
1128  FMT_CONSTEXPR ulong_type map(unsigned long val) { return val; }
1129  FMT_CONSTEXPR long long map(long long val) { return val; }
1130  FMT_CONSTEXPR unsigned long long map(unsigned long long val) { return val; }
1131  FMT_CONSTEXPR int128_t map(int128_t val) { return val; }
1132  FMT_CONSTEXPR uint128_t map(uint128_t val) { return val; }
1133  FMT_CONSTEXPR bool map(bool val) { return val; }
1134 
1137  static_assert(
1139  "mixing character types is disallowed");
1140  return val;
1141  }
1142 
1143  FMT_CONSTEXPR float map(float val) { return val; }
1144  FMT_CONSTEXPR double map(double val) { return val; }
1145  FMT_CONSTEXPR long double map(long double val) { return val; }
1146 
1147  FMT_CONSTEXPR const char_type* map(char_type* val) { return val; }
1148  FMT_CONSTEXPR const char_type* map(const char_type* val) { return val; }
1151  static_assert(std::is_same<char_type, char_t<T>>::value,
1152  "mixing character types is disallowed");
1153  return to_string_view(val);
1154  }
1155  template <typename T,
1156  FMT_ENABLE_IF(
1157  std::is_constructible<basic_string_view<char_type>, T>::value &&
1161  return basic_string_view<char_type>(val);
1162  }
1163  template <
1164  typename T,
1165  FMT_ENABLE_IF(
1166  std::is_constructible<std_string_view<char_type>, T>::value &&
1167  !std::is_constructible<basic_string_view<char_type>, T>::value &&
1171  return std_string_view<char_type>(val);
1172  }
1173  FMT_CONSTEXPR const char* map(const signed char* val) {
1174  static_assert(std::is_same<char_type, char>::value, "invalid string type");
1175  return reinterpret_cast<const char*>(val);
1176  }
1177  FMT_CONSTEXPR const char* map(const unsigned char* val) {
1178  static_assert(std::is_same<char_type, char>::value, "invalid string type");
1179  return reinterpret_cast<const char*>(val);
1180  }
1181  FMT_CONSTEXPR const char* map(signed char* val) {
1182  const auto* const_val = val;
1183  return map(const_val);
1184  }
1185  FMT_CONSTEXPR const char* map(unsigned char* val) {
1186  const auto* const_val = val;
1187  return map(const_val);
1188  }
1189 
1190  FMT_CONSTEXPR const void* map(void* val) { return val; }
1191  FMT_CONSTEXPR const void* map(const void* val) { return val; }
1192  FMT_CONSTEXPR const void* map(std::nullptr_t val) { return val; }
1193  template <typename T> FMT_CONSTEXPR int map(const T*) {
1194  // Formatting of arbitrary pointers is disallowed. If you want to output
1195  // a pointer cast it to "void *" or "const void *". In particular, this
1196  // forbids formatting of "[const] volatile char *" which is printed as bool
1197  // by iostreams.
1198  static_assert(!sizeof(T), "formatting of non-void pointers is disallowed");
1199  return 0;
1200  }
1201 
1202  template <typename T,
1206  FMT_CONSTEXPR auto map(const T& val)
1207  -> decltype(std::declval<arg_mapper>().map(
1208  static_cast<typename std::underlying_type<T>::type>(val))) {
1209  return map(static_cast<typename std::underlying_type<T>::type>(val));
1210  }
1211  template <typename T,
1215  FMT_CONSTEXPR const T& map(const T& val) {
1216  return val;
1217  }
1218 
1219  template <typename T>
1221  -> decltype(std::declval<arg_mapper>().map(val.value)) {
1222  return map(val.value);
1223  }
1224 
1225  unformattable map(...) { return {}; }
1226 };
1227 
1228 // A type constant after applying arg_mapper<Context>.
1229 template <typename T, typename Context>
1230 using mapped_type_constant =
1231  type_constant<decltype(arg_mapper<Context>().map(std::declval<const T&>())),
1232  typename Context::char_type>;
1233 
1234 enum { packed_arg_bits = 4 };
1235 // Maximum number of arguments with packed types.
1237 enum : unsigned long long { is_unpacked_bit = 1ULL << 63 };
1238 enum : unsigned long long { has_named_args_bit = 1ULL << 62 };
1239 } // namespace detail
1240 
1241 // A formatting argument. It is a trivially copyable/constructible type to
1242 // allow storage in basic_memory_buffer.
1243 template <typename Context> class basic_format_arg {
1244  private:
1247 
1248  template <typename ContextType, typename T>
1250  const T& value);
1251 
1252  template <typename Visitor, typename Ctx>
1253  friend FMT_CONSTEXPR auto visit_format_arg(Visitor&& vis,
1254  const basic_format_arg<Ctx>& arg)
1255  -> decltype(vis(0));
1256 
1257  friend class basic_format_args<Context>;
1258  friend class dynamic_format_arg_store<Context>;
1259 
1260  using char_type = typename Context::char_type;
1261 
1262  template <typename T, typename Char, size_t NUM_ARGS, size_t NUM_NAMED_ARGS>
1263  friend struct detail::arg_data;
1264 
1266  : value_(args, size) {}
1267 
1268  public:
1269  class handle {
1270  public:
1271  explicit handle(detail::custom_value<Context> custom) : custom_(custom) {}
1272 
1273  void format(typename Context::parse_context_type& parse_ctx,
1274  Context& ctx) const {
1275  custom_.format(custom_.value, parse_ctx, ctx);
1276  }
1277 
1278  private:
1280  };
1281 
1282  constexpr basic_format_arg() : type_(detail::type::none_type) {}
1283 
1284  constexpr explicit operator bool() const FMT_NOEXCEPT {
1285  return type_ != detail::type::none_type;
1286  }
1287 
1288  detail::type type() const { return type_; }
1289 
1290  bool is_integral() const { return detail::is_integral_type(type_); }
1291  bool is_arithmetic() const { return detail::is_arithmetic_type(type_); }
1292 };
1293 
1301 template <typename Visitor, typename Context>
1303  Visitor&& vis, const basic_format_arg<Context>& arg) -> decltype(vis(0)) {
1304  using char_type = typename Context::char_type;
1305  switch (arg.type_) {
1307  break;
1309  return vis(arg.value_.int_value);
1311  return vis(arg.value_.uint_value);
1313  return vis(arg.value_.long_long_value);
1315  return vis(arg.value_.ulong_long_value);
1316 #if FMT_USE_INT128
1318  return vis(arg.value_.int128_value);
1320  return vis(arg.value_.uint128_value);
1321 #else
1324  break;
1325 #endif
1327  return vis(arg.value_.bool_value);
1329  return vis(arg.value_.char_value);
1331  return vis(arg.value_.float_value);
1333  return vis(arg.value_.double_value);
1335  return vis(arg.value_.long_double_value);
1337  return vis(arg.value_.string.data);
1339  return vis(basic_string_view<char_type>(arg.value_.string.data,
1340  arg.value_.string.size));
1342  return vis(arg.value_.pointer);
1344  return vis(typename basic_format_arg<Context>::handle(arg.value_.custom));
1345  }
1346  return vis(monostate());
1347 }
1348 
1349 template <typename T> struct formattable : std::false_type {};
1350 
1351 namespace detail {
1352 
1353 // A workaround for gcc 4.8 to make void_t work in a SFINAE context.
1354 template <typename... Ts> struct void_t_impl { using type = void; };
1355 
1356 template <typename... Ts>
1357 using void_t = typename detail::void_t_impl<Ts...>::type;
1358 
1359 // Detect the iterator category of *any* given type in a SFINAE-friendly way.
1360 // Unfortunately, older implementations of std::iterator_traits are not safe
1361 // for use in a SFINAE-context.
1362 template <typename It, typename Enable = void>
1363 struct iterator_category : std::false_type {};
1364 
1365 template <typename T> struct iterator_category<T*> {
1366  using type = std::random_access_iterator_tag;
1367 };
1368 
1369 template <typename It>
1370 struct iterator_category<It, void_t<typename It::iterator_category>> {
1371  using type = typename It::iterator_category;
1372 };
1373 
1374 // Detect if *any* given type models the OutputIterator concept.
1375 template <typename It> class is_output_iterator {
1376  // Check for mutability because all iterator categories derived from
1377  // std::input_iterator_tag *may* also meet the requirements of an
1378  // OutputIterator, thereby falling into the category of 'mutable iterators'
1379  // [iterator.requirements.general] clause 4. The compiler reveals this
1380  // property only at the point of *actually dereferencing* the iterator!
1381  template <typename U>
1382  static decltype(*(std::declval<U>())) test(std::input_iterator_tag);
1383  template <typename U> static char& test(std::output_iterator_tag);
1384  template <typename U> static const char& test(...);
1385 
1386  using type = decltype(test<It>(typename iterator_category<It>::type{}));
1387 
1388  public:
1389  enum { value = !std::is_const<remove_reference_t<type>>::value };
1390 };
1391 
1392 template <typename OutputIt>
1393 struct is_back_insert_iterator : std::false_type {};
1394 template <typename Container>
1395 struct is_back_insert_iterator<std::back_insert_iterator<Container>>
1396  : std::true_type {};
1397 
1398 template <typename OutputIt>
1399 struct is_contiguous_back_insert_iterator : std::false_type {};
1400 template <typename Container>
1401 struct is_contiguous_back_insert_iterator<std::back_insert_iterator<Container>>
1402  : is_contiguous<Container> {};
1403 template <typename Char>
1405  : std::true_type {};
1406 
1407 // A type-erased reference to an std::locale to avoid heavy <locale> include.
1408 class locale_ref {
1409  private:
1410  const void* locale_; // A type-erased pointer to std::locale.
1411 
1412  public:
1413  locale_ref() : locale_(nullptr) {}
1414  template <typename Locale> explicit locale_ref(const Locale& loc);
1415 
1416  explicit operator bool() const FMT_NOEXCEPT { return locale_ != nullptr; }
1417 
1418  template <typename Locale> Locale get() const;
1419 };
1420 
1421 template <typename> constexpr unsigned long long encode_types() { return 0; }
1422 
1423 template <typename Context, typename Arg, typename... Args>
1424 constexpr unsigned long long encode_types() {
1425  return static_cast<unsigned>(mapped_type_constant<Arg, Context>::value) |
1426  (encode_types<Context, Args...>() << packed_arg_bits);
1427 }
1428 
1429 template <typename Context, typename T>
1433  arg.value_ = arg_mapper<Context>().map(value);
1434  return arg;
1435 }
1436 
1437 template <typename T> int check(unformattable) {
1438  static_assert(
1439  formattable<T>(),
1440  "Cannot format an argument. To make type T formattable provide a "
1441  "formatter<T> specialization: https://fmt.dev/dev/api.html#udt");
1442  return 0;
1443 }
1444 template <typename T, typename U> inline const U& check(const U& val) {
1445  return val;
1446 }
1447 
1448 // The type template parameter is there to avoid an ODR violation when using
1449 // a fallback formatter in one translation unit and an implicit conversion in
1450 // another (not recommended).
1451 template <bool IS_PACKED, typename Context, type, typename T,
1452  FMT_ENABLE_IF(IS_PACKED)>
1453 inline value<Context> make_arg(const T& val) {
1454  return check<T>(arg_mapper<Context>().map(val));
1455 }
1456 
1457 template <bool IS_PACKED, typename Context, type, typename T,
1458  FMT_ENABLE_IF(!IS_PACKED)>
1459 inline basic_format_arg<Context> make_arg(const T& value) {
1460  return make_arg<Context>(value);
1461 }
1462 
1463 template <typename T> struct is_reference_wrapper : std::false_type {};
1464 template <typename T>
1465 struct is_reference_wrapper<std::reference_wrapper<T>> : std::true_type {};
1466 
1467 template <typename T> const T& unwrap(const T& v) { return v; }
1468 template <typename T> const T& unwrap(const std::reference_wrapper<T>& v) {
1469  return static_cast<const T&>(v);
1470 }
1471 
1473  // Workaround for clang's -Wweak-vtables. Unlike for regular classes, for
1474  // templates it doesn't complain about inability to deduce single translation
1475  // unit for placing vtable. So storage_node_base is made a fake template.
1476  template <typename = void> struct node {
1477  virtual ~node() = default;
1478  std::unique_ptr<node<>> next;
1479  };
1480 
1481  template <typename T> struct typed_node : node<> {
1483 
1484  template <typename Arg>
1485  FMT_CONSTEXPR typed_node(const Arg& arg) : value(arg) {}
1486 
1487  template <typename Char>
1489  : value(arg.data(), arg.size()) {}
1490  };
1491 
1492  std::unique_ptr<node<>> head_;
1493 
1494  public:
1495  template <typename T, typename Arg> const T& push(const Arg& arg) {
1496  auto new_node = std::unique_ptr<typed_node<T>>(new typed_node<T>(arg));
1497  auto& value = new_node->value;
1498  new_node->next = std::move(head_);
1499  head_ = std::move(new_node);
1500  return value;
1501  }
1502 };
1503 } // namespace detail
1504 
1505 // Formatting context.
1506 template <typename OutputIt, typename Char> class basic_format_context {
1507  public:
1509  using char_type = Char;
1510 
1511  private:
1512  OutputIt out_;
1515 
1516  public:
1517  using iterator = OutputIt;
1520  template <typename T> using formatter_type = formatter<T, char_type>;
1521 
1522  basic_format_context(const basic_format_context&) = delete;
1523  void operator=(const basic_format_context&) = delete;
1528  basic_format_context(OutputIt out,
1531  : out_(out), args_(ctx_args), loc_(loc) {}
1532 
1533  format_arg arg(int id) const { return args_.get(id); }
1535  int arg_id(basic_string_view<char_type> name) { return args_.get_id(name); }
1536  const basic_format_args<basic_format_context>& args() const { return args_; }
1537 
1539  void on_error(const char* message) { error_handler().on_error(message); }
1540 
1541  // Returns an iterator to the beginning of the output range.
1542  iterator out() { return out_; }
1543 
1544  // Advances the begin iterator to ``it``.
1547  }
1548 
1549  detail::locale_ref locale() { return loc_; }
1550 };
1551 
1552 template <typename Char>
1553 using buffer_context =
1557 
1558 // Workaround an alias issue: https://stackoverflow.com/q/62767544/471164.
1559 #define FMT_BUFFER_CONTEXT(Char) \
1560  basic_format_context<detail::buffer_appender<Char>, Char>
1561 
1569 template <typename Context, typename... Args>
1571 #if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
1572  // Workaround a GCC template argument substitution bug.
1574 #endif
1575 {
1576  private:
1577  static const size_t num_args = sizeof...(Args);
1578  static const size_t num_named_args = detail::count_named_args<Args...>();
1579  static const bool is_packed = num_args <= detail::max_packed_args;
1580 
1583 
1584  detail::arg_data<value_type, typename Context::char_type, num_args,
1585  num_named_args>
1587 
1588  friend class basic_format_args<Context>;
1589 
1590  static constexpr unsigned long long desc =
1591  (is_packed ? detail::encode_types<Context, Args...>()
1592  : detail::is_unpacked_bit | num_args) |
1593  (num_named_args != 0
1594  ? static_cast<unsigned long long>(detail::has_named_args_bit)
1595  : 0);
1596 
1597  public:
1598  format_arg_store(const Args&... args)
1599  :
1600 #if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
1601  basic_format_args<Context>(*this),
1602 #endif
1603  data_{detail::make_arg<
1604  is_packed, Context,
1606  detail::init_named_args(data_.named_args(), 0, 0, args...);
1607  }
1608 };
1609 
1618 template <typename Context = format_context, typename... Args>
1619 inline format_arg_store<Context, Args...> make_format_args(
1620  const Args&... args) {
1621  return {args...};
1622 }
1623 
1632 template <typename... Args, typename S, typename Char = char_t<S>>
1633 inline auto make_args_checked(const S& format_str,
1634  const remove_reference_t<Args>&... args)
1636  static_assert(
1637  detail::count<(
1638  std::is_base_of<detail::view, remove_reference_t<Args>>::value &&
1639  std::is_reference<Args>::value)...>() == 0,
1640  "passing views as lvalues is disallowed");
1641  detail::check_format_string<Args...>(format_str);
1642  return {args...};
1643 }
1644 
1655 template <typename Char, typename T>
1656 inline detail::named_arg<Char, T> arg(const Char* name, const T& arg) {
1657  static_assert(!detail::is_named_arg<T>(), "nested named arguments");
1658  return {name, arg};
1659 }
1660 
1671 template <typename Context>
1673 #if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
1674  // Workaround a GCC template argument substitution bug.
1676 #endif
1677 {
1678  private:
1679  using char_type = typename Context::char_type;
1680 
1681  template <typename T> struct need_copy {
1682  static constexpr detail::type mapped_type =
1684 
1685  enum {
1687  std::is_same<T, basic_string_view<char_type>>::value ||
1688  std::is_same<T, detail::std_string_view<char_type>>::value ||
1689  (mapped_type != detail::type::cstring_type &&
1690  mapped_type != detail::type::string_type &&
1691  mapped_type != detail::type::custom_type))
1692  };
1693  };
1694 
1695  template <typename T>
1697  std::basic_string<char_type>, T>;
1698 
1699  // Storage of basic_format_arg must be contiguous.
1700  std::vector<basic_format_arg<Context>> data_;
1701  std::vector<detail::named_arg_info<char_type>> named_info_;
1702 
1703  // Storage of arguments not fitting into basic_format_arg must grow
1704  // without relocation because items in data_ refer to it.
1706 
1707  friend class basic_format_args<Context>;
1708 
1709  unsigned long long get_types() const {
1710  return detail::is_unpacked_bit | data_.size() |
1711  (named_info_.empty()
1712  ? 0ULL
1713  : static_cast<unsigned long long>(detail::has_named_args_bit));
1714  }
1715 
1717  return named_info_.empty() ? data_.data() : data_.data() + 1;
1718  }
1719 
1720  template <typename T> void emplace_arg(const T& arg) {
1721  data_.emplace_back(detail::make_arg<Context>(arg));
1722  }
1723 
1724  template <typename T>
1726  if (named_info_.empty()) {
1727  constexpr const detail::named_arg_info<char_type>* zero_ptr{nullptr};
1728  data_.insert(data_.begin(), {zero_ptr, 0});
1729  }
1730  data_.emplace_back(detail::make_arg<Context>(detail::unwrap(arg.value)));
1731  auto pop_one = [](std::vector<basic_format_arg<Context>>* data) {
1732  data->pop_back();
1733  };
1734  std::unique_ptr<std::vector<basic_format_arg<Context>>, decltype(pop_one)>
1735  guard{&data_, pop_one};
1736  named_info_.push_back({arg.name, static_cast<int>(data_.size() - 2u)});
1737  data_[0].value_.named_args = {named_info_.data(), named_info_.size()};
1738  guard.release();
1739  }
1740 
1741  public:
1759  template <typename T> void push_back(const T& arg) {
1761  emplace_arg(dynamic_args_.push<stored_type<T>>(arg));
1762  else
1763  emplace_arg(detail::unwrap(arg));
1764  }
1765 
1788  template <typename T> void push_back(std::reference_wrapper<T> arg) {
1789  static_assert(
1790  detail::is_named_arg<typename std::remove_cv<T>::type>::value ||
1792  "objects of built-in types and string views are always copied");
1793  emplace_arg(arg.get());
1794  }
1795 
1801  template <typename T>
1803  const char_type* arg_name =
1804  dynamic_args_.push<std::basic_string<char_type>>(arg.name).c_str();
1806  emplace_arg(
1807  fmt::arg(arg_name, dynamic_args_.push<stored_type<T>>(arg.value)));
1808  } else {
1809  emplace_arg(fmt::arg(arg_name, arg.value));
1810  }
1811  }
1812 
1814  void clear() {
1815  data_.clear();
1816  named_info_.clear();
1817  dynamic_args_ = detail::dynamic_arg_list();
1818  }
1819 
1826  void reserve(size_t new_cap, size_t new_cap_named) {
1827  FMT_ASSERT(new_cap >= new_cap_named,
1828  "Set of arguments includes set of named arguments");
1829  data_.reserve(new_cap);
1830  named_info_.reserve(new_cap_named);
1831  }
1832 };
1833 
1844 template <typename Context> class basic_format_args {
1845  public:
1846  using size_type = int;
1848 
1849  private:
1850  // A descriptor that contains information about formatting arguments.
1851  // If the number of arguments is less or equal to max_packed_args then
1852  // argument types are passed in the descriptor. This reduces binary code size
1853  // per formatting function call.
1854  unsigned long long desc_;
1855  union {
1856  // If is_packed() returns true then argument values are stored in values_;
1857  // otherwise they are stored in args_. This is done to improve cache
1858  // locality and reduce compiled code size since storing larger objects
1859  // may require more code (at least on x86-64) even if the same amount of
1860  // data is actually copied to stack. It saves ~10% on the bloat test.
1863  };
1864 
1865  bool is_packed() const { return (desc_ & detail::is_unpacked_bit) == 0; }
1866  bool has_named_args() const {
1867  return (desc_ & detail::has_named_args_bit) != 0;
1868  }
1869 
1870  detail::type type(int index) const {
1871  int shift = index * detail::packed_arg_bits;
1872  unsigned int mask = (1 << detail::packed_arg_bits) - 1;
1873  return static_cast<detail::type>((desc_ >> shift) & mask);
1874  }
1875 
1876  basic_format_args(unsigned long long desc,
1877  const detail::value<Context>* values)
1878  : desc_(desc), values_(values) {}
1879  basic_format_args(unsigned long long desc, const format_arg* args)
1880  : desc_(desc), args_(args) {}
1881 
1882  public:
1883  basic_format_args() : desc_(0) {}
1884 
1890  template <typename... Args>
1892  : basic_format_args(store.desc, store.data_.args()) {}
1893 
1901  : basic_format_args(store.get_types(), store.data()) {}
1902 
1909  : basic_format_args(detail::is_unpacked_bit | detail::to_unsigned(count),
1910  args) {}
1911 
1913  format_arg get(int id) const {
1914  format_arg arg;
1915  if (!is_packed()) {
1916  if (id < max_size()) arg = args_[id];
1917  return arg;
1918  }
1919  if (id >= detail::max_packed_args) return arg;
1920  arg.type_ = type(id);
1921  if (arg.type_ == detail::type::none_type) return arg;
1922  arg.value_ = values_[id];
1923  return arg;
1924  }
1925 
1926  template <typename Char> format_arg get(basic_string_view<Char> name) const {
1927  int id = get_id(name);
1928  return id >= 0 ? get(id) : format_arg();
1929  }
1930 
1931  template <typename Char> int get_id(basic_string_view<Char> name) const {
1932  if (!has_named_args()) return -1;
1933  const auto& named_args =
1934  (is_packed() ? values_[-1] : args_[-1].value_).named_args;
1935  for (size_t i = 0; i < named_args.size; ++i) {
1936  if (named_args.data[i].name == name) return named_args.data[i].id;
1937  }
1938  return -1;
1939  }
1940 
1941  int max_size() const {
1942  unsigned long long max_packed = detail::max_packed_args;
1943  return static_cast<int>(is_packed() ? max_packed
1944  : desc_ & ~detail::is_unpacked_bit);
1945  }
1946 };
1947 
1949 // It is a separate type rather than an alias to make symbols readable.
1950 struct format_args : basic_format_args<format_context> {
1951  template <typename... Args>
1952  FMT_INLINE format_args(const Args&... args) : basic_format_args(args...) {}
1953 };
1954 struct wformat_args : basic_format_args<wformat_context> {
1956 };
1957 
1958 namespace detail {
1959 
1961 std::basic_string<Char> vformat(
1962  basic_string_view<Char> format_str,
1964 
1965 FMT_API std::string vformat(string_view format_str, format_args args);
1966 
1967 template <typename Char>
1968 buffer_appender<Char> vformat_to(
1969  buffer<Char>& buf, basic_string_view<Char> format_str,
1971 
1972 template <typename Char, typename Args,
1974 inline void vprint_mojibake(std::FILE*, basic_string_view<Char>, const Args&) {}
1975 
1976 FMT_API void vprint_mojibake(std::FILE*, string_view, format_args);
1977 #ifndef _WIN32
1978 inline void vprint_mojibake(std::FILE*, string_view, format_args) {}
1979 #endif
1980 } // namespace detail
1981 
1983 // GCC 8 and earlier cannot handle std::back_insert_iterator<Container> with
1984 // vformat_to<ArgFormatter>(...) overload, so SFINAE on iterator type instead.
1985 template <typename OutputIt, typename S, typename Char = char_t<S>,
1986  FMT_ENABLE_IF(detail::is_output_iterator<OutputIt>::value)>
1987 OutputIt vformat_to(
1988  OutputIt out, const S& format_str,
1990  decltype(detail::get_buffer<Char>(out)) buf(detail::get_buffer_init(out));
1991  detail::vformat_to(buf, to_string_view(format_str), args);
1992  return detail::get_iterator(buf);
1993 }
1994 
2006 template <typename OutputIt, typename S, typename... Args,
2009 inline OutputIt format_to(OutputIt out, const S& format_str, Args&&... args) {
2010  const auto& vargs = fmt::make_args_checked<Args...>(format_str, args...);
2011  return vformat_to(out, to_string_view(format_str), vargs);
2012 }
2013 
2014 template <typename OutputIt> struct format_to_n_result {
2016  OutputIt out;
2018  size_t size;
2019 };
2020 
2021 template <typename OutputIt, typename Char, typename... Args,
2024  OutputIt out, size_t n, basic_string_view<Char> format_str,
2027  n);
2028  detail::vformat_to(buf, format_str, args);
2029  return {buf.out(), buf.count()};
2030 }
2031 
2039 template <typename OutputIt, typename S, typename... Args,
2042 inline format_to_n_result<OutputIt> format_to_n(OutputIt out, size_t n,
2043  const S& format_str,
2044  const Args&... args) {
2045  const auto& vargs = fmt::make_args_checked<Args...>(format_str, args...);
2046  return vformat_to_n(out, n, to_string_view(format_str), vargs);
2047 }
2048 
2053 template <typename... Args>
2054 inline size_t formatted_size(string_view format_str, Args&&... args) {
2055  const auto& vargs = fmt::make_args_checked<Args...>(format_str, args...);
2057  detail::vformat_to(buf, format_str, vargs);
2058  return buf.count();
2059 }
2060 
2061 template <typename S, typename Char = char_t<S>>
2062 FMT_INLINE std::basic_string<Char> vformat(
2063  const S& format_str,
2065  return detail::vformat(to_string_view(format_str), args);
2066 }
2067 
2078 // Pass char_t as a default template parameter instead of using
2079 // std::basic_string<char_t<S>> to reduce the symbol size.
2080 template <typename S, typename... Args, typename Char = char_t<S>>
2081 FMT_INLINE std::basic_string<Char> format(const S& format_str, Args&&... args) {
2082  const auto& vargs = fmt::make_args_checked<Args...>(format_str, args...);
2083  return detail::vformat(to_string_view(format_str), vargs);
2084 }
2085 
2087 FMT_API void vprint(std::FILE*, string_view, format_args);
2088 
2100 template <typename S, typename... Args, typename Char = char_t<S>>
2101 inline void print(std::FILE* f, const S& format_str, Args&&... args) {
2102  const auto& vargs = fmt::make_args_checked<Args...>(format_str, args...);
2103  return detail::is_unicode<Char>()
2104  ? vprint(f, to_string_view(format_str), vargs)
2105  : detail::vprint_mojibake(f, to_string_view(format_str), vargs);
2106 }
2107 
2119 template <typename S, typename... Args, typename Char = char_t<S>>
2120 inline void print(const S& format_str, Args&&... args) {
2121  const auto& vargs = fmt::make_args_checked<Args...>(format_str, args...);
2122  return detail::is_unicode<Char>()
2123  ? vprint(to_string_view(format_str), vargs)
2124  : detail::vprint_mojibake(stdout, to_string_view(format_str),
2125  vargs);
2126 }
2128 
2129 #endif // FMT_CORE_H_
type
Definition: core.h:969
FMT_INLINE value(const void *val)
Definition: core.h:1079
size_t capacity_
Definition: core.h:661
constexpr FMT_INLINE value(int val=0)
Definition: core.h:1063
#define FMT_ENABLE_IF(...)
Definition: core.h:269
fixed_buffer_traits(size_t limit)
Definition: core.h:753
T * ptr_
Definition: core.h:659
detail::dynamic_arg_list dynamic_args_
Definition: core.h:1705
buffer_appender(buffer< T > &buf)
Definition: core.h:852
void push_back(const T &arg)
Definition: core.h:1759
FMT_CONSTEXPR unsigned long long map(unsigned long long val)
Definition: core.h:1130
FMT_INLINE value(char_type val)
Definition: core.h:1073
buffer_appender operator++(int)
Definition: core.h:860
constexpr bool is_arithmetic_type(type t)
Definition: core.h:1020
int int_value
Definition: core.h:1046
FMT_CONSTEXPR auto map(const T &val) -> decltype(std::declval< arg_mapper >().map(static_cast< typename std::underlying_type< T >::type >(val)))
Definition: core.h:1206
enum MQTTPropertyCodes value
detail::custom_value< Context > custom_
Definition: core.h:1279
constexpr const Char * data() const
Definition: core.h:388
void init_named_args(named_arg_info< Char > *, int, int)
Definition: core.h:936
FMT_CONSTEXPR basic_string_view(const std::basic_string< Char, Traits, Alloc > &s) FMT_NOEXCEPT
Definition: core.h:377
static void format_custom_arg(const void *arg, typename Context::parse_context_type &parse_ctx, Context &ctx)
Definition: core.h:1097
std::unique_ptr< node<> > head_
Definition: core.h:1492
#define FMT_NORETURN
Definition: core.h:149
typename basic_format_context::char_type char_type
Definition: core.h:1043
buffer_appender & operator++()
Definition: core.h:855
FMT_INLINE const T * args() const
Definition: core.h:931
typename detail::char_t_impl< S >::type char_t
Definition: core.h:532
iterator_buffer(T *out, size_t=0)
Definition: core.h:795
const T & push(const Arg &arg)
Definition: core.h:1495
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
Definition: core.h:2081
buffer_appender(base it)
Definition: core.h:853
void format(typename Context::parse_context_type &parse_ctx, Context &ctx) const
Definition: core.h:1273
std::vector< detail::named_arg_info< char_type > > named_info_
Definition: core.h:1701
basic_format_context(OutputIt out, basic_format_args< basic_format_context > ctx_args, detail::locale_ref loc=detail::locale_ref())
Definition: core.h:1528
FMT_CONSTEXPR typed_node(const Arg &arg)
Definition: core.h:1485
auto make_args_checked(const S &format_str, const remove_reference_t< Args > &...args) -> format_arg_store< buffer_context< Char >, remove_reference_t< Args >... >
Definition: core.h:1633
#define nullptr
Definition: backward.hpp:386
FMT_CONSTEXPR void advance_to(iterator it)
Definition: core.h:577
void try_reserve(size_t new_capacity)
Definition: core.h:723
typename std::conditional< B, T, F >::type conditional_t
Definition: core.h:253
static const size_t num_args
Definition: core.h:1577
const T * end() const FMT_NOEXCEPT
Definition: core.h:695
std::random_access_iterator_tag type
Definition: core.h:1366
FMT_CONSTEXPR const void * map(std::nullptr_t val)
Definition: core.h:1192
FMT_CONSTEXPR int128_t map(int128_t val)
Definition: core.h:1131
buffer_appender< T > get_iterator(buffer< T > &buf)
Definition: core.h:883
named_arg_info< Char > * named_args()
Definition: core.h:921
void try_resize(size_t count)
Definition: core.h:714
constexpr T const_check(T value)
Definition: core.h:274
constexpr iterator end() const FMT_NOEXCEPT
Definition: core.h:574
FMT_CONSTEXPR const char_type * map(char_type *val)
Definition: core.h:1147
basic_string_view< Char > to_string_view(const Char *s)
Definition: core.h:460
char_type char_value
Definition: core.h:1053
OutputIt out()
Definition: core.h:783
size_t size_
Definition: core.h:350
char8_type
Definition: core.h:332
void grow(size_t) final FMT_OVERRIDE
Definition: core.h:833
detail::locale_ref locale()
Definition: core.h:1549
size_t size() const FMT_NOEXCEPT
Definition: core.h:698
FMT_INLINE value(long long val)
Definition: core.h:1065
FMT_CONSTEXPR ulong_type map(unsigned long val)
Definition: core.h:1128
#define FMT_CONSTEXPR_DECL
Definition: core.h:99
FMT_CONSTEXPR basic_format_arg< Context > make_arg(const T &value)
Definition: core.h:1430
Definition: json.hpp:4042
T * end() FMT_NOEXCEPT
Definition: core.h:692
handle(detail::custom_value< Context > custom)
Definition: core.h:1271
int arg_id(basic_string_view< char_type > name)
Definition: core.h:1535
unsigned int bool
Definition: MQTTPacket.h:31
FMT_CONSTEXPR int map(const T *)
Definition: core.h:1193
friend bool operator<(basic_string_view lhs, basic_string_view rhs)
Definition: core.h:418
FMT_CONSTEXPR float map(float val)
Definition: core.h:1143
const Char * data_
Definition: core.h:349
decltype(to_string_view(std::declval< S >())) result
Definition: core.h:506
basic_format_args(unsigned long long desc, const detail::value< Context > *values)
Definition: core.h:1876
typename std::remove_cv< remove_reference_t< T >>::type remove_cvref_t
Definition: core.h:260
OutputIt vformat_to(OutputIt out, const S &format_str, basic_format_args< buffer_context< type_identity_t< Char >>> args)
Definition: core.h:1987
FMT_CONSTEXPR const void * map(void *val)
Definition: core.h:1190
size_t count() const
Definition: core.h:743
FMT_CONSTEXPR int map(int val)
Definition: core.h:1125
FMT_CONSTEXPR const void * map(const void *val)
Definition: core.h:1191
FMT_INLINE void init_named_args(std::nullptr_t, int, int, const Args &...)
Definition: core.h:953
constexpr FMT_INLINE value(unsigned val)
Definition: core.h:1064
void vprint_mojibake(std::FILE *, basic_string_view< Char >, const Args &)
Definition: core.h:1974
FMT_CONSTEXPR unsigned map(unsigned val)
Definition: core.h:1126
FMT_INLINE value(basic_string_view< char_type > val)
Definition: core.h:1075
FMT_CONSTEXPR const char * map(unsigned char *val)
Definition: core.h:1185
OutputIt get_buffer_init(OutputIt out)
Definition: core.h:872
const T & value
Definition: core.h:901
FMT_CONSTEXPR void on_error(const char *message)
Definition: core.h:606
format_arg get(int id) const
Definition: core.h:1913
OutputIt out
Definition: core.h:2016
bool is_packed() const
Definition: core.h:1865
constexpr unsigned long long encode_types()
Definition: core.h:1421
basic_format_args(const format_arg *args, int count)
Definition: core.h:1908
const T * data() const FMT_NOEXCEPT
Definition: core.h:707
T & operator[](I index)
Definition: core.h:735
const T * args() const
Definition: core.h:920
FMT_INLINE value(unsigned long long val)
Definition: core.h:1066
#define FMT_END_NAMESPACE
Definition: core.h:190
static const size_t num_named_args
Definition: core.h:1578
FMT_CONSTEXPR unsigned map(unsigned char val)
Definition: core.h:1122
double double_value
Definition: core.h:1055
#define FMT_INLINE
Definition: core.h:177
buffer_context< char > format_context
Definition: core.h:1555
buffer< T > & get_buffer_init(buffer_appender< T > out)
Definition: core.h:875
FMT_CONSTEXPR bool map(bool val)
Definition: core.h:1133
FMT_INLINE std::basic_string< Char > vformat(const S &format_str, basic_format_args< buffer_context< type_identity_t< Char >>> args)
Definition: core.h:2062
FMT_INLINE value(int128_t val)
Definition: core.h:1067
FMT_INLINE arg_data(const U &...init)
Definition: core.h:930
FMT_API void vprint_mojibake(std::FILE *, string_view, format_args)
Definition: core.h:1978
int get_id(basic_string_view< Char > name) const
Definition: core.h:1931
friend bool operator!=(basic_string_view lhs, basic_string_view rhs)
Definition: core.h:415
format_arg_store(const Args &...args)
Definition: core.h:1598
detail::value< Context > value_
Definition: core.h:1245
long double long_double_value
Definition: core.h:1056
FMT_CONSTEXPR std::make_unsigned< Int >::type to_unsigned(Int value)
Definition: core.h:317
T * begin() FMT_NOEXCEPT
Definition: core.h:691
buffer< T > & get_buffer(buffer_appender< T >)
constexpr size_t count()
Definition: core.h:960
basic_string_view(const Char *s)
Definition: core.h:372
conditional_t< long_short, unsigned, unsigned long long > ulong_type
Definition: core.h:1113
void grow(size_t) final FMT_OVERRIDE
Definition: core.h:771
bool has_named_args() const
Definition: core.h:1866
void push_back(std::reference_wrapper< T > arg)
Definition: core.h:1788
buffer_appender< Char > vformat_to(buffer< Char > &buf, basic_string_view< Char > format_str, basic_format_args< FMT_BUFFER_CONTEXT(type_identity_t< Char >)> args)
FMT_CONSTEXPR_DECL FMT_INLINE auto visit_format_arg(Visitor &&vis, const basic_format_arg< Context > &arg) -> decltype(vis(0))
Definition: core.h:1302
bool is_arithmetic() const
Definition: core.h:1291
void emplace_arg(const detail::named_arg< char_type, T > &arg)
Definition: core.h:1725
void push_back(const T &value)
Definition: core.h:727
constexpr bool is_integral_type(type t)
Definition: core.h:1016
friend bool operator>=(basic_string_view lhs, basic_string_view rhs)
Definition: core.h:427
void print(std::FILE *f, const S &format_str, Args &&...args)
Definition: core.h:2101
FMT_INLINE value(const T &val)
Definition: core.h:1083
constexpr basic_format_arg()
Definition: core.h:1282
size_t count() const
Definition: core.h:787
Definition: chrono.h:284
FMT_CONSTEXPR char_type map(T val)
Definition: core.h:1136
FMT_INLINE basic_format_args(const format_arg_store< Context, Args... > &store)
Definition: core.h:1891
decltype(test< It >(typename iterator_category< It >::type{})) type
Definition: core.h:1386
constexpr iterator begin() const FMT_NOEXCEPT
Definition: core.h:569
FMT_CONSTEXPR long_type map(long val)
Definition: core.h:1127
int max_size() const
Definition: core.h:1941
#define FMT_GCC_VERSION
Definition: core.h:32
FMT_CONSTEXPR auto map(const named_arg< char_type, T > &val) -> decltype(std::declval< arg_mapper >().map(val.value))
Definition: core.h:1220
const void * pointer
Definition: core.h:1057
constexpr size_t count()
Definition: core.h:961
std::back_insert_iterator< buffer< T >> base
Definition: core.h:849
std::basic_string< Char > vformat(basic_string_view< Char > format_str, basic_format_args< buffer_context< type_identity_t< Char >>> args)
Definition: format.h:3838
FMT_CONSTEXPR const T & map(const T &val)
Definition: core.h:1215
const basic_format_arg< Context > * data() const
Definition: core.h:1716
void clear()
Definition: core.h:710
void emplace_arg(const T &arg)
Definition: core.h:1720
typename detail::void_t_impl< Ts... >::type void_t
Definition: core.h:1357
typename std::remove_reference< T >::type remove_reference_t
Definition: core.h:256
long long long_long_value
Definition: core.h:1048
FMT_CONSTEXPR typed_node(const basic_string_view< Char > &arg)
Definition: core.h:1488
format_arg arg(int id) const
Definition: core.h:1533
OutputIt out_
Definition: core.h:1512
iterator out()
Definition: core.h:1542
#define FMT_API
Definition: core.h:214
friend bool operator>(basic_string_view lhs, basic_string_view rhs)
Definition: core.h:424
FMT_CONSTEXPR int next_arg_id()
Definition: core.h:585
#define FMT_BUFFER_CONTEXT(Char)
Definition: core.h:1559
FMT_INLINE value(double val)
Definition: core.h:1070
typename basic_format_context::parse_context_type parse_context
Definition: core.h:1035
#define FMT_TYPE_CONSTANT(Type, constant)
Definition: core.h:996
typename Context::char_type char_type
Definition: core.h:1679
const void * value
Definition: core.h:1036
custom_value< Context > custom
Definition: core.h:1059
FMT_CONSTEXPR long long map(long long val)
Definition: core.h:1129
FMT_CONSTEXPR double map(double val)
Definition: core.h:1144
FMT_INLINE value(bool val)
Definition: core.h:1072
FMT_INLINE std::nullptr_t named_args()
Definition: core.h:932
const T * begin() const FMT_NOEXCEPT
Definition: core.h:694
constexpr basic_string_view(const Char *s, size_t count) FMT_NOEXCEPT
Definition: core.h:359
typename Context::char_type char_type
Definition: core.h:1119
#define FMT_UNICODE
Definition: core.h:241
const void * locale_
Definition: core.h:1410
FMT_INLINE format_args(const Args &...args)
Definition: core.h:1952
float float_value
Definition: core.h:1054
FMT_CONSTEXPR void check_arg_id(basic_string_view< Char >)
Definition: core.h:604
unformattable map(...)
Definition: core.h:1225
buffer_traits(size_t)
Definition: core.h:742
j template void())
Definition: json.hpp:3707
typename Context::char_type char_type
Definition: core.h:1260
format_arg_store< Context, Args... > make_format_args(const Args &...args)
Definition: core.h:1619
const T & unwrap(const std::reference_wrapper< T > &v)
Definition: core.h:1468
constexpr const Char & operator[](size_t pos) const
Definition: core.h:396
void advance_to(iterator it)
Definition: core.h:1545
size_t limit(size_t size)
Definition: core.h:744
const char * name
auto get_iterator(Buffer &buf) -> decltype(buf.out())
Definition: core.h:880
constexpr size_t size() const
Definition: core.h:391
static void check(LexState *ls, int c)
Definition: lparser.c:107
friend bool operator<=(basic_string_view lhs, basic_string_view rhs)
Definition: core.h:421
detail::named_arg< Char, T > arg(const Char *name, const T &arg)
Definition: core.h:1656
unsigned long long ulong_long_value
Definition: core.h:1049
const T & operator[](I index) const
Definition: core.h:736
OutputIt format_to(OutputIt out, const S &format_str, Args &&...args)
Definition: core.h:2009
const T & move(const T &v)
Definition: backward.hpp:394
buffer(T *p=nullptr, size_t sz=0, size_t cap=0) FMT_NOEXCEPT
Definition: core.h:668
FMT_CONSTEXPR const char_type * map(const char_type *val)
Definition: core.h:1148
named_arg(const Char *n, const T &v)
Definition: core.h:902
iterator_buffer(OutputIt out, size_t n=buffer_size)
Definition: core.h:777
const basic_format_args< basic_format_context > & args() const
Definition: core.h:1536
FMT_CONSTEXPR uint128_t map(uint128_t val)
Definition: core.h:1132
typename std::remove_const< T >::type remove_const_t
Definition: core.h:258
basic_format_args(unsigned long long desc, const format_arg *args)
Definition: core.h:1879
void on_error(const char *message)
Definition: core.h:1539
FMT_INLINE value(uint128_t val)
Definition: core.h:1068
FMT_INLINE basic_format_args(const dynamic_format_arg_store< Context > &store)
Definition: core.h:1900
basic_format_arg(const detail::named_arg_info< char_type > *args, size_t size)
Definition: core.h:1265
std::is_constructible< typename Context::template formatter_type< T >> has_formatter
Definition: core.h:631
detail::type type() const
Definition: core.h:1288
Container & get_container(std::back_insert_iterator< Container > it)
Definition: core.h:642
std::is_constructible< fallback_formatter< T, typename Context::char_type >> has_fallback_formatter
Definition: core.h:895
constexpr size_t count_named_args()
Definition: core.h:965
const detail::value< Context > * values_
Definition: core.h:1861
int128_t int128_value
Definition: core.h:1050
#define FMT_SUPPRESS_MSC_WARNING(n)
Definition: core.h:58
detail::type type(int index) const
Definition: core.h:1870
std::vector< basic_format_arg< Context > > data_
Definition: core.h:1700
MQTTClient c
Definition: test10.c:1656
std::unique_ptr< node<> > next
Definition: core.h:1478
string_value< char_type > string
Definition: core.h:1058
#define FMT_CONSTEXPR
Definition: core.h:98
bool is_integral() const
Definition: core.h:1290
FMT_INLINE void check_format_string(const S &)
Definition: core.h:512
constexpr unsigned long long encode_types()
Definition: core.h:1424
static const bool is_packed
Definition: core.h:1579
const named_arg_info< Char > * data
Definition: core.h:1030
typename basic_string_view< Char >::iterator iterator
Definition: core.h:558
friend bool operator==(basic_string_view lhs, basic_string_view rhs)
Definition: core.h:412
constexpr iterator end() const
Definition: core.h:394
conditional_t< is_packed, detail::value< Context >, basic_format_arg< Context >> value_type
Definition: core.h:1582
const Char * data
Definition: core.h:1025
typename type_identity< T >::type type_identity_t
Definition: core.h:262
FMT_CONSTEXPR long double map(long double val)
Definition: core.h:1145
FMT_CONSTEXPR const char * map(const unsigned char *val)
Definition: core.h:1177
basic_format_args< basic_format_context > args_
Definition: core.h:1513
size_t formatted_size(string_view format_str, Args &&...args)
Definition: core.h:2054
FMT_CONSTEXPR basic_string_view< char_type > map(const T &val)
Definition: core.h:1150
basic_format_arg< Context > make_arg(const T &value)
Definition: core.h:1459
named_arg_value< char_type > named_args
Definition: core.h:1060
FMT_CONSTEXPR const char * map(signed char *val)
Definition: core.h:1181
OutputIt iterator
Definition: core.h:1517
FMT_INLINE value(float val)
Definition: core.h:1069
const Char * name
Definition: core.h:900
const char * iterator
Definition: core.h:354
constexpr iterator begin() const
Definition: core.h:393
unsigned uint_value
Definition: core.h:1047
FMT_INLINE value(long double val)
Definition: core.h:1071
const format_arg * args_
Definition: core.h:1862
unsigned long long desc_
Definition: core.h:1854
int compare(basic_string_view other) const
Definition: core.h:404
typename std::enable_if< B, T >::type enable_if_t
Definition: core.h:251
uint128_t uint128_value
Definition: core.h:1051
FMT_CONSTEXPR int map(signed char val)
Definition: core.h:1121
#define FMT_NOEXCEPT
Definition: core.h:137
detail::error_handler error_handler()
Definition: core.h:1538
void clear(lua_State *L, int table_index)
Definition: sol.hpp:10569
conditional_t< detail::is_string< T >::value, std::basic_string< char_type >, T > stored_type
Definition: core.h:1697
detail::type type_
Definition: core.h:1246
FMT_CONSTEXPR basic_string_view(S s) FMT_NOEXCEPT
Definition: core.h:384
conditional_t< long_short, int, long long > long_type
Definition: core.h:1112
basic_string_view< Char > format_str_
Definition: core.h:553
#define FMT_ASSERT(condition, message)
Definition: core.h:284
FMT_API void vprint(string_view, format_args)
Definition: format-inl.h:2792
const Char * name
Definition: core.h:906
size_t count() const
Definition: core.h:754
#define FMT_BEGIN_NAMESPACE
Definition: core.h:195
const T & unwrap(const T &v)
Definition: core.h:1467
FMT_CONSTEXPR int map(short val)
Definition: core.h:1123
const wchar_t & const_reference
Definition: core.h:686
void grow(size_t) final FMT_OVERRIDE
Definition: core.h:792
FMT_INLINE value(const named_arg_info< char_type > *args, size_t size)
Definition: core.h:1080
bool bool_value
Definition: core.h:1052
arg_data(const U &...init)
Definition: core.h:918
dictionary data
Definition: mqtt_test.py:22
constexpr basic_string_view() FMT_NOEXCEPT
Definition: core.h:356
#define FMT_OVERRIDE
Definition: core.h:107
size_t limit(size_t size)
Definition: core.h:755
constexpr ErrorHandler error_handler() const
Definition: core.h:610
FMT_CONSTEXPR void check_arg_id(int)
Definition: core.h:597
FMT_CONSTEXPR unsigned map(unsigned short val)
Definition: core.h:1124
constexpr bool is_unicode()
Definition: core.h:324
FMT_CONSTEXPR const char * map(const signed char *val)
Definition: core.h:1173
detail::arg_data< value_type, typename Context::char_type, num_args, num_named_args > data_
Definition: core.h:1586
size_t size_
Definition: core.h:660
FMT_CONSTEXPR void remove_prefix(size_t n)
Definition: core.h:398
void check_format_string(S)
Definition: format.h:3169
FMT_INLINE value(const char_type *val)
Definition: core.h:1074
std::integral_constant< bool, B > bool_constant
Definition: core.h:254
detail::locale_ref loc_
Definition: core.h:1514
Definition: core.h:436
format_to_n_result< OutputIt > format_to_n(OutputIt out, size_t n, const S &format_str, const Args &...args)
Definition: core.h:2042
constexpr basic_format_parse_context(basic_string_view< Char > format_str, ErrorHandler eh={}, int next_arg_id=0)
Definition: core.h:560
T * data() FMT_NOEXCEPT
Definition: core.h:704
void push_back(const detail::named_arg< char_type, T > &arg)
Definition: core.h:1802
format_arg arg(basic_string_view< char_type > name)
Definition: core.h:1534
FMT_NORETURN FMT_API void assert_fail(const char *file, int line, const char *message)
Definition: format-inl.h:38
format_to_n_result< OutputIt > vformat_to_n(OutputIt out, size_t n, basic_string_view< Char > format_str, basic_format_args< buffer_context< type_identity_t< Char >>> args)
Definition: core.h:2023
void reserve(size_t new_cap, size_t new_cap_named)
Definition: core.h:1826
unsigned long long get_types() const
Definition: core.h:1709
size_t capacity() const FMT_NOEXCEPT
Definition: core.h:701


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:47:33