format.h
Go to the documentation of this file.
1 /*
2  Formatting library for C++
3 
4  Copyright (c) 2012 - 2016, Victor Zverovich
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without
8  modification, are permitted provided that the following conditions are met:
9 
10  1. Redistributions of source code must retain the above copyright notice, this
11  list of conditions and the following disclaimer.
12  2. Redistributions in binary form must reproduce the above copyright notice,
13  this list of conditions and the following disclaimer in the documentation
14  and/or other materials provided with the distribution.
15 
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef FMT_FORMAT_H_
29 #define FMT_FORMAT_H_
30 
31 #include <cassert>
32 #include <clocale>
33 #include <cmath>
34 #include <cstdio>
35 #include <cstring>
36 #include <limits>
37 #include <memory>
38 #include <stdexcept>
39 #include <string>
40 #include <vector>
41 #include <utility>
42 
43 #ifdef _SECURE_SCL
44 # define FMT_SECURE_SCL _SECURE_SCL
45 #else
46 # define FMT_SECURE_SCL 0
47 #endif
48 
49 #if FMT_SECURE_SCL
50 # include <iterator>
51 #endif
52 
53 #ifdef _MSC_VER
54 # define FMT_MSC_VER _MSC_VER
55 #else
56 # define FMT_MSC_VER 0
57 #endif
58 
59 #if FMT_MSC_VER && FMT_MSC_VER <= 1500
60 typedef unsigned __int32 uint32_t;
61 typedef unsigned __int64 uint64_t;
62 typedef __int64 intmax_t;
63 #else
64 #include <stdint.h>
65 #endif
66 
67 #if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
68 # ifdef FMT_EXPORT
69 # define FMT_API __declspec(dllexport)
70 # elif defined(FMT_SHARED)
71 # define FMT_API __declspec(dllimport)
72 # endif
73 #endif
74 #ifndef FMT_API
75 # define FMT_API
76 #endif
77 
78 #ifdef __GNUC__
79 # define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
80 # define FMT_GCC_EXTENSION __extension__
81 # if FMT_GCC_VERSION >= 406
82 # pragma GCC diagnostic push
83 // Disable the warning about "long long" which is sometimes reported even
84 // when using __extension__.
85 # pragma GCC diagnostic ignored "-Wlong-long"
86 // Disable the warning about declaration shadowing because it affects too
87 // many valid cases.
88 # pragma GCC diagnostic ignored "-Wshadow"
89 // Disable the warning about implicit conversions that may change the sign of
90 // an integer; silencing it otherwise would require many explicit casts.
91 # pragma GCC diagnostic ignored "-Wsign-conversion"
92 # endif
93 # if __cplusplus >= 201103L || defined __GXX_EXPERIMENTAL_CXX0X__
94 # define FMT_HAS_GXX_CXX11 1
95 # endif
96 #else
97 # define FMT_GCC_EXTENSION
98 #endif
99 
100 #if defined(__INTEL_COMPILER)
101 # define FMT_ICC_VERSION __INTEL_COMPILER
102 #elif defined(__ICL)
103 # define FMT_ICC_VERSION __ICL
104 #endif
105 
106 #if defined(__clang__) && !defined(FMT_ICC_VERSION)
107 # pragma clang diagnostic push
108 # pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
109 # pragma clang diagnostic ignored "-Wpadded"
110 #endif
111 
112 #ifdef __GNUC_LIBSTD__
113 # define FMT_GNUC_LIBSTD_VERSION (__GNUC_LIBSTD__ * 100 + __GNUC_LIBSTD_MINOR__)
114 #endif
115 
116 #ifdef __has_feature
117 # define FMT_HAS_FEATURE(x) __has_feature(x)
118 #else
119 # define FMT_HAS_FEATURE(x) 0
120 #endif
121 
122 #ifdef __has_builtin
123 # define FMT_HAS_BUILTIN(x) __has_builtin(x)
124 #else
125 # define FMT_HAS_BUILTIN(x) 0
126 #endif
127 
128 #ifdef __has_cpp_attribute
129 # define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
130 #else
131 # define FMT_HAS_CPP_ATTRIBUTE(x) 0
132 #endif
133 
134 #ifndef FMT_USE_VARIADIC_TEMPLATES
135 // Variadic templates are available in GCC since version 4.4
136 // (http://gcc.gnu.org/projects/cxx0x.html) and in Visual C++
137 // since version 2013.
138 # define FMT_USE_VARIADIC_TEMPLATES \
139  (FMT_HAS_FEATURE(cxx_variadic_templates) || \
140  (FMT_GCC_VERSION >= 404 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1800)
141 #endif
142 
143 #ifndef FMT_USE_RVALUE_REFERENCES
144 // Don't use rvalue references when compiling with clang and an old libstdc++
145 // as the latter doesn't provide std::move.
146 # if defined(FMT_GNUC_LIBSTD_VERSION) && FMT_GNUC_LIBSTD_VERSION <= 402
147 # define FMT_USE_RVALUE_REFERENCES 0
148 # else
149 # define FMT_USE_RVALUE_REFERENCES \
150  (FMT_HAS_FEATURE(cxx_rvalue_references) || \
151  (FMT_GCC_VERSION >= 403 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1600)
152 # endif
153 #endif
154 
155 #if FMT_USE_RVALUE_REFERENCES
156 # include <utility> // for std::move
157 #endif
158 
159 // Check if exceptions are disabled.
160 #if defined(__GNUC__) && !defined(__EXCEPTIONS)
161 # define FMT_EXCEPTIONS 0
162 #endif
163 #if FMT_MSC_VER && !_HAS_EXCEPTIONS
164 # define FMT_EXCEPTIONS 0
165 #endif
166 #ifndef FMT_EXCEPTIONS
167 # define FMT_EXCEPTIONS 1
168 #endif
169 
170 #ifndef FMT_THROW
171 # if FMT_EXCEPTIONS
172 # define FMT_THROW(x) throw x
173 # else
174 # define FMT_THROW(x) assert(false)
175 # endif
176 #endif
177 
178 // Define FMT_USE_NOEXCEPT to make fmt use noexcept (C++11 feature).
179 #ifndef FMT_USE_NOEXCEPT
180 # define FMT_USE_NOEXCEPT 0
181 #endif
182 
183 #ifndef FMT_NOEXCEPT
184 # if FMT_EXCEPTIONS
185 # if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \
186  (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || \
187  FMT_MSC_VER >= 1900
188 # define FMT_NOEXCEPT noexcept
189 # else
190 # define FMT_NOEXCEPT throw()
191 # endif
192 # else
193 # define FMT_NOEXCEPT
194 # endif
195 #endif
196 
197 #ifndef FMT_OVERRIDE
198 # if FMT_USE_OVERRIDE || FMT_HAS_FEATURE(cxx_override) || \
199  (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || \
200  FMT_MSC_VER >= 1900
201 # define FMT_OVERRIDE override
202 # else
203 # define FMT_OVERRIDE
204 # endif
205 #endif
206 
207 
208 // A macro to disallow the copy constructor and operator= functions
209 // This should be used in the private: declarations for a class
210 #ifndef FMT_USE_DELETED_FUNCTIONS
211 # define FMT_USE_DELETED_FUNCTIONS 0
212 #endif
213 
214 #if FMT_USE_DELETED_FUNCTIONS || FMT_HAS_FEATURE(cxx_deleted_functions) || \
215  (FMT_GCC_VERSION >= 404 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1800
216 # define FMT_DELETED_OR_UNDEFINED = delete
217 # define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \
218  TypeName(const TypeName&) = delete; \
219  TypeName& operator=(const TypeName&) = delete
220 #else
221 # define FMT_DELETED_OR_UNDEFINED
222 # define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \
223  TypeName(const TypeName&); \
224  TypeName& operator=(const TypeName&)
225 #endif
226 
227 #ifndef FMT_USE_USER_DEFINED_LITERALS
228 // All compilers which support UDLs also support variadic templates. This
229 // makes the fmt::literals implementation easier. However, an explicit check
230 // for variadic templates is added here just in case.
231 // For Intel's compiler both it and the system gcc/msc must support UDLs.
232 # define FMT_USE_USER_DEFINED_LITERALS \
233  FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES && \
234  (FMT_HAS_FEATURE(cxx_user_literals) || \
235  (FMT_GCC_VERSION >= 407 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900) && \
236  (!defined(FMT_ICC_VERSION) || FMT_ICC_VERSION >= 1500)
237 #endif
238 
239 #ifndef FMT_ASSERT
240 # define FMT_ASSERT(condition, message) assert((condition) && message)
241 #endif
242 
243 #if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz)
244 # define FMT_BUILTIN_CLZ(n) __builtin_clz(n)
245 #endif
246 
247 #if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clzll)
248 # define FMT_BUILTIN_CLZLL(n) __builtin_clzll(n)
249 #endif
250 
251 // Some compilers masquerade as both MSVC and GCC-likes or
252 // otherwise support __builtin_clz and __builtin_clzll, so
253 // only define FMT_BUILTIN_CLZ using the MSVC intrinsics
254 // if the clz and clzll builtins are not available.
255 #if FMT_MSC_VER && !defined(FMT_BUILTIN_CLZLL)
256 # include <intrin.h> // _BitScanReverse, _BitScanReverse64
257 
258 namespace fmt
259 {
260 namespace internal
261 {
262 # pragma intrinsic(_BitScanReverse)
263 inline uint32_t clz(uint32_t x)
264 {
265  unsigned long r = 0;
266  _BitScanReverse(&r, x);
267 
268  assert(x != 0);
269  // Static analysis complains about using uninitialized data
270  // "r", but the only way that can happen is if "x" is 0,
271  // which the callers guarantee to not happen.
272 # pragma warning(suppress: 6102)
273  return 31 - r;
274 }
275 # define FMT_BUILTIN_CLZ(n) fmt::internal::clz(n)
276 
277 # ifdef _WIN64
278 # pragma intrinsic(_BitScanReverse64)
279 # endif
280 
281 inline uint32_t clzll(uint64_t x)
282 {
283  unsigned long r = 0;
284 # ifdef _WIN64
285  _BitScanReverse64(&r, x);
286 # else
287  // Scan the high 32 bits.
288  if (_BitScanReverse(&r, static_cast<uint32_t>(x >> 32)))
289  return 63 - (r + 32);
290 
291  // Scan the low 32 bits.
292  _BitScanReverse(&r, static_cast<uint32_t>(x));
293 # endif
294 
295  assert(x != 0);
296  // Static analysis complains about using uninitialized data
297  // "r", but the only way that can happen is if "x" is 0,
298  // which the callers guarantee to not happen.
299 # pragma warning(suppress: 6102)
300  return 63 - r;
301 }
302 # define FMT_BUILTIN_CLZLL(n) fmt::internal::clzll(n)
303 }
304 }
305 #endif
306 
307 namespace fmt
308 {
309 namespace internal
310 {
311 struct DummyInt
312 {
313  int data[2];
314  operator int() const
315  {
316  return 0;
317  }
318 };
320 
321 // Dummy implementations of system functions such as signbit and ecvt called
322 // if the latter are not available.
323 inline DummyInt signbit(...)
324 {
325  return DummyInt();
326 }
327 inline DummyInt _ecvt_s(...)
328 {
329  return DummyInt();
330 }
331 inline DummyInt isinf(...)
332 {
333  return DummyInt();
334 }
335 inline DummyInt _finite(...)
336 {
337  return DummyInt();
338 }
339 inline DummyInt isnan(...)
340 {
341  return DummyInt();
342 }
343 inline DummyInt _isnan(...)
344 {
345  return DummyInt();
346 }
347 
348 // A helper function to suppress bogus "conditional expression is constant"
349 // warnings.
350 template <typename T>
351 inline T const_check(T value)
352 {
353  return value;
354 }
355 }
356 } // namespace fmt
357 
358 namespace std
359 {
360 // Standard permits specialization of std::numeric_limits. This specialization
361 // is used to resolve ambiguity between isinf and std::isinf in glibc:
362 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48891
363 // and the same for isnan and signbit.
364 template <>
365 class numeric_limits<fmt::internal::DummyInt> :
366  public std::numeric_limits<int>
367 {
368 public:
369  // Portable version of isinf.
370  template <typename T>
371  static bool isinfinity(T x)
372  {
373  using namespace fmt::internal;
374  // The resolution "priority" is:
375  // isinf macro > std::isinf > ::isinf > fmt::internal::isinf
376  if (const_check(sizeof(isinf(x)) == sizeof(bool) ||
377  sizeof(isinf(x)) == sizeof(int)))
378  {
379  return isinf(x) != 0;
380  }
381  return !_finite(static_cast<double>(x));
382  }
383 
384  // Portable version of isnan.
385  template <typename T>
386  static bool isnotanumber(T x)
387  {
388  using namespace fmt::internal;
389  if (const_check(sizeof(isnan(x)) == sizeof(bool) ||
390  sizeof(isnan(x)) == sizeof(int)))
391  {
392  return isnan(x) != 0;
393  }
394  return _isnan(static_cast<double>(x)) != 0;
395  }
396 
397  // Portable version of signbit.
398  static bool isnegative(double x)
399  {
400  using namespace fmt::internal;
401  if (const_check(sizeof(signbit(x)) == sizeof(int)))
402  return signbit(x) != 0;
403  if (x < 0) return true;
404  if (!isnotanumber(x)) return false;
405  int dec = 0, sign = 0;
406  char buffer[2]; // The buffer size must be >= 2 or _ecvt_s will fail.
407  _ecvt_s(buffer, sizeof(buffer), x, 0, &dec, &sign);
408  return sign != 0;
409  }
410 };
411 } // namespace std
412 
413 namespace fmt
414 {
415 
416 // Fix the warning about long long on older versions of GCC
417 // that don't support the diagnostic pragma.
418 FMT_GCC_EXTENSION typedef long long LongLong;
419 FMT_GCC_EXTENSION typedef unsigned long long ULongLong;
420 
421 #if FMT_USE_RVALUE_REFERENCES
422 using std::move;
423 #endif
424 
425 template <typename Char>
427 
428 typedef BasicWriter<char> Writer;
430 
431 template <typename Char>
433 
434 template <typename CharType,
437 
462 template <typename Char>
464 {
465 private:
466  const Char *data_;
467  std::size_t size_;
468 
469 public:
471  BasicStringRef(const Char *s, std::size_t size) : data_(s), size_(size) {}
472 
480  : data_(s), size_(std::char_traits<Char>::length(s)) {}
481 
487  BasicStringRef(const std::basic_string<Char> &s)
488  : data_(s.c_str()), size_(s.size()) {}
489 
495  std::basic_string<Char> to_string() const
496  {
497  return std::basic_string<Char>(data_, size_);
498  }
499 
501  const Char *data() const
502  {
503  return data_;
504  }
505 
507  std::size_t size() const
508  {
509  return size_;
510  }
511 
512  // Lexicographically compare this string reference to other.
513  int compare(BasicStringRef other) const
514  {
515  std::size_t size = size_ < other.size_ ? size_ : other.size_;
516  int result = std::char_traits<Char>::compare(data_, other.data_, size);
517  if (result == 0)
518  result = size_ == other.size_ ? 0 : (size_ < other.size_ ? -1 : 1);
519  return result;
520  }
521 
523  {
524  return lhs.compare(rhs) == 0;
525  }
527  {
528  return lhs.compare(rhs) != 0;
529  }
531  {
532  return lhs.compare(rhs) < 0;
533  }
535  {
536  return lhs.compare(rhs) <= 0;
537  }
539  {
540  return lhs.compare(rhs) > 0;
541  }
543  {
544  return lhs.compare(rhs) >= 0;
545  }
546 };
547 
550 
576 template <typename Char>
578 {
579 private:
580  const Char *data_;
581 
582 public:
584  BasicCStringRef(const Char *s) : data_(s) {}
585 
591  BasicCStringRef(const std::basic_string<Char> &s) : data_(s.c_str()) {}
592 
594  const Char *c_str() const
595  {
596  return data_;
597  }
598 };
599 
602 
604 class FormatError : public std::runtime_error
605 {
606 public:
607  explicit FormatError(CStringRef message)
608  : std::runtime_error(message.c_str()) {}
609  ~FormatError() throw();
610 };
611 
612 namespace internal
613 {
614 
615 // MakeUnsigned<T>::Type gives an unsigned type corresponding to integer type T.
616 template <typename T>
618 {
619  typedef T Type;
620 };
621 
622 #define FMT_SPECIALIZE_MAKE_UNSIGNED(T, U) \
623  template <> \
624  struct MakeUnsigned<T> { typedef U Type; }
625 
626 FMT_SPECIALIZE_MAKE_UNSIGNED(char, unsigned char);
627 FMT_SPECIALIZE_MAKE_UNSIGNED(signed char, unsigned char);
628 FMT_SPECIALIZE_MAKE_UNSIGNED(short, unsigned short);
629 FMT_SPECIALIZE_MAKE_UNSIGNED(int, unsigned);
630 FMT_SPECIALIZE_MAKE_UNSIGNED(long, unsigned long);
631 FMT_SPECIALIZE_MAKE_UNSIGNED(LongLong, ULongLong);
632 
633 // Casts nonnegative integer to unsigned.
634 template <typename Int>
635 inline typename MakeUnsigned<Int>::Type to_unsigned(Int value)
636 {
637  FMT_ASSERT(value >= 0, "negative value");
638  return static_cast<typename MakeUnsigned<Int>::Type>(value);
639 }
640 
641 // The number of characters to store in the MemoryBuffer object itself
642 // to avoid dynamic memory allocation.
643 enum { INLINE_BUFFER_SIZE = 500 };
644 
645 #if FMT_SECURE_SCL
646 // Use checked iterator to avoid warnings on MSVC.
647 template <typename T>
648 inline stdext::checked_array_iterator<T*> make_ptr(T *ptr, std::size_t size)
649 {
650  return stdext::checked_array_iterator<T*>(ptr, size);
651 }
652 #else
653 template <typename T>
654 inline T *make_ptr(T *ptr, std::size_t)
655 {
656  return ptr;
657 }
658 #endif
659 } // namespace internal
660 
666 template <typename T>
667 class Buffer
668 {
669 private:
671 
672 protected:
673  T *ptr_;
674  std::size_t size_;
675  std::size_t capacity_;
676 
677  Buffer(T *ptr = 0, std::size_t capacity = 0)
678  : ptr_(ptr), size_(0), capacity_(capacity) {}
679 
686  virtual void grow(std::size_t size) = 0;
687 
688 public:
689  virtual ~Buffer() {}
690 
692  std::size_t size() const
693  {
694  return size_;
695  }
696 
698  std::size_t capacity() const
699  {
700  return capacity_;
701  }
702 
706  void resize(std::size_t new_size)
707  {
708  if (new_size > capacity_)
709  grow(new_size);
710  size_ = new_size;
711  }
712 
718  void reserve(std::size_t capacity)
719  {
720  if (capacity > capacity_)
721  grow(capacity);
722  }
723 
724  void clear() FMT_NOEXCEPT { size_ = 0; }
725 
726  void push_back(const T &value)
727  {
728  if (size_ == capacity_)
729  grow(size_ + 1);
730  ptr_[size_++] = value;
731  }
732 
734  template <typename U>
735  void append(const U *begin, const U *end);
736 
737  T &operator[](std::size_t index)
738  {
739  return ptr_[index];
740  }
741  const T &operator[](std::size_t index) const
742  {
743  return ptr_[index];
744  }
745 };
746 
747 template <typename T>
748 template <typename U>
749 void Buffer<T>::append(const U *begin, const U *end)
750 {
751  std::size_t new_size = size_ + internal::to_unsigned(end - begin);
752  if (new_size > capacity_)
753  grow(new_size);
754  std::uninitialized_copy(begin, end,
755  internal::make_ptr(ptr_, capacity_) + size_);
756  size_ = new_size;
757 }
758 
759 namespace internal
760 {
761 
762 // A memory buffer for trivially copyable/constructible types with the first
763 // SIZE elements stored in the object itself.
764 template <typename T, std::size_t SIZE, typename Allocator = std::allocator<T> >
765 class MemoryBuffer : private Allocator, public Buffer<T>
766 {
767 private:
768  T data_[SIZE];
769 
770  // Deallocate memory allocated by the buffer.
771  void deallocate()
772  {
773  if (this->ptr_ != data_) Allocator::deallocate(this->ptr_, this->capacity_);
774  }
775 
776 protected:
777  void grow(std::size_t size) FMT_OVERRIDE;
778 
779 public:
780  explicit MemoryBuffer(const Allocator &alloc = Allocator())
781  : Allocator(alloc), Buffer<T>(data_, SIZE) {}
783  {
784  deallocate();
785  }
786 
787 #if FMT_USE_RVALUE_REFERENCES
788 private:
789  // Move data from other to this buffer.
790  void move(MemoryBuffer &other)
791  {
792  Allocator &this_alloc = *this, &other_alloc = other;
793  this_alloc = std::move(other_alloc);
794  this->size_ = other.size_;
795  this->capacity_ = other.capacity_;
796  if (other.ptr_ == other.data_)
797  {
798  this->ptr_ = data_;
799  std::uninitialized_copy(other.data_, other.data_ + this->size_,
800  make_ptr(data_, this->capacity_));
801  }
802  else
803  {
804  this->ptr_ = other.ptr_;
805  // Set pointer to the inline array so that delete is not called
806  // when deallocating.
807  other.ptr_ = other.data_;
808  }
809  }
810 
811 public:
812  MemoryBuffer(MemoryBuffer &&other)
813  {
814  move(other);
815  }
816 
817  MemoryBuffer &operator=(MemoryBuffer &&other)
818  {
819  assert(this != &other);
820  deallocate();
821  move(other);
822  return *this;
823  }
824 #endif
825 
826  // Returns a copy of the allocator associated with this buffer.
827  Allocator get_allocator() const
828  {
829  return *this;
830  }
831 };
832 
833 template <typename T, std::size_t SIZE, typename Allocator>
835 {
836  std::size_t new_capacity = this->capacity_ + this->capacity_ / 2;
837  if (size > new_capacity)
838  new_capacity = size;
839  T *new_ptr = this->allocate(new_capacity);
840  // The following code doesn't throw, so the raw pointer above doesn't leak.
841  std::uninitialized_copy(this->ptr_, this->ptr_ + this->size_,
842  make_ptr(new_ptr, new_capacity));
843  std::size_t old_capacity = this->capacity_;
844  T *old_ptr = this->ptr_;
845  this->capacity_ = new_capacity;
846  this->ptr_ = new_ptr;
847  // deallocate may throw (at least in principle), but it doesn't matter since
848  // the buffer already uses the new storage and will deallocate it in case
849  // of exception.
850  if (old_ptr != data_)
851  Allocator::deallocate(old_ptr, old_capacity);
852 }
853 
854 // A fixed-size buffer.
855 template <typename Char>
856 class FixedBuffer : public fmt::Buffer<Char>
857 {
858 public:
859  FixedBuffer(Char *array, std::size_t size) : fmt::Buffer<Char>(array, size) {}
860 
861 protected:
862  FMT_API void grow(std::size_t size);
863 };
864 
865 template <typename Char>
867 {
868 public:
869 #if FMT_SECURE_SCL
870  typedef stdext::checked_array_iterator<Char*> CharPtr;
871 #else
872  typedef Char *CharPtr;
873 #endif
874  static Char cast(int value)
875  {
876  return static_cast<Char>(value);
877  }
878 };
879 
880 template <typename Char>
882 
883 template <>
884 class CharTraits<char> : public BasicCharTraits<char>
885 {
886 private:
887  // Conversion from wchar_t to char is not allowed.
888  static char convert(wchar_t);
889 
890 public:
891  static char convert(char value)
892  {
893  return value;
894  }
895 
896  // Formats a floating-point number.
897  template <typename T>
898  FMT_API static int format_float(char *buffer, std::size_t size,
899  const char *format, unsigned width, int precision, T value);
900 };
901 
902 template <>
903 class CharTraits<wchar_t> : public BasicCharTraits<wchar_t>
904 {
905 public:
906  static wchar_t convert(char value)
907  {
908  return value;
909  }
910  static wchar_t convert(wchar_t value)
911  {
912  return value;
913  }
914 
915  template <typename T>
916  FMT_API static int format_float(wchar_t *buffer, std::size_t size,
917  const wchar_t *format, unsigned width, int precision, T value);
918 };
919 
920 // Checks if a number is negative - used to avoid warnings.
921 template <bool IsSigned>
923 {
924  template <typename T>
925  static bool is_negative(T value)
926  {
927  return value < 0;
928  }
929 };
930 
931 template <>
932 struct SignChecker<false>
933 {
934  template <typename T>
935  static bool is_negative(T)
936  {
937  return false;
938  }
939 };
940 
941 // Returns true if value is negative, false otherwise.
942 // Same as (value < 0) but doesn't produce warnings if T is an unsigned type.
943 template <typename T>
944 inline bool is_negative(T value)
945 {
947 }
948 
949 // Selects uint32_t if FitsIn32Bits is true, uint64_t otherwise.
950 template <bool FitsIn32Bits>
952 {
953  typedef uint32_t Type;
954 };
955 
956 template <>
957 struct TypeSelector<false>
958 {
959  typedef uint64_t Type;
960 };
961 
962 template <typename T>
963 struct IntTraits
964 {
965  // Smallest of uint32_t and uint64_t that is large enough to represent
966  // all values of T.
967  typedef typename
968  TypeSelector<std::numeric_limits<T>::digits <= 32>::Type MainType;
969 };
970 
971 FMT_API void report_unknown_type(char code, const char *type);
972 
973 // Static data is placed in this class template to allow header-only
974 // configuration.
975 template <typename T = void>
977 {
978  static const uint32_t POWERS_OF_10_32[];
979  static const uint64_t POWERS_OF_10_64[];
980  static const char DIGITS[];
981 };
982 
983 #ifndef FMT_USE_EXTERN_TEMPLATES
984 // Clang doesn't have a feature check for extern templates so we check
985 // for variadic templates which were introduced in the same version.
986 # define FMT_USE_EXTERN_TEMPLATES (__clang__ && FMT_USE_VARIADIC_TEMPLATES)
987 #endif
988 
989 #if FMT_USE_EXTERN_TEMPLATES && !defined(FMT_HEADER_ONLY)
990 extern template struct BasicData<void>;
991 #endif
992 
994 
995 #ifdef FMT_BUILTIN_CLZLL
996 // Returns the number of decimal digits in n. Leading zeros are not counted
997 // except for n == 0 in which case count_digits returns 1.
998 inline unsigned count_digits(uint64_t n)
999 {
1000  // Based on http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
1001  // and the benchmark https://github.com/localvoid/cxx-benchmark-count-digits.
1002  int t = (64 - FMT_BUILTIN_CLZLL(n | 1)) * 1233 >> 12;
1003  return to_unsigned(t) - (n < Data::POWERS_OF_10_64[t]) + 1;
1004 }
1005 #else
1006 // Fallback version of count_digits used when __builtin_clz is not available.
1007 inline unsigned count_digits(uint64_t n)
1008 {
1009  unsigned count = 1;
1010  for (;;)
1011  {
1012  // Integer division is slow so do it for a group of four digits instead
1013  // of for every digit. The idea comes from the talk by Alexandrescu
1014  // "Three Optimization Tips for C++". See speed-test for a comparison.
1015  if (n < 10) return count;
1016  if (n < 100) return count + 1;
1017  if (n < 1000) return count + 2;
1018  if (n < 10000) return count + 3;
1019  n /= 10000u;
1020  count += 4;
1021  }
1022 }
1023 #endif
1024 
1025 #ifdef FMT_BUILTIN_CLZ
1026 // Optional version of count_digits for better performance on 32-bit platforms.
1027 inline unsigned count_digits(uint32_t n)
1028 {
1029  int t = (32 - FMT_BUILTIN_CLZ(n | 1)) * 1233 >> 12;
1030  return to_unsigned(t) - (n < Data::POWERS_OF_10_32[t]) + 1;
1031 }
1032 #endif
1033 
1034 // A functor that doesn't add a thousands separator.
1036 {
1037  template <typename Char>
1038  void operator()(Char *) {}
1039 };
1040 
1041 // A functor that adds a thousands separator.
1043 {
1044 private:
1046 
1047  // Index of a decimal digit with the least significant digit having index 0.
1048  unsigned digit_index_;
1049 
1050 public:
1051  explicit ThousandsSep(fmt::StringRef sep) : sep_(sep), digit_index_(0) {}
1052 
1053  template <typename Char>
1054  void operator()(Char *&buffer)
1055  {
1056  if (++digit_index_ % 3 != 0)
1057  return;
1058  buffer -= sep_.size();
1059  std::uninitialized_copy(sep_.data(), sep_.data() + sep_.size(),
1060  internal::make_ptr(buffer, sep_.size()));
1061  }
1062 };
1063 
1064 // Formats a decimal unsigned integer value writing into buffer.
1065 // thousands_sep is a functor that is called after writing each char to
1066 // add a thousands separator if necessary.
1067 template <typename UInt, typename Char, typename ThousandsSep>
1068 inline void format_decimal(Char *buffer, UInt value, unsigned num_digits,
1070 {
1071  buffer += num_digits;
1072  while (value >= 100)
1073  {
1074  // Integer division is slow so do it for a group of two digits instead
1075  // of for every digit. The idea comes from the talk by Alexandrescu
1076  // "Three Optimization Tips for C++". See speed-test for a comparison.
1077  unsigned index = static_cast<unsigned>((value % 100) * 2);
1078  value /= 100;
1079  *--buffer = Data::DIGITS[index + 1];
1080  thousands_sep(buffer);
1081  *--buffer = Data::DIGITS[index];
1082  thousands_sep(buffer);
1083  }
1084  if (value < 10)
1085  {
1086  *--buffer = static_cast<char>('0' + value);
1087  return;
1088  }
1089  unsigned index = static_cast<unsigned>(value * 2);
1090  *--buffer = Data::DIGITS[index + 1];
1091  thousands_sep(buffer);
1092  *--buffer = Data::DIGITS[index];
1093 }
1094 
1095 template <typename UInt, typename Char>
1096 inline void format_decimal(Char *buffer, UInt value, unsigned num_digits)
1097 {
1098  return format_decimal(buffer, value, num_digits, NoThousandsSep());
1099 }
1100 
1101 #ifndef _WIN32
1102 # define FMT_USE_WINDOWS_H 0
1103 #elif !defined(FMT_USE_WINDOWS_H)
1104 # define FMT_USE_WINDOWS_H 1
1105 #endif
1106 
1107 // Define FMT_USE_WINDOWS_H to 0 to disable use of windows.h.
1108 // All the functionality that relies on it will be disabled too.
1109 #if FMT_USE_WINDOWS_H
1110 // A converter from UTF-8 to UTF-16.
1111 // It is only provided for Windows since other systems support UTF-8 natively.
1112 class UTF8ToUTF16
1113 {
1114 private:
1116 
1117 public:
1118  FMT_API explicit UTF8ToUTF16(StringRef s);
1119  operator WStringRef() const
1120  {
1121  return WStringRef(&buffer_[0], size());
1122  }
1123  size_t size() const
1124  {
1125  return buffer_.size() - 1;
1126  }
1127  const wchar_t *c_str() const
1128  {
1129  return &buffer_[0];
1130  }
1131  std::wstring str() const
1132  {
1133  return std::wstring(&buffer_[0], size());
1134  }
1135 };
1136 
1137 // A converter from UTF-16 to UTF-8.
1138 // It is only provided for Windows since other systems support UTF-8 natively.
1139 class UTF16ToUTF8
1140 {
1141 private:
1143 
1144 public:
1145  UTF16ToUTF8() {}
1146  FMT_API explicit UTF16ToUTF8(WStringRef s);
1147  operator StringRef() const
1148  {
1149  return StringRef(&buffer_[0], size());
1150  }
1151  size_t size() const
1152  {
1153  return buffer_.size() - 1;
1154  }
1155  const char *c_str() const
1156  {
1157  return &buffer_[0];
1158  }
1159  std::string str() const
1160  {
1161  return std::string(&buffer_[0], size());
1162  }
1163 
1164  // Performs conversion returning a system error code instead of
1165  // throwing exception on conversion error. This method may still throw
1166  // in case of memory allocation error.
1167  FMT_API int convert(WStringRef s);
1168 };
1169 
1170 FMT_API void format_windows_error(fmt::Writer &out, int error_code,
1172 #endif
1173 
1174 FMT_API void format_system_error(fmt::Writer &out, int error_code,
1175  fmt::StringRef message) FMT_NOEXCEPT;
1176 
1177 // A formatting argument value.
1178 struct Value
1179 {
1180  template <typename Char>
1182  {
1183  const Char *value;
1184  std::size_t size;
1185  };
1186 
1187  typedef void (*FormatFunc)(
1188  void *formatter, const void *arg, void *format_str_ptr);
1189 
1191  {
1192  const void *value;
1193  FormatFunc format;
1194  };
1195 
1196  union
1197  {
1199  unsigned uint_value;
1201  ULongLong ulong_long_value;
1203  long double long_double_value;
1204  const void *pointer;
1210  };
1211 
1212  enum Type
1213  {
1214  NONE, NAMED_ARG,
1215  // Integer types should go first,
1216  INT, UINT, LONG_LONG, ULONG_LONG, BOOL, CHAR, LAST_INTEGER_TYPE = CHAR,
1217  // followed by floating-point types.
1218  DOUBLE, LONG_DOUBLE, LAST_NUMERIC_TYPE = LONG_DOUBLE,
1219  CSTRING, STRING, WSTRING, POINTER, CUSTOM
1220  };
1221 };
1222 
1223 // A formatting argument. It is a trivially copyable/constructible type to
1224 // allow storage in internal::MemoryBuffer.
1225 struct Arg : Value
1226 {
1228 };
1229 
1230 template <typename Char>
1231 struct NamedArg;
1232 
1233 template <typename T = void>
1234 struct Null {};
1235 
1236 // A helper class template to enable or disable overloads taking wide
1237 // characters and strings in MakeValue.
1238 template <typename T, typename Char>
1240 {
1242  typedef T Unsupported;
1243 };
1244 
1245 template <typename T>
1247 {
1248  typedef T Supported;
1250 };
1251 
1252 typedef char Yes[1];
1253 typedef char No[2];
1254 
1255 template <typename T>
1256 T &get();
1257 
1258 // These are non-members to workaround an overload resolution bug in bcc32.
1259 Yes &convert(fmt::ULongLong);
1260 No &convert(...);
1261 
1262 template<typename T, bool ENABLE_CONVERSION>
1264 {
1265  enum { value = ENABLE_CONVERSION };
1266 };
1267 
1268 template<typename T, bool ENABLE_CONVERSION>
1270 {
1271  enum { value = false };
1272 };
1273 
1274 template<typename T>
1276 {
1277  enum
1278  {
1279  // Don't convert numeric types.
1281  };
1282 };
1283 
1284 template<typename T>
1286 {
1287  enum { enable_conversion = sizeof(convert(get<T>())) == sizeof(Yes) };
1289 };
1290 
1291 #define FMT_DISABLE_CONVERSION_TO_INT(Type) \
1292  template <> \
1293  struct ConvertToInt<Type> { enum { value = 0 }; }
1294 
1295 // Silence warnings about convering float to int.
1298 FMT_DISABLE_CONVERSION_TO_INT(long double);
1299 
1300 template<bool B, class T = void>
1301 struct EnableIf {};
1302 
1303 template<class T>
1304 struct EnableIf<true, T>
1305 {
1306  typedef T type;
1307 };
1308 
1309 template<bool B, class T, class F>
1311 {
1312  typedef T type;
1313 };
1314 
1315 template<class T, class F>
1316 struct Conditional<false, T, F>
1317 {
1318  typedef F type;
1319 };
1320 
1321 // For bcc32 which doesn't understand ! in template arguments.
1322 template<bool>
1323 struct Not
1324 {
1325  enum { value = 0 };
1326 };
1327 
1328 template<>
1329 struct Not<false>
1330 {
1331  enum { value = 1 };
1332 };
1333 
1334 template<typename T, T> struct LConvCheck
1335 {
1336  LConvCheck(int) {}
1337 };
1338 
1339 // Returns the thousands separator for the current locale.
1340 // We check if ``lconv`` contains ``thousands_sep`` because on Android
1341 // ``lconv`` is stubbed as an empty struct.
1342 template <typename LConv>
1343 inline StringRef thousands_sep(
1345 {
1346  return lc->thousands_sep;
1347 }
1348 
1350 {
1351  return "";
1352 }
1353 
1354 // Makes an Arg object from any type.
1355 template <typename Formatter>
1356 class MakeValue : public Arg
1357 {
1358 public:
1359  typedef typename Formatter::Char Char;
1360 
1361 private:
1362  // The following two methods are private to disallow formatting of
1363  // arbitrary pointers. If you want to output a pointer cast it to
1364  // "void *" or "const void *". In particular, this forbids formatting
1365  // of "[const] volatile char *" which is printed as bool by iostreams.
1366  // Do not implement!
1367  template <typename T>
1368  MakeValue(const T *value);
1369  template <typename T>
1370  MakeValue(T *value);
1371 
1372  // The following methods are private to disallow formatting of wide
1373  // characters and strings into narrow strings as in
1374  // fmt::format("{}", L"test");
1375  // To fix this, use a wide format string: fmt::format(L"{}", L"test").
1376 #if !FMT_MSC_VER || defined(_NATIVE_WCHAR_T_DEFINED)
1378 #endif
1383 
1384  void set_string(StringRef str)
1385  {
1386  string.value = str.data();
1387  string.size = str.size();
1388  }
1389 
1390  void set_string(WStringRef str)
1391  {
1392  wstring.value = str.data();
1393  wstring.size = str.size();
1394  }
1395 
1396  // Formats an argument of a custom type, such as a user-defined class.
1397  template <typename T>
1398  static void format_custom_arg(
1399  void *formatter, const void *arg, void *format_str_ptr)
1400  {
1401  format(*static_cast<Formatter*>(formatter),
1402  *static_cast<const Char**>(format_str_ptr),
1403  *static_cast<const T*>(arg));
1404  }
1405 
1406 public:
1408 
1409 #define FMT_MAKE_VALUE_(Type, field, TYPE, rhs) \
1410  MakeValue(Type value) { field = rhs; } \
1411  static uint64_t type(Type) { return Arg::TYPE; }
1412 
1413 #define FMT_MAKE_VALUE(Type, field, TYPE) \
1414  FMT_MAKE_VALUE_(Type, field, TYPE, value)
1415 
1416  FMT_MAKE_VALUE(bool, int_value, BOOL)
1417  FMT_MAKE_VALUE(short, int_value, INT)
1418  FMT_MAKE_VALUE(unsigned short, uint_value, UINT)
1419  FMT_MAKE_VALUE(int, int_value, INT)
1420  FMT_MAKE_VALUE(unsigned, uint_value, UINT)
1421 
1422  MakeValue(long value)
1423  {
1424  // To minimize the number of types we need to deal with, long is
1425  // translated either to int or to long long depending on its size.
1426  if (const_check(sizeof(long) == sizeof(int)))
1427  int_value = static_cast<int>(value);
1428  else
1429  long_long_value = value;
1430  }
1431  static uint64_t type(long)
1432  {
1433  return sizeof(long) == sizeof(int) ? Arg::INT : Arg::LONG_LONG;
1434  }
1435 
1436  MakeValue(unsigned long value)
1437  {
1438  if (const_check(sizeof(unsigned long) == sizeof(unsigned)))
1439  uint_value = static_cast<unsigned>(value);
1440  else
1441  ulong_long_value = value;
1442  }
1443  static uint64_t type(unsigned long)
1444  {
1445  return sizeof(unsigned long) == sizeof(unsigned) ?
1447  }
1448 
1449  FMT_MAKE_VALUE(LongLong, long_long_value, LONG_LONG)
1450  FMT_MAKE_VALUE(ULongLong, ulong_long_value, ULONG_LONG)
1451  FMT_MAKE_VALUE(float, double_value, DOUBLE)
1452  FMT_MAKE_VALUE(double, double_value, DOUBLE)
1453  FMT_MAKE_VALUE(long double, long_double_value, LONG_DOUBLE)
1454  FMT_MAKE_VALUE(signed char, int_value, INT)
1455  FMT_MAKE_VALUE(unsigned char, uint_value, UINT)
1456  FMT_MAKE_VALUE(char, int_value, CHAR)
1457 
1458 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
1460  {
1461  int_value = value;
1462  }
1463  static uint64_t type(wchar_t)
1464  {
1465  return Arg::CHAR;
1466  }
1467 #endif
1468 
1469 #define FMT_MAKE_STR_VALUE(Type, TYPE) \
1470  MakeValue(Type value) { set_string(value); } \
1471  static uint64_t type(Type) { return Arg::TYPE; }
1472 
1473  FMT_MAKE_VALUE(char *, string.value, CSTRING)
1474  FMT_MAKE_VALUE(const char *, string.value, CSTRING)
1475  FMT_MAKE_VALUE(signed char *, sstring.value, CSTRING)
1476  FMT_MAKE_VALUE(const signed char *, sstring.value, CSTRING)
1477  FMT_MAKE_VALUE(unsigned char *, ustring.value, CSTRING)
1478  FMT_MAKE_VALUE(const unsigned char *, ustring.value, CSTRING)
1479  FMT_MAKE_STR_VALUE(const std::string &, STRING)
1480  FMT_MAKE_STR_VALUE(StringRef, STRING)
1481  FMT_MAKE_VALUE_(CStringRef, string.value, CSTRING, value.c_str())
1482 
1483 #define FMT_MAKE_WSTR_VALUE(Type, TYPE) \
1484  MakeValue(typename WCharHelper<Type, Char>::Supported value) { \
1485  set_string(value); \
1486  } \
1487  static uint64_t type(Type) { return Arg::TYPE; }
1488 
1489  FMT_MAKE_WSTR_VALUE(wchar_t *, WSTRING)
1490  FMT_MAKE_WSTR_VALUE(const wchar_t *, WSTRING)
1491  FMT_MAKE_WSTR_VALUE(const std::wstring &, WSTRING)
1492  FMT_MAKE_WSTR_VALUE(WStringRef, WSTRING)
1493 
1494  FMT_MAKE_VALUE(void *, pointer, POINTER)
1495  FMT_MAKE_VALUE(const void *, pointer, POINTER)
1496 
1497  template <typename T>
1498  MakeValue(const T &value,
1499  typename EnableIf<Not<
1500  ConvertToInt<T>::value>::value, int>::type = 0)
1501  {
1502  custom.value = &value;
1503  custom.format = &format_custom_arg<T>;
1504  }
1505 
1506  template <typename T>
1507  MakeValue(const T &value,
1508  typename EnableIf<ConvertToInt<T>::value, int>::type = 0)
1509  {
1510  int_value = value;
1511  }
1512 
1513  template <typename T>
1514  static uint64_t type(const T &)
1515  {
1517  }
1518 
1519  // Additional template param `Char_` is needed here because make_type always
1520  // uses char.
1521  template <typename Char_>
1523  {
1524  pointer = &value;
1525  }
1526 
1527  template <typename Char_>
1528  static uint64_t type(const NamedArg<Char_> &)
1529  {
1530  return Arg::NAMED_ARG;
1531  }
1532 };
1533 
1534 template <typename Formatter>
1535 class MakeArg : public Arg
1536 {
1537 public:
1539  {
1540  type = Arg::NONE;
1541  }
1542 
1543  template <typename T>
1544  MakeArg(const T &value)
1545  : Arg(MakeValue<Formatter>(value))
1546  {
1547  type = static_cast<Arg::Type>(MakeValue<Formatter>::type(value));
1548  }
1549 };
1550 
1551 template <typename Char>
1552 struct NamedArg : Arg
1553 {
1555 
1556  template <typename T>
1557  NamedArg(BasicStringRef<Char> argname, const T &value)
1558  : Arg(MakeArg< BasicFormatter<Char> >(value)), name(argname) {}
1559 };
1560 
1561 class RuntimeError : public std::runtime_error
1562 {
1563 protected:
1564  RuntimeError() : std::runtime_error("") {}
1565  ~RuntimeError() throw();
1566 };
1567 
1568 template <typename Char>
1569 class PrintfArgFormatter;
1570 
1571 template <typename Char>
1572 class ArgMap;
1573 } // namespace internal
1574 
1576 class ArgList
1577 {
1578 private:
1579  // To reduce compiled code size per formatting function call, types of first
1580  // MAX_PACKED_ARGS arguments are passed in the types_ field.
1581  uint64_t types_;
1582  union
1583  {
1584  // If the number of arguments is less than MAX_PACKED_ARGS, the argument
1585  // values are stored in values_, otherwise they are stored in args_.
1586  // This is done to reduce compiled code size as storing larger objects
1587  // may require more code (at least on x86-64) even if the same amount of
1588  // data is actually copied to stack. It saves ~10% on the bloat test.
1591  };
1592 
1593  internal::Arg::Type type(unsigned index) const
1594  {
1595  unsigned shift = index * 4;
1596  uint64_t mask = 0xf;
1597  return static_cast<internal::Arg::Type>(
1598  (types_ & (mask << shift)) >> shift);
1599  }
1600 
1601  template <typename Char>
1602  friend class internal::ArgMap;
1603 
1604 public:
1605  // Maximum number of arguments with packed types.
1606  enum { MAX_PACKED_ARGS = 16 };
1607 
1608  ArgList() : types_(0) {}
1609 
1610  ArgList(ULongLong types, const internal::Value *values)
1611  : types_(types), values_(values) {}
1612  ArgList(ULongLong types, const internal::Arg *args)
1613  : types_(types), args_(args) {}
1614 
1616  internal::Arg operator[](unsigned index) const
1617  {
1618  using internal::Arg;
1619  Arg arg;
1620  bool use_values = type(MAX_PACKED_ARGS - 1) == Arg::NONE;
1621  if (index < MAX_PACKED_ARGS)
1622  {
1623  Arg::Type arg_type = type(index);
1624  internal::Value &val = arg;
1625  if (arg_type != Arg::NONE)
1626  val = use_values ? values_[index] : args_[index];
1627  arg.type = arg_type;
1628  return arg;
1629  }
1630  if (use_values)
1631  {
1632  // The index is greater than the number of arguments that can be stored
1633  // in values, so return a "none" argument.
1634  arg.type = Arg::NONE;
1635  return arg;
1636  }
1637  for (unsigned i = MAX_PACKED_ARGS; i <= index; ++i)
1638  {
1639  if (args_[i].type == Arg::NONE)
1640  return args_[i];
1641  }
1642  return args_[index];
1643  }
1644 };
1645 
1646 #define FMT_DISPATCH(call) static_cast<Impl*>(this)->call
1647 
1672 template <typename Impl, typename Result>
1674 {
1675 private:
1677 
1678 public:
1680 
1682  {
1683  FMT_DISPATCH(report_unhandled_arg());
1684  return Result();
1685  }
1686 
1688  Result visit_int(int value)
1689  {
1690  return FMT_DISPATCH(visit_any_int(value));
1691  }
1692 
1694  Result visit_long_long(LongLong value)
1695  {
1696  return FMT_DISPATCH(visit_any_int(value));
1697  }
1698 
1700  Result visit_uint(unsigned value)
1701  {
1702  return FMT_DISPATCH(visit_any_int(value));
1703  }
1704 
1706  Result visit_ulong_long(ULongLong value)
1707  {
1708  return FMT_DISPATCH(visit_any_int(value));
1709  }
1710 
1712  Result visit_bool(bool value)
1713  {
1714  return FMT_DISPATCH(visit_any_int(value));
1715  }
1716 
1718  Result visit_char(int value)
1719  {
1720  return FMT_DISPATCH(visit_any_int(value));
1721  }
1722 
1724  template <typename T>
1725  Result visit_any_int(T)
1726  {
1727  return FMT_DISPATCH(visit_unhandled_arg());
1728  }
1729 
1731  Result visit_double(double value)
1732  {
1733  return FMT_DISPATCH(visit_any_double(value));
1734  }
1735 
1737  Result visit_long_double(long double value)
1738  {
1739  return FMT_DISPATCH(visit_any_double(value));
1740  }
1741 
1743  template <typename T>
1745  {
1746  return FMT_DISPATCH(visit_unhandled_arg());
1747  }
1748 
1750  Result visit_cstring(const char *)
1751  {
1752  return FMT_DISPATCH(visit_unhandled_arg());
1753  }
1754 
1757  {
1758  return FMT_DISPATCH(visit_unhandled_arg());
1759  }
1760 
1763  {
1764  return FMT_DISPATCH(visit_unhandled_arg());
1765  }
1766 
1768  Result visit_pointer(const void *)
1769  {
1770  return FMT_DISPATCH(visit_unhandled_arg());
1771  }
1772 
1775  {
1776  return FMT_DISPATCH(visit_unhandled_arg());
1777  }
1778 
1787  Result visit(const Arg &arg)
1788  {
1789  switch (arg.type)
1790  {
1791  case Arg::NONE:
1792  case Arg::NAMED_ARG:
1793  FMT_ASSERT(false, "invalid argument type");
1794  break;
1795  case Arg::INT:
1796  return FMT_DISPATCH(visit_int(arg.int_value));
1797  case Arg::UINT:
1798  return FMT_DISPATCH(visit_uint(arg.uint_value));
1799  case Arg::LONG_LONG:
1800  return FMT_DISPATCH(visit_long_long(arg.long_long_value));
1801  case Arg::ULONG_LONG:
1802  return FMT_DISPATCH(visit_ulong_long(arg.ulong_long_value));
1803  case Arg::BOOL:
1804  return FMT_DISPATCH(visit_bool(arg.int_value != 0));
1805  case Arg::CHAR:
1806  return FMT_DISPATCH(visit_char(arg.int_value));
1807  case Arg::DOUBLE:
1808  return FMT_DISPATCH(visit_double(arg.double_value));
1809  case Arg::LONG_DOUBLE:
1810  return FMT_DISPATCH(visit_long_double(arg.long_double_value));
1811  case Arg::CSTRING:
1812  return FMT_DISPATCH(visit_cstring(arg.string.value));
1813  case Arg::STRING:
1814  return FMT_DISPATCH(visit_string(arg.string));
1815  case Arg::WSTRING:
1816  return FMT_DISPATCH(visit_wstring(arg.wstring));
1817  case Arg::POINTER:
1818  return FMT_DISPATCH(visit_pointer(arg.pointer));
1819  case Arg::CUSTOM:
1820  return FMT_DISPATCH(visit_custom(arg.custom));
1821  }
1822  return Result();
1823  }
1824 };
1825 
1827 {
1829 };
1830 
1831 // Flags.
1832 enum
1833 {
1835  CHAR_FLAG = 0x10 // Argument has char type - used in error reporting.
1836 };
1837 
1838 // An empty format specifier.
1839 struct EmptySpec {};
1840 
1841 // A type specifier.
1842 template <char TYPE>
1844 {
1846  {
1847  return ALIGN_DEFAULT;
1848  }
1849  unsigned width() const
1850  {
1851  return 0;
1852  }
1853  int precision() const
1854  {
1855  return -1;
1856  }
1857  bool flag(unsigned) const
1858  {
1859  return false;
1860  }
1861  char type() const
1862  {
1863  return TYPE;
1864  }
1865  char fill() const
1866  {
1867  return ' ';
1868  }
1869 };
1870 
1871 // A width specifier.
1873 {
1874  unsigned width_;
1875  // Fill is always wchar_t and cast to char if necessary to avoid having
1876  // two specialization of WidthSpec and its subclasses.
1877  wchar_t fill_;
1878 
1879  WidthSpec(unsigned width, wchar_t fill) : width_(width), fill_(fill) {}
1880 
1881  unsigned width() const
1882  {
1883  return width_;
1884  }
1885  wchar_t fill() const
1886  {
1887  return fill_;
1888  }
1889 };
1890 
1891 // An alignment specifier.
1893 {
1895 
1896  AlignSpec(unsigned width, wchar_t fill, Alignment align = ALIGN_DEFAULT)
1897  : WidthSpec(width, fill), align_(align) {}
1898 
1900  {
1901  return align_;
1902  }
1903 
1904  int precision() const
1905  {
1906  return -1;
1907  }
1908 };
1909 
1910 // An alignment and type specifier.
1911 template <char TYPE>
1913 {
1914  AlignTypeSpec(unsigned width, wchar_t fill) : AlignSpec(width, fill) {}
1915 
1916  bool flag(unsigned) const
1917  {
1918  return false;
1919  }
1920  char type() const
1921  {
1922  return TYPE;
1923  }
1924 };
1925 
1926 // A full format specifier.
1928 {
1929  unsigned flags_;
1931  char type_;
1932 
1934  unsigned width = 0, char type = 0, wchar_t fill = ' ')
1935  : AlignSpec(width, fill), flags_(0), precision_(-1), type_(type) {}
1936 
1937  bool flag(unsigned f) const
1938  {
1939  return (flags_ & f) != 0;
1940  }
1941  int precision() const
1942  {
1943  return precision_;
1944  }
1945  char type() const
1946  {
1947  return type_;
1948  }
1949 };
1950 
1951 // An integer format specifier.
1952 template <typename T, typename SpecT = TypeSpec<0>, typename Char = char>
1953 class IntFormatSpec : public SpecT
1954 {
1955 private:
1957 
1958 public:
1959  IntFormatSpec(T val, const SpecT &spec = SpecT())
1960  : SpecT(spec), value_(val) {}
1961 
1962  T value() const
1963  {
1964  return value_;
1965  }
1966 };
1967 
1968 // A string format specifier.
1969 template <typename Char>
1970 class StrFormatSpec : public AlignSpec
1971 {
1972 private:
1973  const Char *str_;
1974 
1975 public:
1976  template <typename FillChar>
1977  StrFormatSpec(const Char *str, unsigned width, FillChar fill)
1978  : AlignSpec(width, fill), str_(str)
1979  {
1981  }
1982 
1983  const Char *str() const
1984  {
1985  return str_;
1986  }
1987 };
1988 
1993 
1998 
2004 
2010 
2025 template <char TYPE_CODE, typename Char>
2027  int value, unsigned width, Char fill = ' ');
2028 
2029 #define FMT_DEFINE_INT_FORMATTERS(TYPE) \
2030 inline IntFormatSpec<TYPE, TypeSpec<'b'> > bin(TYPE value) { \
2031  return IntFormatSpec<TYPE, TypeSpec<'b'> >(value, TypeSpec<'b'>()); \
2032 } \
2033  \
2034 inline IntFormatSpec<TYPE, TypeSpec<'o'> > oct(TYPE value) { \
2035  return IntFormatSpec<TYPE, TypeSpec<'o'> >(value, TypeSpec<'o'>()); \
2036 } \
2037  \
2038 inline IntFormatSpec<TYPE, TypeSpec<'x'> > hex(TYPE value) { \
2039  return IntFormatSpec<TYPE, TypeSpec<'x'> >(value, TypeSpec<'x'>()); \
2040 } \
2041  \
2042 inline IntFormatSpec<TYPE, TypeSpec<'X'> > hexu(TYPE value) { \
2043  return IntFormatSpec<TYPE, TypeSpec<'X'> >(value, TypeSpec<'X'>()); \
2044 } \
2045  \
2046 template <char TYPE_CODE> \
2047 inline IntFormatSpec<TYPE, AlignTypeSpec<TYPE_CODE> > pad( \
2048  IntFormatSpec<TYPE, TypeSpec<TYPE_CODE> > f, unsigned width) { \
2049  return IntFormatSpec<TYPE, AlignTypeSpec<TYPE_CODE> >( \
2050  f.value(), AlignTypeSpec<TYPE_CODE>(width, ' ')); \
2051 } \
2052  \
2053 /* For compatibility with older compilers we provide two overloads for pad, */ \
2054 /* one that takes a fill character and one that doesn't. In the future this */ \
2055 /* can be replaced with one overload making the template argument Char */ \
2056 /* default to char (C++11). */ \
2057 template <char TYPE_CODE, typename Char> \
2058 inline IntFormatSpec<TYPE, AlignTypeSpec<TYPE_CODE>, Char> pad( \
2059  IntFormatSpec<TYPE, TypeSpec<TYPE_CODE>, Char> f, \
2060  unsigned width, Char fill) { \
2061  return IntFormatSpec<TYPE, AlignTypeSpec<TYPE_CODE>, Char>( \
2062  f.value(), AlignTypeSpec<TYPE_CODE>(width, fill)); \
2063 } \
2064  \
2065 inline IntFormatSpec<TYPE, AlignTypeSpec<0> > pad( \
2066  TYPE value, unsigned width) { \
2067  return IntFormatSpec<TYPE, AlignTypeSpec<0> >( \
2068  value, AlignTypeSpec<0>(width, ' ')); \
2069 } \
2070  \
2071 template <typename Char> \
2072 inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
2073  TYPE value, unsigned width, Char fill) { \
2074  return IntFormatSpec<TYPE, AlignTypeSpec<0>, Char>( \
2075  value, AlignTypeSpec<0>(width, fill)); \
2076 }
2077 
2080 FMT_DEFINE_INT_FORMATTERS(unsigned)
2081 FMT_DEFINE_INT_FORMATTERS(unsigned long)
2082 FMT_DEFINE_INT_FORMATTERS(LongLong)
2083 FMT_DEFINE_INT_FORMATTERS(ULongLong)
2084 
2097 template <typename Char>
2098 inline StrFormatSpec<Char> pad(
2099  const Char *str, unsigned width, Char fill = ' ')
2100 {
2101  return StrFormatSpec<Char>(str, width, fill);
2102 }
2103 
2105  const wchar_t *str, unsigned width, char fill = ' ')
2106 {
2107  return StrFormatSpec<wchar_t>(str, width, fill);
2108 }
2109 
2110 namespace internal
2111 {
2112 
2113 template <typename Char>
2114 class ArgMap
2115 {
2116 private:
2117  typedef std::vector<
2118  std::pair<fmt::BasicStringRef<Char>, internal::Arg> > MapType;
2119  typedef typename MapType::value_type Pair;
2120 
2121  MapType map_;
2122 
2123 public:
2124  FMT_API void init(const ArgList &args);
2125 
2127  {
2128  // The list is unsorted, so just return the first matching name.
2129  for (typename MapType::const_iterator it = map_.begin(), end = map_.end();
2130  it != end; ++it)
2131  {
2132  if (it->first == name)
2133  return &it->second;
2134  }
2135  return 0;
2136  }
2137 };
2138 
2139 template <typename Impl, typename Char>
2140 class ArgFormatterBase : public ArgVisitor<Impl, void>
2141 {
2142 private:
2145 
2147 
2148  void write_pointer(const void *p)
2149  {
2150  spec_.flags_ = HASH_FLAG;
2151  spec_.type_ = 'x';
2152  writer_.write_int(reinterpret_cast<uintptr_t>(p), spec_);
2153  }
2154 
2155 protected:
2157  {
2158  return writer_;
2159  }
2161  {
2162  return spec_;
2163  }
2164 
2165  void write(bool value)
2166  {
2167  const char *str_value = value ? "true" : "false";
2168  Arg::StringValue<char> str = { str_value, std::strlen(str_value) };
2169  writer_.write_str(str, spec_);
2170  }
2171 
2172  void write(const char *value)
2173  {
2174  Arg::StringValue<char> str = {value, value != 0 ? std::strlen(value) : 0};
2175  writer_.write_str(str, spec_);
2176  }
2177 
2178 public:
2180  : writer_(w), spec_(s) {}
2181 
2182  template <typename T>
2183  void visit_any_int(T value)
2184  {
2185  writer_.write_int(value, spec_);
2186  }
2187 
2188  template <typename T>
2189  void visit_any_double(T value)
2190  {
2191  writer_.write_double(value, spec_);
2192  }
2193 
2194  void visit_bool(bool value)
2195  {
2196  if (spec_.type_)
2197  return visit_any_int(value);
2198  write(value);
2199  }
2200 
2201  void visit_char(int value)
2202  {
2203  if (spec_.type_ && spec_.type_ != 'c')
2204  {
2205  spec_.flags_ |= CHAR_FLAG;
2206  writer_.write_int(value, spec_);
2207  return;
2208  }
2209  if (spec_.align_ == ALIGN_NUMERIC || spec_.flags_ != 0)
2210  FMT_THROW(FormatError("invalid format specifier for char"));
2211  typedef typename BasicWriter<Char>::CharPtr CharPtr;
2212  Char fill = internal::CharTraits<Char>::cast(spec_.fill());
2213  CharPtr out = CharPtr();
2214  const unsigned CHAR_SIZE = 1;
2215  if (spec_.width_ > CHAR_SIZE)
2216  {
2217  out = writer_.grow_buffer(spec_.width_);
2218  if (spec_.align_ == ALIGN_RIGHT)
2219  {
2220  std::uninitialized_fill_n(out, spec_.width_ - CHAR_SIZE, fill);
2221  out += spec_.width_ - CHAR_SIZE;
2222  }
2223  else if (spec_.align_ == ALIGN_CENTER)
2224  {
2225  out = writer_.fill_padding(out, spec_.width_,
2226  internal::const_check(CHAR_SIZE), fill);
2227  }
2228  else
2229  {
2230  std::uninitialized_fill_n(out + CHAR_SIZE,
2231  spec_.width_ - CHAR_SIZE, fill);
2232  }
2233  }
2234  else
2235  {
2236  out = writer_.grow_buffer(CHAR_SIZE);
2237  }
2238  *out = internal::CharTraits<Char>::cast(value);
2239  }
2240 
2241  void visit_cstring(const char *value)
2242  {
2243  if (spec_.type_ == 'p')
2244  return write_pointer(value);
2245  write(value);
2246  }
2247 
2249  {
2250  writer_.write_str(value, spec_);
2251  }
2252 
2254 
2256  {
2257  writer_.write_str(value, spec_);
2258  }
2259 
2260  void visit_pointer(const void *value)
2261  {
2262  if (spec_.type_ && spec_.type_ != 'p')
2263  report_unknown_type(spec_.type_, "pointer");
2264  write_pointer(value);
2265  }
2266 };
2267 
2269 {
2270 private:
2273 
2274  // Returns the argument with specified index.
2275  FMT_API Arg do_get_arg(unsigned arg_index, const char *&error);
2276 
2277 protected:
2278  const ArgList &args() const
2279  {
2280  return args_;
2281  }
2282 
2283  explicit FormatterBase(const ArgList &args)
2284  {
2285  args_ = args;
2286  next_arg_index_ = 0;
2287  }
2288 
2289  // Returns the next argument.
2290  Arg next_arg(const char *&error)
2291  {
2292  if (next_arg_index_ >= 0)
2293  return do_get_arg(internal::to_unsigned(next_arg_index_++), error);
2294  error = "cannot switch from manual to automatic argument indexing";
2295  return Arg();
2296  }
2297 
2298  // Checks if manual indexing is used and returns the argument with
2299  // specified index.
2300  Arg get_arg(unsigned arg_index, const char *&error)
2301  {
2302  return check_no_auto_index(error) ? do_get_arg(arg_index, error) : Arg();
2303  }
2304 
2305  bool check_no_auto_index(const char *&error)
2306  {
2307  if (next_arg_index_ > 0)
2308  {
2309  error = "cannot switch from automatic to manual argument indexing";
2310  return false;
2311  }
2312  next_arg_index_ = -1;
2313  return true;
2314  }
2315 
2316  template <typename Char>
2317  void write(BasicWriter<Char> &w, const Char *start, const Char *end)
2318  {
2319  if (start != end)
2320  w << BasicStringRef<Char>(start, internal::to_unsigned(end - start));
2321  }
2322 };
2323 
2324 // A printf formatter.
2325 template <typename Char>
2327 {
2328 private:
2329  void parse_flags(FormatSpec &spec, const Char *&s);
2330 
2331  // Returns the argument with specified index or, if arg_index is equal
2332  // to the maximum unsigned value, the next argument.
2333  Arg get_arg(const Char *s,
2334  unsigned arg_index = (std::numeric_limits<unsigned>::max)());
2335 
2336  // Parses argument index, flags and width and returns the argument index.
2337  unsigned parse_header(const Char *&s, FormatSpec &spec);
2338 
2339 public:
2340  explicit PrintfFormatter(const ArgList &args) : FormatterBase(args) {}
2341  FMT_API void format(BasicWriter<Char> &writer,
2342  BasicCStringRef<Char> format_str);
2343 };
2344 } // namespace internal
2345 
2363 template <typename Impl, typename Char>
2365 {
2366 private:
2368  const Char *format_;
2369 
2370 public:
2380  FormatSpec &spec, const Char *fmt)
2381  : internal::ArgFormatterBase<Impl, Char>(formatter.writer(), spec),
2382  formatter_(formatter), format_(fmt) {}
2383 
2386  {
2387  c.format(&formatter_, c.value, &format_);
2388  }
2389 };
2390 
2392 template <typename Char>
2393 class ArgFormatter : public BasicArgFormatter<ArgFormatter<Char>, Char>
2394 {
2395 public:
2398  FormatSpec &spec, const Char *fmt)
2399  : BasicArgFormatter<ArgFormatter<Char>, Char>(formatter, spec, fmt) {}
2400 };
2401 
2403 template <typename CharType, typename ArgFormatter>
2405 {
2406 public:
2408  typedef CharType Char;
2409 
2410 private:
2413 
2415 
2417 
2418  // Checks if manual indexing is used and returns the argument with
2419  // specified name.
2420  internal::Arg get_arg(BasicStringRef<Char> arg_name, const char *&error);
2421 
2422  // Parses argument index and returns corresponding argument.
2423  internal::Arg parse_arg_index(const Char *&s);
2424 
2425  // Parses argument name and returns corresponding argument.
2426  internal::Arg parse_arg_name(const Char *&s);
2427 
2428 public:
2437  : internal::FormatterBase(args), writer_(w) {}
2438 
2441  {
2442  return writer_;
2443  }
2444 
2446  void format(BasicCStringRef<Char> format_str);
2447 
2448  // Formats a single argument and advances format_str, a format string pointer.
2449  const Char *format(const Char *&format_str, const internal::Arg &arg);
2450 };
2451 
2452 // Generates a comma-separated list with results of applying f to
2453 // numbers 0..n-1.
2454 # define FMT_GEN(n, f) FMT_GEN##n(f)
2455 # define FMT_GEN1(f) f(0)
2456 # define FMT_GEN2(f) FMT_GEN1(f), f(1)
2457 # define FMT_GEN3(f) FMT_GEN2(f), f(2)
2458 # define FMT_GEN4(f) FMT_GEN3(f), f(3)
2459 # define FMT_GEN5(f) FMT_GEN4(f), f(4)
2460 # define FMT_GEN6(f) FMT_GEN5(f), f(5)
2461 # define FMT_GEN7(f) FMT_GEN6(f), f(6)
2462 # define FMT_GEN8(f) FMT_GEN7(f), f(7)
2463 # define FMT_GEN9(f) FMT_GEN8(f), f(8)
2464 # define FMT_GEN10(f) FMT_GEN9(f), f(9)
2465 # define FMT_GEN11(f) FMT_GEN10(f), f(10)
2466 # define FMT_GEN12(f) FMT_GEN11(f), f(11)
2467 # define FMT_GEN13(f) FMT_GEN12(f), f(12)
2468 # define FMT_GEN14(f) FMT_GEN13(f), f(13)
2469 # define FMT_GEN15(f) FMT_GEN14(f), f(14)
2470 
2471 namespace internal
2472 {
2473 inline uint64_t make_type()
2474 {
2475  return 0;
2476 }
2477 
2478 template <typename T>
2479 inline uint64_t make_type(const T &arg)
2480 {
2481  return MakeValue< BasicFormatter<char> >::type(arg);
2482 }
2483 
2484 template <unsigned N, bool/*IsPacked*/= (N < ArgList::MAX_PACKED_ARGS)>
2485  struct ArgArray;
2486 
2487 template <unsigned N>
2488 struct ArgArray<N, true/*IsPacked*/>
2489 {
2490  typedef Value Type[N > 0 ? N : 1];
2491 
2492 template <typename Formatter, typename T>
2493 static Value make(const T &value)
2494 {
2495 #ifdef __clang__
2496  Value result = MakeValue<Formatter>(value);
2497  // Workaround a bug in Apple LLVM version 4.2 (clang-425.0.28) of clang:
2498  // https://github.com/fmtlib/fmt/issues/276
2499  (void)result.custom.format;
2500  return result;
2501 #else
2502  return MakeValue<Formatter>(value);
2503 #endif
2504 }
2505  };
2506 
2507 template <unsigned N>
2508 struct ArgArray<N, false/*IsPacked*/>
2509 {
2510  typedef Arg Type[N + 1]; // +1 for the list end Arg::NONE
2511 
2512  template <typename Formatter, typename T>
2513  static Arg make(const T &value)
2514  {
2515  return MakeArg<Formatter>(value);
2516  }
2517 };
2518 
2519 #if FMT_USE_VARIADIC_TEMPLATES
2520 template <typename Arg, typename... Args>
2521 inline uint64_t make_type(const Arg &first, const Args & ... tail)
2522 {
2523  return make_type(first) | (make_type(tail...) << 4);
2524 }
2525 
2526 #else
2527 
2528 struct ArgType
2529 {
2530  uint64_t type;
2531 
2532  ArgType() : type(0) {}
2533 
2534  template <typename T>
2535  ArgType(const T &arg) : type(make_type(arg)) {}
2536 };
2537 
2538 # define FMT_ARG_TYPE_DEFAULT(n) ArgType t##n = ArgType()
2539 
2541 {
2542  return t0.type | (t1.type << 4) | (t2.type << 8) | (t3.type << 12) |
2543  (t4.type << 16) | (t5.type << 20) | (t6.type << 24) | (t7.type << 28) |
2544  (t8.type << 32) | (t9.type << 36) | (t10.type << 40) | (t11.type << 44) |
2545  (t12.type << 48) | (t13.type << 52) | (t14.type << 56);
2546 }
2547 #endif
2548 } // namespace internal
2549 
2550 # define FMT_MAKE_TEMPLATE_ARG(n) typename T##n
2551 # define FMT_MAKE_ARG_TYPE(n) T##n
2552 # define FMT_MAKE_ARG(n) const T##n &v##n
2553 # define FMT_ASSIGN_char(n) \
2554  arr[n] = fmt::internal::MakeValue< fmt::BasicFormatter<char> >(v##n)
2555 # define FMT_ASSIGN_wchar_t(n) \
2556  arr[n] = fmt::internal::MakeValue< fmt::BasicFormatter<wchar_t> >(v##n)
2557 
2558 #if FMT_USE_VARIADIC_TEMPLATES
2559 // Defines a variadic function returning void.
2560 # define FMT_VARIADIC_VOID(func, arg_type) \
2561  template <typename... Args> \
2562  void func(arg_type arg0, const Args & ... args) { \
2563  typedef fmt::internal::ArgArray<sizeof...(Args)> ArgArray; \
2564  typename ArgArray::Type array{ \
2565  ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \
2566  func(arg0, fmt::ArgList(fmt::internal::make_type(args...), array)); \
2567  }
2568 
2569 // Defines a variadic constructor.
2570 # define FMT_VARIADIC_CTOR(ctor, func, arg0_type, arg1_type) \
2571  template <typename... Args> \
2572  ctor(arg0_type arg0, arg1_type arg1, const Args & ... args) { \
2573  typedef fmt::internal::ArgArray<sizeof...(Args)> ArgArray; \
2574  typename ArgArray::Type array{ \
2575  ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \
2576  func(arg0, arg1, fmt::ArgList(fmt::internal::make_type(args...), array)); \
2577  }
2578 
2579 #else
2580 
2581 # define FMT_MAKE_REF(n) \
2582  fmt::internal::MakeValue< fmt::BasicFormatter<Char> >(v##n)
2583 # define FMT_MAKE_REF2(n) v##n
2584 
2585 // Defines a wrapper for a function taking one argument of type arg_type
2586 // and n additional arguments of arbitrary types.
2587 # define FMT_WRAP1(func, arg_type, n) \
2588  template <FMT_GEN(n, FMT_MAKE_TEMPLATE_ARG)> \
2589  inline void func(arg_type arg1, FMT_GEN(n, FMT_MAKE_ARG)) { \
2590  const fmt::internal::ArgArray<n>::Type array = {FMT_GEN(n, FMT_MAKE_REF)}; \
2591  func(arg1, fmt::ArgList( \
2592  fmt::internal::make_type(FMT_GEN(n, FMT_MAKE_REF2)), array)); \
2593  }
2594 
2595 // Emulates a variadic function returning void on a pre-C++11 compiler.
2596 # define FMT_VARIADIC_VOID(func, arg_type) \
2597  inline void func(arg_type arg) { func(arg, fmt::ArgList()); } \
2598  FMT_WRAP1(func, arg_type, 1) FMT_WRAP1(func, arg_type, 2) \
2599  FMT_WRAP1(func, arg_type, 3) FMT_WRAP1(func, arg_type, 4) \
2600  FMT_WRAP1(func, arg_type, 5) FMT_WRAP1(func, arg_type, 6) \
2601  FMT_WRAP1(func, arg_type, 7) FMT_WRAP1(func, arg_type, 8) \
2602  FMT_WRAP1(func, arg_type, 9) FMT_WRAP1(func, arg_type, 10)
2603 
2604 # define FMT_CTOR(ctor, func, arg0_type, arg1_type, n) \
2605  template <FMT_GEN(n, FMT_MAKE_TEMPLATE_ARG)> \
2606  ctor(arg0_type arg0, arg1_type arg1, FMT_GEN(n, FMT_MAKE_ARG)) { \
2607  const fmt::internal::ArgArray<n>::Type array = {FMT_GEN(n, FMT_MAKE_REF)}; \
2608  func(arg0, arg1, fmt::ArgList( \
2609  fmt::internal::make_type(FMT_GEN(n, FMT_MAKE_REF2)), array)); \
2610  }
2611 
2612 // Emulates a variadic constructor on a pre-C++11 compiler.
2613 # define FMT_VARIADIC_CTOR(ctor, func, arg0_type, arg1_type) \
2614  FMT_CTOR(ctor, func, arg0_type, arg1_type, 1) \
2615  FMT_CTOR(ctor, func, arg0_type, arg1_type, 2) \
2616  FMT_CTOR(ctor, func, arg0_type, arg1_type, 3) \
2617  FMT_CTOR(ctor, func, arg0_type, arg1_type, 4) \
2618  FMT_CTOR(ctor, func, arg0_type, arg1_type, 5) \
2619  FMT_CTOR(ctor, func, arg0_type, arg1_type, 6) \
2620  FMT_CTOR(ctor, func, arg0_type, arg1_type, 7) \
2621  FMT_CTOR(ctor, func, arg0_type, arg1_type, 8) \
2622  FMT_CTOR(ctor, func, arg0_type, arg1_type, 9) \
2623  FMT_CTOR(ctor, func, arg0_type, arg1_type, 10)
2624 #endif
2625 
2626 // Generates a comma-separated list with results of applying f to pairs
2627 // (argument, index).
2628 #define FMT_FOR_EACH1(f, x0) f(x0, 0)
2629 #define FMT_FOR_EACH2(f, x0, x1) \
2630  FMT_FOR_EACH1(f, x0), f(x1, 1)
2631 #define FMT_FOR_EACH3(f, x0, x1, x2) \
2632  FMT_FOR_EACH2(f, x0 ,x1), f(x2, 2)
2633 #define FMT_FOR_EACH4(f, x0, x1, x2, x3) \
2634  FMT_FOR_EACH3(f, x0, x1, x2), f(x3, 3)
2635 #define FMT_FOR_EACH5(f, x0, x1, x2, x3, x4) \
2636  FMT_FOR_EACH4(f, x0, x1, x2, x3), f(x4, 4)
2637 #define FMT_FOR_EACH6(f, x0, x1, x2, x3, x4, x5) \
2638  FMT_FOR_EACH5(f, x0, x1, x2, x3, x4), f(x5, 5)
2639 #define FMT_FOR_EACH7(f, x0, x1, x2, x3, x4, x5, x6) \
2640  FMT_FOR_EACH6(f, x0, x1, x2, x3, x4, x5), f(x6, 6)
2641 #define FMT_FOR_EACH8(f, x0, x1, x2, x3, x4, x5, x6, x7) \
2642  FMT_FOR_EACH7(f, x0, x1, x2, x3, x4, x5, x6), f(x7, 7)
2643 #define FMT_FOR_EACH9(f, x0, x1, x2, x3, x4, x5, x6, x7, x8) \
2644  FMT_FOR_EACH8(f, x0, x1, x2, x3, x4, x5, x6, x7), f(x8, 8)
2645 #define FMT_FOR_EACH10(f, x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) \
2646  FMT_FOR_EACH9(f, x0, x1, x2, x3, x4, x5, x6, x7, x8), f(x9, 9)
2647 
2653 {
2654 private:
2655  void init(int err_code, CStringRef format_str, ArgList args);
2656 
2657 protected:
2659 
2660  typedef char Char; // For FMT_VARIADIC_CTOR.
2661 
2663 
2664 public:
2690  SystemError(int error_code, CStringRef message)
2691  {
2692  init(error_code, message, ArgList());
2693  }
2694  FMT_VARIADIC_CTOR(SystemError, init, int, CStringRef)
2695 
2696  ~SystemError() throw();
2697 
2698  int error_code() const
2699  {
2700  return error_code_;
2701  }
2702 };
2703 
2722 template <typename Char>
2723 class BasicWriter
2724 {
2725 private:
2726  // Output buffer.
2728 
2730 
2732 
2733 #if FMT_SECURE_SCL
2734  // Returns pointer value.
2735  static Char *get(CharPtr p)
2736  {
2737  return p.base();
2738  }
2739 #else
2740  static Char *get(Char *p)
2741  {
2742  return p;
2743  }
2744 #endif
2745 
2746  // Fills the padding around the content and returns the pointer to the
2747  // content area.
2748  static CharPtr fill_padding(CharPtr buffer,
2749  unsigned total_size, std::size_t content_size, wchar_t fill);
2750 
2751  // Grows the buffer by n characters and returns a pointer to the newly
2752  // allocated area.
2753  CharPtr grow_buffer(std::size_t n)
2754  {
2755  std::size_t size = buffer_.size();
2756  buffer_.resize(size + n);
2757  return internal::make_ptr(&buffer_[size], n);
2758  }
2759 
2760  // Writes an unsigned decimal integer.
2761  template <typename UInt>
2762  Char *write_unsigned_decimal(UInt value, unsigned prefix_size = 0)
2763  {
2764  unsigned num_digits = internal::count_digits(value);
2765  Char *ptr = get(grow_buffer(prefix_size + num_digits));
2766  internal::format_decimal(ptr + prefix_size, value, num_digits);
2767  return ptr;
2768  }
2769 
2770  // Writes a decimal integer.
2771  template <typename Int>
2772  void write_decimal(Int value)
2773  {
2774  typedef typename internal::IntTraits<Int>::MainType MainType;
2775  MainType abs_value = static_cast<MainType>(value);
2776  if (internal::is_negative(value))
2777  {
2778  abs_value = 0 - abs_value;
2779  *write_unsigned_decimal(abs_value, 1) = '-';
2780  }
2781  else
2782  {
2783  write_unsigned_decimal(abs_value, 0);
2784  }
2785  }
2786 
2787  // Prepare a buffer for integer formatting.
2788  CharPtr prepare_int_buffer(unsigned num_digits,
2789  const EmptySpec &, const char *prefix, unsigned prefix_size)
2790  {
2791  unsigned size = prefix_size + num_digits;
2792  CharPtr p = grow_buffer(size);
2793  std::uninitialized_copy(prefix, prefix + prefix_size, p);
2794  return p + size - 1;
2795  }
2796 
2797  template <typename Spec>
2798  CharPtr prepare_int_buffer(unsigned num_digits,
2799  const Spec &spec, const char *prefix, unsigned prefix_size);
2800 
2801  // Formats an integer.
2802  template <typename T, typename Spec>
2803  void write_int(T value, Spec spec);
2804 
2805  // Formats a floating-point number (double or long double).
2806  template <typename T>
2807  void write_double(T value, const FormatSpec &spec);
2808 
2809  // Writes a formatted string.
2810  template <typename StrChar>
2811  CharPtr write_str(const StrChar *s, std::size_t size, const AlignSpec &spec);
2812 
2813  template <typename StrChar>
2814  void write_str(const internal::Arg::StringValue<StrChar> &str,
2815  const FormatSpec &spec);
2816 
2817  // This following methods are private to disallow writing wide characters
2818  // and strings to a char stream. If you want to print a wide string as a
2819  // pointer as std::ostream does, cast it to const void*.
2820  // Do not implement!
2821  void operator<<(typename internal::WCharHelper<wchar_t, Char>::Unsupported);
2822  void operator<<(
2824 
2825  // Appends floating-point length specifier to the format string.
2826  // The second argument is only used for overload resolution.
2827  void append_float_length(Char *&format_ptr, long double)
2828  {
2829  *format_ptr++ = 'L';
2830  }
2831 
2832  template<typename T>
2833  void append_float_length(Char *&, T) {}
2834 
2835  template <typename Impl, typename Char_>
2837 
2839 
2840 protected:
2844  explicit BasicWriter(Buffer<Char> &b) : buffer_(b) {}
2845 
2846 public:
2852  virtual ~BasicWriter() {}
2853 
2857  std::size_t size() const
2858  {
2859  return buffer_.size();
2860  }
2861 
2866  const Char *data() const FMT_NOEXCEPT
2867  {
2868  return &buffer_[0];
2869  }
2870 
2875  const Char *c_str() const
2876  {
2877  std::size_t size = buffer_.size();
2878  buffer_.reserve(size + 1);
2879  buffer_[size] = '\0';
2880  return &buffer_[0];
2881  }
2882 
2888  std::basic_string<Char> str() const
2889  {
2890  return std::basic_string<Char>(&buffer_[0], buffer_.size());
2891  }
2892 
2919  {
2920  BasicFormatter<Char>(args, *this).format(format);
2921  }
2923 
2924  BasicWriter &operator<<(int value)
2925  {
2926  write_decimal(value);
2927  return *this;
2928  }
2929  BasicWriter &operator<<(unsigned value)
2930  {
2931  return *this << IntFormatSpec<unsigned>(value);
2932  }
2934  {
2935  write_decimal(value);
2936  return *this;
2937  }
2938  BasicWriter &operator<<(unsigned long value)
2939  {
2940  return *this << IntFormatSpec<unsigned long>(value);
2941  }
2942  BasicWriter &operator<<(LongLong value)
2943  {
2944  write_decimal(value);
2945  return *this;
2946  }
2947 
2953  BasicWriter &operator<<(ULongLong value)
2954  {
2955  return *this << IntFormatSpec<ULongLong>(value);
2956  }
2957 
2958  BasicWriter &operator<<(double value)
2959  {
2960  write_double(value, FormatSpec());
2961  return *this;
2962  }
2963 
2970  BasicWriter &operator<<(long double value)
2971  {
2972  write_double(value, FormatSpec());
2973  return *this;
2974  }
2975 
2980  {
2981  buffer_.push_back(value);
2982  return *this;
2983  }
2984 
2987  {
2988  buffer_.push_back(value);
2989  return *this;
2990  }
2991 
2997  BasicWriter &operator<<(fmt::BasicStringRef<Char> value)
2998  {
2999  const Char *str = value.data();
3000  buffer_.append(str, str + value.size());
3001  return *this;
3002  }
3003 
3006  {
3007  const char *str = value.data();
3008  buffer_.append(str, str + value.size());
3009  return *this;
3010  }
3011 
3012  template <typename T, typename Spec, typename FillChar>
3013  BasicWriter &operator<<(IntFormatSpec<T, Spec, FillChar> spec)
3014  {
3016  write_int(spec.value(), spec);
3017  return *this;
3018  }
3019 
3020  template <typename StrChar>
3021  BasicWriter &operator<<(const StrFormatSpec<StrChar> &spec)
3022  {
3023  const StrChar *s = spec.str();
3024  write_str(s, std::char_traits<Char>::length(s), spec);
3025  return *this;
3026  }
3027 
3028  void clear() FMT_NOEXCEPT { buffer_.clear(); }
3029 
3030  Buffer<Char> &buffer() FMT_NOEXCEPT { return buffer_; }
3031 };
3032 
3033 template <typename Char>
3034 template <typename StrChar>
3036  const StrChar *s, std::size_t size, const AlignSpec &spec)
3037 {
3038  CharPtr out = CharPtr();
3039  if (spec.width() > size)
3040  {
3041  out = grow_buffer(spec.width());
3043  if (spec.align() == ALIGN_RIGHT)
3044  {
3045  std::uninitialized_fill_n(out, spec.width() - size, fill);
3046  out += spec.width() - size;
3047  }
3048  else if (spec.align() == ALIGN_CENTER)
3049  {
3050  out = fill_padding(out, spec.width(), size, fill);
3051  }
3052  else
3053  {
3054  std::uninitialized_fill_n(out + size, spec.width() - size, fill);
3055  }
3056  }
3057  else
3058  {
3059  out = grow_buffer(size);
3060  }
3061  std::uninitialized_copy(s, s + size, out);
3062  return out;
3063 }
3064 
3065 template <typename Char>
3066 template <typename StrChar>
3068  const internal::Arg::StringValue<StrChar> &s, const FormatSpec &spec)
3069 {
3070  // Check if StrChar is convertible to Char.
3072  if (spec.type_ && spec.type_ != 's')
3073  internal::report_unknown_type(spec.type_, "string");
3074  const StrChar *str_value = s.value;
3075  std::size_t str_size = s.size;
3076  if (str_size == 0)
3077  {
3078  if (!str_value)
3079  {
3080  FMT_THROW(FormatError("string pointer is null"));
3081  }
3082  }
3083  std::size_t precision = static_cast<std::size_t>(spec.precision_);
3084  if (spec.precision_ >= 0 && precision < str_size)
3085  str_size = precision;
3086  write_str(str_value, str_size, spec);
3087 }
3088 
3089 template <typename Char>
3092  CharPtr buffer, unsigned total_size,
3093  std::size_t content_size, wchar_t fill)
3094 {
3095  std::size_t padding = total_size - content_size;
3096  std::size_t left_padding = padding / 2;
3097  Char fill_char = internal::CharTraits<Char>::cast(fill);
3098  std::uninitialized_fill_n(buffer, left_padding, fill_char);
3099  buffer += left_padding;
3100  CharPtr content = buffer;
3101  std::uninitialized_fill_n(buffer + content_size,
3102  padding - left_padding, fill_char);
3103  return content;
3104 }
3105 
3106 template <typename Char>
3107 template <typename Spec>
3110  unsigned num_digits, const Spec &spec,
3111  const char *prefix, unsigned prefix_size)
3112 {
3113  unsigned width = spec.width();
3114  Alignment align = spec.align();
3115  Char fill = internal::CharTraits<Char>::cast(spec.fill());
3116  if (spec.precision() > static_cast<int>(num_digits))
3117  {
3118  // Octal prefix '0' is counted as a digit, so ignore it if precision
3119  // is specified.
3120  if (prefix_size > 0 && prefix[prefix_size - 1] == '0')
3121  --prefix_size;
3122  unsigned number_size =
3123  prefix_size + internal::to_unsigned(spec.precision());
3124  AlignSpec subspec(number_size, '0', ALIGN_NUMERIC);
3125  if (number_size >= width)
3126  return prepare_int_buffer(num_digits, subspec, prefix, prefix_size);
3127  buffer_.reserve(width);
3128  unsigned fill_size = width - number_size;
3129  if (align != ALIGN_LEFT)
3130  {
3131  CharPtr p = grow_buffer(fill_size);
3132  std::uninitialized_fill(p, p + fill_size, fill);
3133  }
3134  CharPtr result = prepare_int_buffer(
3135  num_digits, subspec, prefix, prefix_size);
3136  if (align == ALIGN_LEFT)
3137  {
3138  CharPtr p = grow_buffer(fill_size);
3139  std::uninitialized_fill(p, p + fill_size, fill);
3140  }
3141  return result;
3142  }
3143  unsigned size = prefix_size + num_digits;
3144  if (width <= size)
3145  {
3146  CharPtr p = grow_buffer(size);
3147  std::uninitialized_copy(prefix, prefix + prefix_size, p);
3148  return p + size - 1;
3149  }
3150  CharPtr p = grow_buffer(width);
3151  CharPtr end = p + width;
3152  if (align == ALIGN_LEFT)
3153  {
3154  std::uninitialized_copy(prefix, prefix + prefix_size, p);
3155  p += size;
3156  std::uninitialized_fill(p, end, fill);
3157  }
3158  else if (align == ALIGN_CENTER)
3159  {
3160  p = fill_padding(p, width, size, fill);
3161  std::uninitialized_copy(prefix, prefix + prefix_size, p);
3162  p += size;
3163  }
3164  else
3165  {
3166  if (align == ALIGN_NUMERIC)
3167  {
3168  if (prefix_size != 0)
3169  {
3170  p = std::uninitialized_copy(prefix, prefix + prefix_size, p);
3171  size -= prefix_size;
3172  }
3173  }
3174  else
3175  {
3176  std::uninitialized_copy(prefix, prefix + prefix_size, end - size);
3177  }
3178  std::uninitialized_fill(p, end - size, fill);
3179  p = end;
3180  }
3181  return p - 1;
3182 }
3183 
3184 template <typename Char>
3185 template <typename T, typename Spec>
3186 void BasicWriter<Char>::write_int(T value, Spec spec)
3187 {
3188  unsigned prefix_size = 0;
3189  typedef typename internal::IntTraits<T>::MainType UnsignedType;
3190  UnsignedType abs_value = static_cast<UnsignedType>(value);
3191  char prefix[4] = "";
3192  if (internal::is_negative(value))
3193  {
3194  prefix[0] = '-';
3195  ++prefix_size;
3196  abs_value = 0 - abs_value;
3197  }
3198  else if (spec.flag(SIGN_FLAG))
3199  {
3200  prefix[0] = spec.flag(PLUS_FLAG) ? '+' : ' ';
3201  ++prefix_size;
3202  }
3203  switch (spec.type())
3204  {
3205  case 0:
3206  case 'd':
3207  {
3208  unsigned num_digits = internal::count_digits(abs_value);
3209  CharPtr p = prepare_int_buffer(num_digits, spec, prefix, prefix_size) + 1;
3210  internal::format_decimal(get(p), abs_value, 0);
3211  break;
3212  }
3213  case 'x':
3214  case 'X':
3215  {
3216  UnsignedType n = abs_value;
3217  if (spec.flag(HASH_FLAG))
3218  {
3219  prefix[prefix_size++] = '0';
3220  prefix[prefix_size++] = spec.type();
3221  }
3222  unsigned num_digits = 0;
3223  do
3224  {
3225  ++num_digits;
3226  }
3227  while ((n >>= 4) != 0);
3228  Char *p = get(prepare_int_buffer(
3229  num_digits, spec, prefix, prefix_size));
3230  n = abs_value;
3231  const char *digits = spec.type() == 'x' ?
3232  "0123456789abcdef" : "0123456789ABCDEF";
3233  do
3234  {
3235  *p-- = digits[n & 0xf];
3236  }
3237  while ((n >>= 4) != 0);
3238  break;
3239  }
3240  case 'b':
3241  case 'B':
3242  {
3243  UnsignedType n = abs_value;
3244  if (spec.flag(HASH_FLAG))
3245  {
3246  prefix[prefix_size++] = '0';
3247  prefix[prefix_size++] = spec.type();
3248  }
3249  unsigned num_digits = 0;
3250  do
3251  {
3252  ++num_digits;
3253  }
3254  while ((n >>= 1) != 0);
3255  Char *p = get(prepare_int_buffer(num_digits, spec, prefix, prefix_size));
3256  n = abs_value;
3257  do
3258  {
3259  *p-- = static_cast<Char>('0' + (n & 1));
3260  }
3261  while ((n >>= 1) != 0);
3262  break;
3263  }
3264  case 'o':
3265  {
3266  UnsignedType n = abs_value;
3267  if (spec.flag(HASH_FLAG))
3268  prefix[prefix_size++] = '0';
3269  unsigned num_digits = 0;
3270  do
3271  {
3272  ++num_digits;
3273  }
3274  while ((n >>= 3) != 0);
3275  Char *p = get(prepare_int_buffer(num_digits, spec, prefix, prefix_size));
3276  n = abs_value;
3277  do
3278  {
3279  *p-- = static_cast<Char>('0' + (n & 7));
3280  }
3281  while ((n >>= 3) != 0);
3282  break;
3283  }
3284  case 'n':
3285  {
3286  unsigned num_digits = internal::count_digits(abs_value);
3287  fmt::StringRef sep = "";
3288 #ifndef ANDROID
3289  sep = internal::thousands_sep(std::localeconv());
3290 #endif
3291  unsigned size = static_cast<unsigned>(
3292  num_digits + sep.size() * ((num_digits - 1) / 3));
3293  CharPtr p = prepare_int_buffer(size, spec, prefix, prefix_size) + 1;
3294  internal::format_decimal(get(p), abs_value, 0, internal::ThousandsSep(sep));
3295  break;
3296  }
3297  default:
3299  spec.type(), spec.flag(CHAR_FLAG) ? "char" : "integer");
3300  break;
3301  }
3302 }
3303 
3304 template <typename Char>
3305 template <typename T>
3307 {
3308  // Check type.
3309  char type = spec.type();
3310  bool upper = false;
3311  switch (type)
3312  {
3313  case 0:
3314  type = 'g';
3315  break;
3316  case 'e':
3317  case 'f':
3318  case 'g':
3319  case 'a':
3320  break;
3321  case 'F':
3322 #if FMT_MSC_VER
3323  // MSVC's printf doesn't support 'F'.
3324  type = 'f';
3325 #endif
3326  // Fall through.
3327  case 'E':
3328  case 'G':
3329  case 'A':
3330  upper = true;
3331  break;
3332  default:
3333  internal::report_unknown_type(type, "double");
3334  break;
3335  }
3336 
3337  char sign = 0;
3338  // Use isnegative instead of value < 0 because the latter is always
3339  // false for NaN.
3340  if (internal::FPUtil::isnegative(static_cast<double>(value)))
3341  {
3342  sign = '-';
3343  value = -value;
3344  }
3345  else if (spec.flag(SIGN_FLAG))
3346  {
3347  sign = spec.flag(PLUS_FLAG) ? '+' : ' ';
3348  }
3349 
3350  if (internal::FPUtil::isnotanumber(value))
3351  {
3352  // Format NaN ourselves because sprintf's output is not consistent
3353  // across platforms.
3354  std::size_t nan_size = 4;
3355  const char *nan = upper ? " NAN" : " nan";
3356  if (!sign)
3357  {
3358  --nan_size;
3359  ++nan;
3360  }
3361  CharPtr out = write_str(nan, nan_size, spec);
3362  if (sign)
3363  *out = sign;
3364  return;
3365  }
3366 
3367  if (internal::FPUtil::isinfinity(value))
3368  {
3369  // Format infinity ourselves because sprintf's output is not consistent
3370  // across platforms.
3371  std::size_t inf_size = 4;
3372  const char *inf = upper ? " INF" : " inf";
3373  if (!sign)
3374  {
3375  --inf_size;
3376  ++inf;
3377  }
3378  CharPtr out = write_str(inf, inf_size, spec);
3379  if (sign)
3380  *out = sign;
3381  return;
3382  }
3383 
3384  std::size_t offset = buffer_.size();
3385  unsigned width = spec.width();
3386  if (sign)
3387  {
3388  buffer_.reserve(buffer_.size() + (width > 1u ? width : 1u));
3389  if (width > 0)
3390  --width;
3391  ++offset;
3392  }
3393 
3394  // Build format string.
3395  enum { MAX_FORMAT_SIZE = 10}; // longest format: %#-*.*Lg
3396  Char format[MAX_FORMAT_SIZE];
3397  Char *format_ptr = format;
3398  *format_ptr++ = '%';
3399  unsigned width_for_sprintf = width;
3400  if (spec.flag(HASH_FLAG))
3401  *format_ptr++ = '#';
3402  if (spec.align() == ALIGN_CENTER)
3403  {
3404  width_for_sprintf = 0;
3405  }
3406  else
3407  {
3408  if (spec.align() == ALIGN_LEFT)
3409  *format_ptr++ = '-';
3410  if (width != 0)
3411  *format_ptr++ = '*';
3412  }
3413  if (spec.precision() >= 0)
3414  {
3415  *format_ptr++ = '.';
3416  *format_ptr++ = '*';
3417  }
3418 
3419  append_float_length(format_ptr, value);
3420  *format_ptr++ = type;
3421  *format_ptr = '\0';
3422 
3423  // Format using snprintf.
3425  unsigned n = 0;
3426  Char *start = 0;
3427  for (;;)
3428  {
3429  std::size_t buffer_size = buffer_.capacity() - offset;
3430 #if FMT_MSC_VER
3431  // MSVC's vsnprintf_s doesn't work with zero size, so reserve
3432  // space for at least one extra character to make the size non-zero.
3433  // Note that the buffer's capacity will increase by more than 1.
3434  if (buffer_size == 0)
3435  {
3436  buffer_.reserve(offset + 1);
3437  buffer_size = buffer_.capacity() - offset;
3438  }
3439 #endif
3440  start = &buffer_[offset];
3442  start, buffer_size, format, width_for_sprintf, spec.precision(), value);
3443  if (result >= 0)
3444  {
3445  n = internal::to_unsigned(result);
3446  if (offset + n < buffer_.capacity())
3447  break; // The buffer is large enough - continue with formatting.
3448  buffer_.reserve(offset + n + 1);
3449  }
3450  else
3451  {
3452  // If result is negative we ask to increase the capacity by at least 1,
3453  // but as std::vector, the buffer grows exponentially.
3454  buffer_.reserve(buffer_.capacity() + 1);
3455  }
3456  }
3457  if (sign)
3458  {
3459  if ((spec.align() != ALIGN_RIGHT && spec.align() != ALIGN_DEFAULT) ||
3460  *start != ' ')
3461  {
3462  *(start - 1) = sign;
3463  sign = 0;
3464  }
3465  else
3466  {
3467  *(start - 1) = fill;
3468  }
3469  ++n;
3470  }
3471  if (spec.align() == ALIGN_CENTER && spec.width() > n)
3472  {
3473  width = spec.width();
3474  CharPtr p = grow_buffer(width);
3475  std::memmove(get(p) + (width - n) / 2, get(p), n * sizeof(Char));
3476  fill_padding(p, spec.width(), n, fill);
3477  return;
3478  }
3479  if (spec.fill() != ' ' || sign)
3480  {
3481  while (*start == ' ')
3482  *start++ = fill;
3483  if (sign)
3484  *(start - 1) = sign;
3485  }
3486  grow_buffer(n);
3487 }
3488 
3523 template <typename Char, typename Allocator = std::allocator<Char> >
3524 class BasicMemoryWriter : public BasicWriter<Char>
3525 {
3526 private:
3528 
3529 public:
3530  explicit BasicMemoryWriter(const Allocator& alloc = Allocator())
3531  : BasicWriter<Char>(buffer_), buffer_(alloc) {}
3532 
3533 #if FMT_USE_RVALUE_REFERENCES
3534 
3541  : BasicWriter<Char>(buffer_), buffer_(std::move(other.buffer_))
3542  {
3543  }
3544 
3550  BasicMemoryWriter &operator=(BasicMemoryWriter &&other)
3551  {
3552  buffer_ = std::move(other.buffer_);
3553  return *this;
3554  }
3555 #endif
3556 };
3557 
3560 
3581 template <typename Char>
3582 class BasicArrayWriter : public BasicWriter<Char>
3583 {
3584 private:
3586 
3587 public:
3594  BasicArrayWriter(Char *array, std::size_t size)
3595  : BasicWriter<Char>(buffer_), buffer_(array, size) {}
3596 
3603  template <std::size_t SIZE>
3604  explicit BasicArrayWriter(Char (&array)[SIZE])
3605  : BasicWriter<Char>(buffer_), buffer_(array, SIZE) {}
3606 };
3607 
3610 
3611 // Reports a system error without throwing an exception.
3612 // Can be used to report errors from destructors.
3613 FMT_API void report_system_error(int error_code,
3614  StringRef message) FMT_NOEXCEPT;
3615 
3616 #if FMT_USE_WINDOWS_H
3617 
3619 class WindowsError : public SystemError
3620 {
3621 private:
3622  FMT_API void init(int error_code, CStringRef format_str, ArgList args);
3623 
3624 public:
3653  WindowsError(int error_code, CStringRef message)
3654  {
3655  init(error_code, message, ArgList());
3656  }
3657  FMT_VARIADIC_CTOR(WindowsError, init, int, CStringRef)
3658 };
3659 
3660 // Reports a Windows error without throwing an exception.
3661 // Can be used to report errors from destructors.
3662 FMT_API void report_windows_error(int error_code,
3663  StringRef message) FMT_NOEXCEPT;
3664 
3665 #endif
3666 
3668 
3675 FMT_API void print_colored(Color c, CStringRef format, ArgList args);
3676 
3686 inline std::string format(CStringRef format_str, ArgList args)
3687 {
3688  MemoryWriter w;
3689  w.write(format_str, args);
3690  return w.str();
3691 }
3692 
3693 inline std::wstring format(WCStringRef format_str, ArgList args)
3694 {
3695  WMemoryWriter w;
3696  w.write(format_str, args);
3697  return w.str();
3698 }
3699 
3709 FMT_API void print(std::FILE *f, CStringRef format_str, ArgList args);
3710 
3720 FMT_API void print(CStringRef format_str, ArgList args);
3721 
3722 template <typename Char>
3724 {
3725  internal::PrintfFormatter<Char>(args).format(w, format);
3726 }
3727 
3737 inline std::string sprintf(CStringRef format, ArgList args)
3738 {
3739  MemoryWriter w;
3740  printf(w, format, args);
3741  return w.str();
3742 }
3743 
3744 inline std::wstring sprintf(WCStringRef format, ArgList args)
3745 {
3746  WMemoryWriter w;
3747  printf(w, format, args);
3748  return w.str();
3749 }
3750 
3760 FMT_API int fprintf(std::FILE *f, CStringRef format, ArgList args);
3761 
3771 inline int printf(CStringRef format, ArgList args)
3772 {
3773  return fprintf(stdout, format, args);
3774 }
3775 
3780 {
3781 private:
3782  // Buffer should be large enough to hold all digits (digits10 + 1),
3783  // a sign and a null character.
3784  enum {BUFFER_SIZE = std::numeric_limits<ULongLong>::digits10 + 3};
3785  mutable char buffer_[BUFFER_SIZE];
3786  char *str_;
3787 
3788  // Formats value in reverse and returns the number of digits.
3789  char *format_decimal(ULongLong value)
3790  {
3791  char *buffer_end = buffer_ + BUFFER_SIZE - 1;
3792  while (value >= 100)
3793  {
3794  // Integer division is slow so do it for a group of two digits instead
3795  // of for every digit. The idea comes from the talk by Alexandrescu
3796  // "Three Optimization Tips for C++". See speed-test for a comparison.
3797  unsigned index = static_cast<unsigned>((value % 100) * 2);
3798  value /= 100;
3799  *--buffer_end = internal::Data::DIGITS[index + 1];
3800  *--buffer_end = internal::Data::DIGITS[index];
3801  }
3802  if (value < 10)
3803  {
3804  *--buffer_end = static_cast<char>('0' + value);
3805  return buffer_end;
3806  }
3807  unsigned index = static_cast<unsigned>(value * 2);
3808  *--buffer_end = internal::Data::DIGITS[index + 1];
3809  *--buffer_end = internal::Data::DIGITS[index];
3810  return buffer_end;
3811  }
3812 
3813  void FormatSigned(LongLong value)
3814  {
3815  ULongLong abs_value = static_cast<ULongLong>(value);
3816  bool negative = value < 0;
3817  if (negative)
3818  abs_value = 0 - abs_value;
3819  str_ = format_decimal(abs_value);
3820  if (negative)
3821  *--str_ = '-';
3822  }
3823 
3824 public:
3825  explicit FormatInt(int value)
3826  {
3827  FormatSigned(value);
3828  }
3829  explicit FormatInt(long value)
3830  {
3831  FormatSigned(value);
3832  }
3833  explicit FormatInt(LongLong value)
3834  {
3835  FormatSigned(value);
3836  }
3837  explicit FormatInt(unsigned value) : str_(format_decimal(value)) {}
3838  explicit FormatInt(unsigned long value) : str_(format_decimal(value)) {}
3839  explicit FormatInt(ULongLong value) : str_(format_decimal(value)) {}
3840 
3842  std::size_t size() const
3843  {
3844  return internal::to_unsigned(buffer_ - str_ + BUFFER_SIZE - 1);
3845  }
3846 
3851  const char *data() const
3852  {
3853  return str_;
3854  }
3855 
3860  const char *c_str() const
3861  {
3862  buffer_[BUFFER_SIZE - 1] = '\0';
3863  return str_;
3864  }
3865 
3872  {
3873  return std::string(str_, size());
3874  }
3875 };
3876 
3877 // Formats a decimal integer value writing into buffer and returns
3878 // a pointer to the end of the formatted string. This function doesn't
3879 // write a terminating null character.
3880 template <typename T>
3881 inline void format_decimal(char *&buffer, T value)
3882 {
3883  typedef typename internal::IntTraits<T>::MainType MainType;
3884  MainType abs_value = static_cast<MainType>(value);
3885  if (internal::is_negative(value))
3886  {
3887  *buffer++ = '-';
3888  abs_value = 0 - abs_value;
3889  }
3890  if (abs_value < 100)
3891  {
3892  if (abs_value < 10)
3893  {
3894  *buffer++ = static_cast<char>('0' + abs_value);
3895  return;
3896  }
3897  unsigned index = static_cast<unsigned>(abs_value * 2);
3898  *buffer++ = internal::Data::DIGITS[index];
3899  *buffer++ = internal::Data::DIGITS[index + 1];
3900  return;
3901  }
3902  unsigned num_digits = internal::count_digits(abs_value);
3903  internal::format_decimal(buffer, abs_value, num_digits);
3904  buffer += num_digits;
3905 }
3906 
3917 template <typename T>
3918 inline internal::NamedArg<char> arg(StringRef name, const T &arg)
3919 {
3921 }
3922 
3923 template <typename T>
3924 inline internal::NamedArg<wchar_t> arg(WStringRef name, const T &arg)
3925 {
3927 }
3928 
3929 // The following two functions are deleted intentionally to disable
3930 // nested named arguments as in ``format("{}", arg("a", arg("b", 42)))``.
3931 template <typename Char>
3932 void arg(StringRef, const internal::NamedArg<Char>&) FMT_DELETED_OR_UNDEFINED;
3933 template <typename Char>
3934 void arg(WStringRef, const internal::NamedArg<Char>&) FMT_DELETED_OR_UNDEFINED;
3935 }
3936 
3937 #if FMT_GCC_VERSION
3938 // Use the system_header pragma to suppress warnings about variadic macros
3939 // because suppressing -Wvariadic-macros with the diagnostic pragma doesn't
3940 // work. It is used at the end because we want to suppress as little warnings
3941 // as possible.
3942 # pragma GCC system_header
3943 #endif
3944 
3945 // This is used to work around VC++ bugs in handling variadic macros.
3946 #define FMT_EXPAND(args) args
3947 
3948 // Returns the number of arguments.
3949 // Based on https://groups.google.com/forum/#!topic/comp.std.c/d-6Mj5Lko_s.
3950 #define FMT_NARG(...) FMT_NARG_(__VA_ARGS__, FMT_RSEQ_N())
3951 #define FMT_NARG_(...) FMT_EXPAND(FMT_ARG_N(__VA_ARGS__))
3952 #define FMT_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
3953 #define FMT_RSEQ_N() 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
3954 
3955 #define FMT_CONCAT(a, b) a##b
3956 #define FMT_FOR_EACH_(N, f, ...) \
3957  FMT_EXPAND(FMT_CONCAT(FMT_FOR_EACH, N)(f, __VA_ARGS__))
3958 #define FMT_FOR_EACH(f, ...) \
3959  FMT_EXPAND(FMT_FOR_EACH_(FMT_NARG(__VA_ARGS__), f, __VA_ARGS__))
3960 
3961 #define FMT_ADD_ARG_NAME(type, index) type arg##index
3962 #define FMT_GET_ARG_NAME(type, index) arg##index
3963 
3964 #if FMT_USE_VARIADIC_TEMPLATES
3965 # define FMT_VARIADIC_(Char, ReturnType, func, call, ...) \
3966  template <typename... Args> \
3967  ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), \
3968  const Args & ... args) { \
3969  typedef fmt::internal::ArgArray<sizeof...(Args)> ArgArray; \
3970  typename ArgArray::Type array{ \
3971  ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \
3972  call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), \
3973  fmt::ArgList(fmt::internal::make_type(args...), array)); \
3974  }
3975 #else
3976 // Defines a wrapper for a function taking __VA_ARGS__ arguments
3977 // and n additional arguments of arbitrary types.
3978 # define FMT_WRAP(Char, ReturnType, func, call, n, ...) \
3979  template <FMT_GEN(n, FMT_MAKE_TEMPLATE_ARG)> \
3980  inline ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), \
3981  FMT_GEN(n, FMT_MAKE_ARG)) { \
3982  fmt::internal::ArgArray<n>::Type arr; \
3983  FMT_GEN(n, FMT_ASSIGN_##Char); \
3984  call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), fmt::ArgList( \
3985  fmt::internal::make_type(FMT_GEN(n, FMT_MAKE_REF2)), arr)); \
3986  }
3987 
3988 # define FMT_VARIADIC_(Char, ReturnType, func, call, ...) \
3989  inline ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__)) { \
3990  call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), fmt::ArgList()); \
3991  } \
3992  FMT_WRAP(Char, ReturnType, func, call, 1, __VA_ARGS__) \
3993  FMT_WRAP(Char, ReturnType, func, call, 2, __VA_ARGS__) \
3994  FMT_WRAP(Char, ReturnType, func, call, 3, __VA_ARGS__) \
3995  FMT_WRAP(Char, ReturnType, func, call, 4, __VA_ARGS__) \
3996  FMT_WRAP(Char, ReturnType, func, call, 5, __VA_ARGS__) \
3997  FMT_WRAP(Char, ReturnType, func, call, 6, __VA_ARGS__) \
3998  FMT_WRAP(Char, ReturnType, func, call, 7, __VA_ARGS__) \
3999  FMT_WRAP(Char, ReturnType, func, call, 8, __VA_ARGS__) \
4000  FMT_WRAP(Char, ReturnType, func, call, 9, __VA_ARGS__) \
4001  FMT_WRAP(Char, ReturnType, func, call, 10, __VA_ARGS__) \
4002  FMT_WRAP(Char, ReturnType, func, call, 11, __VA_ARGS__) \
4003  FMT_WRAP(Char, ReturnType, func, call, 12, __VA_ARGS__) \
4004  FMT_WRAP(Char, ReturnType, func, call, 13, __VA_ARGS__) \
4005  FMT_WRAP(Char, ReturnType, func, call, 14, __VA_ARGS__) \
4006  FMT_WRAP(Char, ReturnType, func, call, 15, __VA_ARGS__)
4007 #endif // FMT_USE_VARIADIC_TEMPLATES
4008 
4036 #define FMT_VARIADIC(ReturnType, func, ...) \
4037  FMT_VARIADIC_(char, ReturnType, func, return func, __VA_ARGS__)
4038 
4039 #define FMT_VARIADIC_W(ReturnType, func, ...) \
4040  FMT_VARIADIC_(wchar_t, ReturnType, func, return func, __VA_ARGS__)
4041 
4042 #define FMT_CAPTURE_ARG_(id, index) ::fmt::arg(#id, id)
4043 
4044 #define FMT_CAPTURE_ARG_W_(id, index) ::fmt::arg(L###id, id)
4045 
4060 #define FMT_CAPTURE(...) FMT_FOR_EACH(FMT_CAPTURE_ARG_, __VA_ARGS__)
4061 
4062 #define FMT_CAPTURE_W(...) FMT_FOR_EACH(FMT_CAPTURE_ARG_W_, __VA_ARGS__)
4063 
4064 namespace fmt
4065 {
4066 FMT_VARIADIC(std::string, format, CStringRef)
4067 FMT_VARIADIC_W(std::wstring, format, WCStringRef)
4068 FMT_VARIADIC(void, print, CStringRef)
4069 FMT_VARIADIC(void, print, std::FILE *, CStringRef)
4070 
4071 FMT_VARIADIC(void, print_colored, Color, CStringRef)
4072 FMT_VARIADIC(std::string, sprintf, CStringRef)
4073 FMT_VARIADIC_W(std::wstring, sprintf, WCStringRef)
4074 FMT_VARIADIC(int, printf, CStringRef)
4075 FMT_VARIADIC(int, fprintf, std::FILE *, CStringRef)
4076 
4077 namespace internal
4078 {
4079 template <typename Char>
4080 inline bool is_name_start(Char c)
4081 {
4082  return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || '_' == c;
4083 }
4084 
4085 // Parses an unsigned integer advancing s to the end of the parsed input.
4086 // This function assumes that the first character of s is a digit.
4087 template <typename Char>
4088 unsigned parse_nonnegative_int(const Char *&s)
4089 {
4090  assert('0' <= *s && *s <= '9');
4091  unsigned value = 0;
4092  do
4093  {
4094  unsigned new_value = value * 10 + (*s++ - '0');
4095  // Check if value wrapped around.
4096  if (new_value < value)
4097  {
4098  value = (std::numeric_limits<unsigned>::max)();
4099  break;
4100  }
4101  value = new_value;
4102  }
4103  while ('0' <= *s && *s <= '9');
4104  // Convert to unsigned to prevent a warning.
4105  unsigned max_int = (std::numeric_limits<int>::max)();
4106  if (value > max_int)
4107  FMT_THROW(FormatError("number is too big"));
4108  return value;
4109 }
4110 
4111 inline void require_numeric_argument(const Arg &arg, char spec)
4112 {
4113  if (arg.type > Arg::LAST_NUMERIC_TYPE)
4114  {
4115  std::string message =
4116  fmt::format("format specifier '{}' requires numeric argument", spec);
4117  FMT_THROW(fmt::FormatError(message));
4118  }
4119 }
4120 
4121 template <typename Char>
4122 void check_sign(const Char *&s, const Arg &arg)
4123 {
4124  char sign = static_cast<char>(*s);
4125  require_numeric_argument(arg, sign);
4126  if (arg.type == Arg::UINT || arg.type == Arg::ULONG_LONG)
4127  {
4129  "format specifier '{}' requires signed argument", sign)));
4130  }
4131  ++s;
4132 }
4133 } // namespace internal
4134 
4135 template <typename Char, typename AF>
4137  BasicStringRef<Char> arg_name, const char *&error)
4138 {
4139  if (check_no_auto_index(error))
4140  {
4141  map_.init(args());
4142  const internal::Arg *arg = map_.find(arg_name);
4143  if (arg)
4144  return *arg;
4145  error = "argument not found";
4146  }
4147  return internal::Arg();
4148 }
4149 
4150 template <typename Char, typename AF>
4152 {
4153  const char *error = 0;
4154  internal::Arg arg = *s < '0' || *s > '9' ?
4155  next_arg(error) : get_arg(internal::parse_nonnegative_int(s), error);
4156  if (error)
4157  {
4159  *s != '}' && *s != ':' ? "invalid format string" : error));
4160  }
4161  return arg;
4162 }
4163 
4164 template <typename Char, typename AF>
4166 {
4167  assert(internal::is_name_start(*s));
4168  const Char *start = s;
4169  Char c;
4170  do
4171  {
4172  c = *++s;
4173  }
4174  while (internal::is_name_start(c) || ('0' <= c && c <= '9'));
4175  const char *error = 0;
4176  internal::Arg arg = get_arg(BasicStringRef<Char>(start, s - start), error);
4177  if (error)
4178  FMT_THROW(FormatError(error));
4179  return arg;
4180 }
4181 
4182 template <typename Char, typename ArgFormatter>
4184  const Char *&format_str, const internal::Arg &arg)
4185 {
4186  using internal::Arg;
4187  const Char *s = format_str;
4188  FormatSpec spec;
4189  if (*s == ':')
4190  {
4191  if (arg.type == Arg::CUSTOM)
4192  {
4193  arg.custom.format(this, arg.custom.value, &s);
4194  return s;
4195  }
4196  ++s;
4197  // Parse fill and alignment.
4198  if (Char c = *s)
4199  {
4200  const Char *p = s + 1;
4201  spec.align_ = ALIGN_DEFAULT;
4202  do
4203  {
4204  switch (*p)
4205  {
4206  case '<':
4207  spec.align_ = ALIGN_LEFT;
4208  break;
4209  case '>':
4210  spec.align_ = ALIGN_RIGHT;
4211  break;
4212  case '=':
4213  spec.align_ = ALIGN_NUMERIC;
4214  break;
4215  case '^':
4216  spec.align_ = ALIGN_CENTER;
4217  break;
4218  }
4219  if (spec.align_ != ALIGN_DEFAULT)
4220  {
4221  if (p != s)
4222  {
4223  if (c == '}') break;
4224  if (c == '{')
4225  FMT_THROW(FormatError("invalid fill character '{'"));
4226  s += 2;
4227  spec.fill_ = c;
4228  }
4229  else ++s;
4230  if (spec.align_ == ALIGN_NUMERIC)
4231  require_numeric_argument(arg, '=');
4232  break;
4233  }
4234  }
4235  while (--p >= s);
4236  }
4237 
4238  // Parse sign.
4239  switch (*s)
4240  {
4241  case '+':
4242  check_sign(s, arg);
4243  spec.flags_ |= SIGN_FLAG | PLUS_FLAG;
4244  break;
4245  case '-':
4246  check_sign(s, arg);
4247  spec.flags_ |= MINUS_FLAG;
4248  break;
4249  case ' ':
4250  check_sign(s, arg);
4251  spec.flags_ |= SIGN_FLAG;
4252  break;
4253  }
4254 
4255  if (*s == '#')
4256  {
4257  require_numeric_argument(arg, '#');
4258  spec.flags_ |= HASH_FLAG;
4259  ++s;
4260  }
4261 
4262  // Parse zero flag.
4263  if (*s == '0')
4264  {
4265  require_numeric_argument(arg, '0');
4266  spec.align_ = ALIGN_NUMERIC;
4267  spec.fill_ = '0';
4268  ++s;
4269  }
4270 
4271  // Parse width.
4272  if ('0' <= *s && *s <= '9')
4273  {
4275  }
4276  else if (*s == '{')
4277  {
4278  ++s;
4279  Arg width_arg = internal::is_name_start(*s) ?
4280  parse_arg_name(s) : parse_arg_index(s);
4281  if (*s++ != '}')
4282  FMT_THROW(FormatError("invalid format string"));
4283  ULongLong value = 0;
4284  switch (width_arg.type)
4285  {
4286  case Arg::INT:
4287  if (width_arg.int_value < 0)
4288  FMT_THROW(FormatError("negative width"));
4289  value = width_arg.int_value;
4290  break;
4291  case Arg::UINT:
4292  value = width_arg.uint_value;
4293  break;
4294  case Arg::LONG_LONG:
4295  if (width_arg.long_long_value < 0)
4296  FMT_THROW(FormatError("negative width"));
4297  value = width_arg.long_long_value;
4298  break;
4299  case Arg::ULONG_LONG:
4300  value = width_arg.ulong_long_value;
4301  break;
4302  default:
4303  FMT_THROW(FormatError("width is not integer"));
4304  }
4305  if (value > (std::numeric_limits<int>::max)())
4306  FMT_THROW(FormatError("number is too big"));
4307  spec.width_ = static_cast<int>(value);
4308  }
4309 
4310  // Parse precision.
4311  if (*s == '.')
4312  {
4313  ++s;
4314  spec.precision_ = 0;
4315  if ('0' <= *s && *s <= '9')
4316  {
4318  }
4319  else if (*s == '{')
4320  {
4321  ++s;
4322  Arg precision_arg = internal::is_name_start(*s) ?
4323  parse_arg_name(s) : parse_arg_index(s);
4324  if (*s++ != '}')
4325  FMT_THROW(FormatError("invalid format string"));
4326  ULongLong value = 0;
4327  switch (precision_arg.type)
4328  {
4329  case Arg::INT:
4330  if (precision_arg.int_value < 0)
4331  FMT_THROW(FormatError("negative precision"));
4332  value = precision_arg.int_value;
4333  break;
4334  case Arg::UINT:
4335  value = precision_arg.uint_value;
4336  break;
4337  case Arg::LONG_LONG:
4338  if (precision_arg.long_long_value < 0)
4339  FMT_THROW(FormatError("negative precision"));
4340  value = precision_arg.long_long_value;
4341  break;
4342  case Arg::ULONG_LONG:
4343  value = precision_arg.ulong_long_value;
4344  break;
4345  default:
4346  FMT_THROW(FormatError("precision is not integer"));
4347  }
4348  if (value > (std::numeric_limits<int>::max)())
4349  FMT_THROW(FormatError("number is too big"));
4350  spec.precision_ = static_cast<int>(value);
4351  }
4352  else
4353  {
4354  FMT_THROW(FormatError("missing precision specifier"));
4355  }
4356  if (arg.type <= Arg::LAST_INTEGER_TYPE || arg.type == Arg::POINTER)
4357  {
4359  fmt::format("precision not allowed in {} format specifier",
4360  arg.type == Arg::POINTER ? "pointer" : "integer")));
4361  }
4362  }
4363 
4364  // Parse type.
4365  if (*s != '}' && *s)
4366  spec.type_ = static_cast<char>(*s++);
4367  }
4368 
4369  if (*s++ != '}')
4370  FMT_THROW(FormatError("missing '}' in format string"));
4371 
4372  // Format argument.
4373  ArgFormatter(*this, spec, s - 1).visit(arg);
4374  return s;
4375 }
4376 
4377 template <typename Char, typename AF>
4379 {
4380  const Char *s = format_str.c_str();
4381  const Char *start = s;
4382  while (*s)
4383  {
4384  Char c = *s++;
4385  if (c != '{' && c != '}') continue;
4386  if (*s == c)
4387  {
4388  write(writer_, start, s);
4389  start = ++s;
4390  continue;
4391  }
4392  if (c == '}')
4393  FMT_THROW(FormatError("unmatched '}' in format string"));
4394  write(writer_, start, s - 1);
4396  parse_arg_name(s) : parse_arg_index(s);
4397  start = s = format(s, arg);
4398  }
4399  write(writer_, start, s);
4400 }
4401 } // namespace fmt
4402 
4403 #if FMT_USE_USER_DEFINED_LITERALS
4404 namespace fmt
4405 {
4406 namespace internal
4407 {
4408 
4409 template <typename Char>
4410 struct UdlFormat
4411 {
4412  const Char *str;
4413 
4414  template <typename... Args>
4415  auto operator()(Args && ... args) const
4416  -> decltype(format(str, std::forward<Args>(args)...))
4417  {
4418  return format(str, std::forward<Args>(args)...);
4419  }
4420 };
4421 
4422 template <typename Char>
4423 struct UdlArg
4424 {
4425  const Char *str;
4426 
4427  template <typename T>
4428  NamedArg<Char> operator=(T &&value) const
4429  {
4430  return {str, std::forward<T>(value)};
4431  }
4432 };
4433 
4434 } // namespace internal
4435 
4436 inline namespace literals
4437 {
4438 
4449 inline internal::UdlFormat<char>
4450 operator"" _format(const char *s, std::size_t)
4451 {
4452  return {s};
4453 }
4454 inline internal::UdlFormat<wchar_t>
4455 operator"" _format(const wchar_t *s, std::size_t)
4456 {
4457  return {s};
4458 }
4459 
4470 inline internal::UdlArg<char>
4471 operator"" _a(const char *s, std::size_t)
4472 {
4473  return {s};
4474 }
4475 inline internal::UdlArg<wchar_t>
4476 operator"" _a(const wchar_t *s, std::size_t)
4477 {
4478  return {s};
4479 }
4480 
4481 } // inline namespace literals
4482 } // namespace fmt
4483 #endif // FMT_USE_USER_DEFINED_LITERALS
4484 
4485 // Restore warnings.
4486 #if FMT_GCC_VERSION >= 406
4487 # pragma GCC diagnostic pop
4488 #endif
4489 
4490 #if defined(__clang__) && !defined(FMT_ICC_VERSION)
4491 # pragma clang diagnostic pop
4492 #endif
4493 
4494 #ifdef FMT_HEADER_ONLY
4495 # define FMT_FUNC inline
4496 # include "format.cc"
4497 #else
4498 # define FMT_FUNC
4499 #endif
4500 
4501 #endif // FMT_FORMAT_H_
CharPtr prepare_int_buffer(unsigned num_digits, const EmptySpec &, const char *prefix, unsigned prefix_size)
Definition: format.h:2788
BasicCStringRef(const Char *s)
Definition: format.h:584
void format_decimal(Char *buffer, UInt value, unsigned num_digits, ThousandsSep thousands_sep)
Definition: format.h:1068
internal::Arg parse_arg_name(const Char *&s)
Definition: format.h:4165
Result visit_bool(bool value)
Definition: format.h:1712
AlignTypeSpec(unsigned width, wchar_t fill)
Definition: format.h:1914
static const char DIGITS[]
Definition: format.h:980
#define FMT_GCC_EXTENSION
Definition: format.h:97
#define FMT_MAKE_VALUE_(Type, field, TYPE, rhs)
Definition: format.h:1409
FormatInt(unsigned long value)
Definition: format.h:3838
MakeValue(typename WCharHelper< wchar_t, Char >::Supported value)
Definition: format.h:1459
BasicStringRef(const Char *s)
Definition: format.h:479
MapType::value_type Pair
Definition: format.h:2119
StrFormatSpec(const Char *str, unsigned width, FillChar fill)
Definition: format.h:1977
BasicWriter< Char > & writer()
Definition: format.h:2156
StringRef thousands_sep(LConv *lc, LConvCheck< char *LConv::*,&LConv::thousands_sep >=0)
Definition: format.h:1343
const T & operator[](std::size_t index) const
Definition: format.h:741
Buffer< Char > & buffer_
Definition: format.h:2727
int precision() const
Definition: format.h:1941
#define FMT_NOEXCEPT
Definition: format.h:190
ArgFormatterBase(BasicWriter< Char > &w, FormatSpec &s)
Definition: format.h:2179
ArgType(const T &arg)
Definition: format.h:2535
static const uint32_t POWERS_OF_10_32[]
Definition: format.h:978
bool is_negative(T value)
Definition: format.h:944
#define FMT_ASSERT(condition, message)
Definition: format.h:240
void visit_custom(internal::Arg::CustomValue c)
Definition: format.h:2385
Alignment align_
Definition: format.h:1894
const Char * data() const
Definition: format.h:501
FMT_API void format_system_error(fmt::Writer &out, int error_code, fmt::StringRef message) FMT_NOEXCEPT
Definition: format.cc:600
int * count
static void format_custom_arg(void *formatter, const void *arg, void *format_str_ptr)
Definition: format.h:1398
std::size_t size_
Definition: format.h:674
ROSCPP_DECL void start()
static bool is_negative(T value)
Definition: format.h:925
#define FMT_VARIADIC(ReturnType, func,...)
Definition: format.h:4036
void resize(std::size_t new_size)
Definition: format.h:706
Alignment align() const
Definition: format.h:1845
friend bool operator!=(BasicStringRef lhs, BasicStringRef rhs)
Definition: format.h:526
int precision() const
Definition: format.h:1904
friend bool operator<=(BasicStringRef lhs, BasicStringRef rhs)
Definition: format.h:534
char Yes[1]
Definition: format.h:1252
Result visit_ulong_long(ULongLong value)
Definition: format.h:1706
IntFormatSpec< int, AlignTypeSpec< TYPE_CODE >, Char > pad(int value, unsigned width, Char fill= ' ')
wchar_t fill_
Definition: format.h:1877
f
IntFormatSpec< int, TypeSpec<'x'> > hex(int value)
BasicWriter(Buffer< Char > &b)
Definition: format.h:2844
Result visit_pointer(const void *)
Definition: format.h:1768
FMT_API void print(std::FILE *f, CStringRef format_str, ArgList args)
Definition: format.cc:873
#define FMT_MAKE_WSTR_VALUE(Type, TYPE)
Definition: format.h:1483
Arg next_arg(const char *&error)
Definition: format.h:2290
#define FMT_MAKE_VALUE(Type, field, TYPE)
Definition: format.h:1413
uint64_t make_type()
Definition: format.h:2473
IntFormatSpec< int, TypeSpec<'o'> > oct(int value)
WidthSpec(unsigned width, wchar_t fill)
Definition: format.h:1879
T * make_ptr(T *ptr, std::size_t)
Definition: format.h:654
FMT_API void report_unknown_type(char code, const char *type)
Definition: format.cc:509
FormatSpec & spec_
Definition: format.cc:245
friend bool operator<(BasicStringRef lhs, BasicStringRef rhs)
Definition: format.h:530
void visit_wstring(Arg::StringValue< Char > value)
Definition: format.h:2255
void write(const char *value)
Definition: format.h:2172
const char * c_str() const
Definition: format.h:3860
void init(const M_string &remappings)
BasicWriter< Char > & writer_
Definition: format.h:2143
internal::FixedBuffer< Char > buffer_
Definition: format.h:3585
Result visit_any_double(T)
Definition: format.h:1744
void operator()(Char *&buffer)
Definition: format.h:1054
BasicArgFormatter(BasicFormatter< Char, Impl > &formatter, FormatSpec &spec, const Char *fmt)
Definition: format.h:2379
void write(BasicCStringRef< Char > format, ArgList args)
Definition: format.h:2918
static wchar_t convert(char value)
Definition: format.h:906
void visit_bool(bool value)
Definition: format.h:2194
std::string format(CStringRef format_str, ArgList args)
Definition: format.h:3686
XmlRpcServer s
BasicWriter & operator<<(unsigned long value)
Definition: format.h:2938
#define FMT_DISPATCH(call)
Definition: format.h:1646
FormatInt(ULongLong value)
Definition: format.h:3839
T const_check(T value)
Definition: format.h:351
std::size_t capacity() const
Definition: format.h:698
unsigned width_
Definition: format.h:1874
fmt::StringRef sep_
Definition: format.h:1045
BasicArrayWriter(Char *array, std::size_t size)
Definition: format.h:3594
const Char * c_str() const
Definition: format.h:594
FMT_GCC_EXTENSION typedef unsigned long long ULongLong
Definition: format.h:419
char * str_
Definition: format.h:3786
BasicWriter< Char > & writer()
Definition: format.h:2440
void visit_string(Arg::StringValue< char > value)
Definition: format.h:2248
Alignment align() const
Definition: format.h:1899
DummyInt isinf(...)
Definition: format.h:331
static uint64_t type(long)
Definition: format.h:1431
Result visit_custom(Arg::CustomValue)
Definition: format.h:1774
MakeValue(const NamedArg< Char_ > &value)
Definition: format.h:1522
std::basic_string< Char > str() const
Definition: format.h:2888
Char * write_unsigned_decimal(UInt value, unsigned prefix_size=0)
Definition: format.h:2762
bool flag(unsigned) const
Definition: format.h:1857
BasicWriter & operator<<(ULongLong value)
Definition: format.h:2953
const void * pointer
Definition: format.h:1204
BasicWriter & operator<<(double value)
Definition: format.h:2958
NamedArg(BasicStringRef< Char > argname, const T &value)
Definition: format.h:1557
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
static wchar_t convert(wchar_t value)
Definition: format.h:910
BasicStringRef< Char > name
Definition: format.h:1554
unsigned parse_nonnegative_int(const Char *&s)
Definition: format.h:4088
BasicStringRef(const Char *s, std::size_t size)
Definition: format.h:471
const Char * data() const FMT_NOEXCEPT
Definition: format.h:2866
void format(BasicCStringRef< Char > format_str)
Definition: format.h:4378
name
Definition: setup.py:38
StringValue< signed char > sstring
Definition: format.h:1206
virtual ~BasicWriter()
Definition: format.h:2852
ThousandsSep(fmt::StringRef sep)
Definition: format.h:1051
CustomValue custom
Definition: format.h:1209
BasicCStringRef(const std::basic_string< Char > &s)
Definition: format.h:591
FormatInt(unsigned value)
Definition: format.h:3837
void visit_pointer(const void *value)
Definition: format.h:2260
#define FMT_THROW(x)
Definition: format.h:172
Yes & convert(fmt::ULongLong)
T & operator[](std::size_t index)
Definition: format.h:737
FormatSpec(unsigned width=0, char type=0, wchar_t fill= ' ')
Definition: format.h:1933
FMT_API void print_colored(Color c, CStringRef format, ArgList args)
Definition: format.cc:883
friend bool operator>(BasicStringRef lhs, BasicStringRef rhs)
Definition: format.h:538
bool flag(unsigned f) const
Definition: format.h:1937
ArgFormatter(BasicFormatter< Char > &formatter, FormatSpec &spec, const Char *fmt)
Definition: format.h:2397
void set_string(StringRef str)
Definition: format.h:1384
const Char * str_
Definition: format.h:1973
static uint64_t type(unsigned long)
Definition: format.h:1443
void append(const U *begin, const U *end)
Definition: format.h:749
static const uint64_t POWERS_OF_10_64[]
Definition: format.h:979
static uint64_t type(const T &)
Definition: format.h:1514
FixedBuffer(Char *array, std::size_t size)
Definition: format.h:859
bool write(ros_opcua_srvs::Write::Request &req, ros_opcua_srvs::Write::Response &res)
std::size_t size() const
Definition: format.h:3842
virtual ~Buffer()
Definition: format.h:689
#define FMT_API
Definition: format.h:75
PrintfFormatter(const ArgList &args)
Definition: format.h:2340
wchar_t fill() const
Definition: format.h:1885
std::basic_string< Char > to_string() const
Definition: format.h:495
#define FMT_VARIADIC_CTOR(ctor, func, arg0_type, arg1_type)
Definition: format.h:2613
BasicStringRef< wchar_t > WStringRef
Definition: format.h:549
unsigned width() const
Definition: format.h:1849
void append_float_length(Char *&, T)
Definition: format.h:2833
Result visit_any_int(T)
Definition: format.h:1725
static uint64_t type(wchar_t)
Definition: format.h:1463
void clear() FMT_NOEXCEPT
Definition: format.h:724
BasicStringRef< char > StringRef
Definition: format.h:548
#define FMT_MAKE_STR_VALUE(Type, TYPE)
Definition: format.h:1469
BasicWriter & operator<<(long value)
Definition: format.h:2933
fmt::BufferedFile & move(fmt::BufferedFile &f)
Definition: posix.h:432
void clear() FMT_NOEXCEPT
Definition: format.h:3028
FMT_DISABLE_CONVERSION_TO_INT(float)
Alignment
Definition: format.h:1826
void write_decimal(Int value)
Definition: format.h:2772
BasicMemoryWriter< char > MemoryWriter
Definition: format.h:3558
int error_code() const
Definition: format.h:2698
uint64_t types_
Definition: format.h:1581
CharPtr grow_buffer(std::size_t n)
Definition: format.h:2753
#define FMT_ARG_TYPE_DEFAULT(n)
Definition: format.h:2538
CharPtr write_str(const StrChar *s, std::size_t size, const AlignSpec &spec)
Definition: format.h:3035
message
Definition: server.py:50
DummyInt isnan(...)
Definition: format.h:339
Result visit_long_long(LongLong value)
Definition: format.h:1694
MakeValue(unsigned long value)
Definition: format.h:1436
#define FMT_OVERRIDE
Definition: format.h:203
Result visit_double(double value)
Definition: format.h:1731
IntFormatSpec< int, TypeSpec<'X'> > hexu(int value)
BasicWriter & operator<<(LongLong value)
Definition: format.h:2942
BasicWriter & operator<<(typename internal::WCharHelper< StringRef, Char >::Supported value)
Definition: format.h:3004
std::string sprintf(CStringRef format, ArgList args)
Definition: format.h:3737
BasicCStringRef< char > CStringRef
Definition: format.h:600
unsigned uint_value
Definition: format.h:1199
friend bool operator==(BasicStringRef lhs, BasicStringRef rhs)
Definition: format.h:522
bool check_no_auto_index(const char *&error)
Definition: format.h:2305
Result visit_uint(unsigned value)
Definition: format.h:1700
BasicWriter< char > Writer
Definition: format.h:426
void write(bool value)
Definition: format.h:2165
char type() const
Definition: format.h:1945
std::size_t size() const
Definition: format.h:692
void append_float_length(Char *&format_ptr, long double)
Definition: format.h:2827
Result visit_string(Arg::StringValue< char >)
Definition: format.h:1756
void FormatSigned(LongLong value)
Definition: format.h:3813
BasicWriter< Char > & writer_
Definition: format.h:2411
std::vector< std::pair< fmt::BasicStringRef< Char >, internal::Arg > > MapType
Definition: format.h:2118
MakeUnsigned< Int >::Type to_unsigned(Int value)
Definition: format.h:635
std::size_t size() const
Definition: format.h:2857
friend bool operator>=(BasicStringRef lhs, BasicStringRef rhs)
Definition: format.h:542
void visit_char(int value)
Definition: format.h:2201
Result visit_cstring(const char *)
Definition: format.h:1750
SystemError(int error_code, CStringRef message)
Definition: format.h:2690
StringValue< char > string
Definition: format.h:1205
BasicWriter & operator<<(char value)
Definition: format.h:2979
DummyInt signbit(...)
Definition: format.h:323
void check_sign(const Char *&s, const Arg &arg)
Definition: format.h:4122
const char * data() const
Definition: format.h:3851
Buffer(T *ptr=0, std::size_t capacity=0)
Definition: format.h:677
BasicCStringRef< wchar_t > WCStringRef
Definition: format.h:601
void grow(std::size_t size) FMT_OVERRIDE
Definition: format.h:834
FMT_API void report_system_error(int error_code, StringRef message) FMT_NOEXCEPT
Definition: format.cc:859
internal::Arg operator[](unsigned index) const
Definition: format.h:1616
BasicWriter & operator<<(typename internal::WCharHelper< wchar_t, Char >::Supported value)
Definition: format.h:2985
int compare(BasicStringRef other) const
Definition: format.h:513
ArgList(ULongLong types, const internal::Arg *args)
Definition: format.h:1612
No & operator<<(std::ostream &, int)
std::size_t size() const
Definition: format.h:507
const internal::Arg * args_
Definition: format.h:1590
#define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: format.h:222
void write_int(T value, Spec spec)
Definition: format.h:3186
DummyInt _isnan(...)
Definition: format.h:343
BasicWriter< wchar_t > WWriter
Definition: format.h:429
MakeValue(const T &value, typename EnableIf< ConvertToInt< T >::value, int >::type=0)
Definition: format.h:1507
Formatter::Char Char
Definition: format.h:1359
void push_back(const T &value)
Definition: format.h:726
BasicFormatter(const ArgList &args, BasicWriter< Char > &w)
Definition: format.h:2436
BasicWriter & operator<<(long double value)
Definition: format.h:2970
char No[2]
Definition: format.h:1253
internal::CharTraits< Char >::CharPtr CharPtr
Definition: format.h:2731
const Char * str() const
Definition: format.h:1983
BasicArrayWriter(Char(&array)[SIZE])
Definition: format.h:3604
BasicArrayWriter< char > ArrayWriter
Definition: format.h:3608
BasicMemoryWriter(const Allocator &alloc=Allocator())
Definition: format.h:3530
Allocator get_allocator() const
Definition: format.h:827
const Char * data_
Definition: format.h:580
wchar_t type_
Definition: format.cc:302
Color
Definition: format.h:3667
FormatInt(long value)
Definition: format.h:3829
FMT_SPECIALIZE_MAKE_UNSIGNED(char, unsigned char)
char type() const
Definition: format.h:1861
static char convert(char value)
Definition: format.h:891
internal::NamedArg< char > arg(StringRef name, const T &arg)
Definition: format.h:3918
FormatInt(LongLong value)
Definition: format.h:3833
T * ptr_
Definition: format.h:673
BasicWriter & operator<<(unsigned value)
Definition: format.h:2929
char * format_decimal(ULongLong value)
Definition: format.h:3789
void require_numeric_argument(const Arg &arg, char spec)
Definition: format.h:4111
void set_string(WStringRef str)
Definition: format.h:1390
Result visit_unhandled_arg()
Definition: format.h:1681
StringValue< wchar_t > wstring
Definition: format.h:1208
unsigned count_digits(uint64_t n)
Definition: format.h:1007
T value() const
Definition: format.h:1962
MemoryBuffer(const Allocator &alloc=Allocator())
Definition: format.h:780
int precision() const
Definition: format.h:1853
BasicFormatter< Char, Impl > & formatter_
Definition: format.h:2367
void visit_cstring(const char *value)
Definition: format.h:2241
Buffer< Char > & buffer() FMT_NOEXCEPT
Definition: format.h:3030
void write(BasicWriter< Char > &w, const Char *start, const Char *end)
Definition: format.h:2317
BasicStringRef(const std::basic_string< Char > &s)
Definition: format.h:487
void write_double(T value, const FormatSpec &spec)
Definition: format.h:3306
char fill() const
Definition: format.h:1865
Result visit_char(int value)
Definition: format.h:1718
IntFormatSpec(T val, const SpecT &spec=SpecT())
Definition: format.h:1959
ROSCPP_DECL std::string append(const std::string &left, const std::string &right)
FormatterBase(const ArgList &args)
Definition: format.h:2283
IntFormatSpec< int, TypeSpec<'b'> > bin(int value)
MakeArg(const T &value)
Definition: format.h:1544
#define FMT_DEFINE_INT_FORMATTERS(TYPE)
Definition: format.h:2029
void reserve(std::size_t capacity)
Definition: format.h:718
const Char * format_
Definition: format.h:2368
BasicData Data
Definition: format.h:993
internal::MemoryBuffer< Char, internal::INLINE_BUFFER_SIZE, Allocator > buffer_
Definition: format.h:3527
std::size_t capacity_
Definition: format.h:675
FormatError(CStringRef message)
Definition: format.h:607
FMT_API int fprintf(std::FILE *f, CStringRef format, ArgList args)
Definition: format.cc:891
Result visit_int(int value)
Definition: format.h:1688
static Arg make(const T &value)
Definition: format.h:2513
internal::Arg Arg
Definition: format.h:1676
No & convert(...)
ULongLong ulong_long_value
Definition: format.h:1201
Definition: format.cc:81
bool flag(unsigned) const
Definition: format.h:1916
unsigned flags_
Definition: format.h:1929
BasicMemoryWriter< wchar_t > WMemoryWriter
Definition: format.h:3559
std::string str() const
Definition: format.h:3871
Arg get_arg(unsigned arg_index, const char *&error)
Definition: format.h:2300
#define FMT_GEN15(f)
Definition: format.h:2469
Result visit_wstring(Arg::StringValue< wchar_t >)
Definition: format.h:1762
static uint64_t type(const NamedArg< Char_ > &)
Definition: format.h:1528
internal::Arg get_arg(BasicStringRef< Char > arg_name, const char *&error)
Definition: format.h:4136
AlignSpec(unsigned width, wchar_t fill, Alignment align=ALIGN_DEFAULT)
Definition: format.h:1896
unsigned width() const
Definition: format.h:1881
LongLong long_long_value
Definition: format.h:1200
void visit_any_double(T value)
Definition: format.h:2189
DummyInt _finite(...)
Definition: format.h:335
const Char * c_str() const
Definition: format.h:2875
#define FMT_VARIADIC_VOID(func, arg_type)
Definition: format.h:2596
long double long_double_value
Definition: format.h:1203
void report_unhandled_arg()
Definition: format.h:1679
char type() const
Definition: format.h:1920
StringValue< unsigned char > ustring
Definition: format.h:1207
const internal::Value * values_
Definition: format.h:1589
std::numeric_limits< fmt::internal::DummyInt > FPUtil
Definition: format.h:319
#define FMT_VARIADIC_W(ReturnType, func,...)
Definition: format.h:4039
internal::ArgMap< Char > map_
Definition: format.h:2412
static Value make(const T &value)
Definition: format.h:2493
void write_pointer(const void *p)
Definition: format.h:2148
internal::Arg parse_arg_index(const Char *&s)
Definition: format.h:4151
static Char cast(int value)
Definition: format.h:874
const ArgList & args() const
Definition: format.h:2278
FormatInt(int value)
Definition: format.h:3825
static CharPtr fill_padding(CharPtr buffer, unsigned total_size, std::size_t content_size, wchar_t fill)
Definition: format.h:3091
ArgList(ULongLong types, const internal::Value *values)
Definition: format.h:1610
internal::Arg::Type type(unsigned index) const
Definition: format.h:1593
Result visit_long_double(long double value)
Definition: format.h:1737
BasicArrayWriter< wchar_t > WArrayWriter
Definition: format.h:3609
FMT_GCC_EXTENSION typedef long long LongLong
Definition: format.h:418
DummyInt _ecvt_s(...)
Definition: format.h:327
#define FMT_DELETED_OR_UNDEFINED
Definition: format.h:221
const Char * data_
Definition: format.h:466
bool is_name_start(Char c)
Definition: format.h:4080
const internal::Arg * find(const fmt::BasicStringRef< Char > &name) const
Definition: format.h:2126
Result visit(const Arg &arg)
Definition: format.h:1787
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3723
std::size_t size_
Definition: format.h:467


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:06:05