42 #ifndef FMT_USE_IOSTREAMS
43 # define FMT_USE_IOSTREAMS 1
51 # define FMT_SECURE_SCL _SECURE_SCL
53 # define FMT_SECURE_SCL 0
60 #if defined(_MSC_VER) && _MSC_VER <= 1500
68 #if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
70 # define FMT_API __declspec(dllexport)
71 # elif defined(FMT_SHARED)
72 # define FMT_API __declspec(dllimport)
80 # define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
81 # define FMT_GCC_EXTENSION __extension__
82 # if FMT_GCC_VERSION >= 406
83 # pragma GCC diagnostic push
86 # pragma GCC diagnostic ignored "-Wlong-long"
89 # pragma GCC diagnostic ignored "-Wshadow"
92 # pragma GCC diagnostic ignored "-Wsign-conversion"
94 # if __cplusplus >= 201103L || defined __GXX_EXPERIMENTAL_CXX0X__
95 # define FMT_HAS_GXX_CXX11 1
98 # define FMT_GCC_EXTENSION
101 #if defined(__clang__) && !defined(__INTEL_COMPILER)
102 # pragma clang diagnostic push
103 # pragma clang diagnostic ignored "-Wdocumentation"
106 #ifdef __GNUC_LIBSTD__
107 # define FMT_GNUC_LIBSTD_VERSION (__GNUC_LIBSTD__ * 100 + __GNUC_LIBSTD_MINOR__)
111 # define FMT_HAS_FEATURE(x) __has_feature(x)
113 # define FMT_HAS_FEATURE(x) 0
117 # define FMT_HAS_BUILTIN(x) __has_builtin(x)
119 # define FMT_HAS_BUILTIN(x) 0
122 #ifdef __has_cpp_attribute
123 # define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
125 # define FMT_HAS_CPP_ATTRIBUTE(x) 0
128 #ifndef FMT_USE_VARIADIC_TEMPLATES
132 # define FMT_USE_VARIADIC_TEMPLATES \
133 (FMT_HAS_FEATURE(cxx_variadic_templates) || \
134 (FMT_GCC_VERSION >= 404 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1800)
137 #ifndef FMT_USE_RVALUE_REFERENCES
140 # if defined(FMT_GNUC_LIBSTD_VERSION) && FMT_GNUC_LIBSTD_VERSION <= 402
141 # define FMT_USE_RVALUE_REFERENCES 0
143 # define FMT_USE_RVALUE_REFERENCES \
144 (FMT_HAS_FEATURE(cxx_rvalue_references) || \
145 (FMT_GCC_VERSION >= 403 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1600)
149 #if FMT_USE_RVALUE_REFERENCES
154 #if defined(__GNUC__) && !defined(__EXCEPTIONS)
155 # define FMT_EXCEPTIONS 0
157 #if defined(_MSC_VER) && !_HAS_EXCEPTIONS
158 # define FMT_EXCEPTIONS 0
160 #ifndef FMT_EXCEPTIONS
161 # define FMT_EXCEPTIONS 1
166 # define FMT_THROW(x) throw x
168 # define FMT_THROW(x) assert(false)
173 #ifndef FMT_USE_NOEXCEPT
174 # define FMT_USE_NOEXCEPT 0
179 # if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \
180 (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || \
182 # define FMT_NOEXCEPT noexcept
184 # define FMT_NOEXCEPT throw()
187 # define FMT_NOEXCEPT
193 #ifndef FMT_USE_DELETED_FUNCTIONS
194 # define FMT_USE_DELETED_FUNCTIONS 0
197 #if FMT_USE_DELETED_FUNCTIONS || FMT_HAS_FEATURE(cxx_deleted_functions) || \
198 (FMT_GCC_VERSION >= 404 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1800
199 # define FMT_DELETED_OR_UNDEFINED = delete
200 # define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \
201 TypeName(const TypeName&) = delete; \
202 TypeName& operator=(const TypeName&) = delete
204 # define FMT_DELETED_OR_UNDEFINED
205 # define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \
206 TypeName(const TypeName&); \
207 TypeName& operator=(const TypeName&)
210 #ifndef FMT_USE_USER_DEFINED_LITERALS
214 # define FMT_USE_USER_DEFINED_LITERALS \
215 FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES && \
216 (FMT_HAS_FEATURE(cxx_user_literals) || \
217 (FMT_GCC_VERSION >= 407 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1900)
221 # define FMT_ASSERT(condition, message) assert((condition) && message)
225 #if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz)
226 # define FMT_BUILTIN_CLZ(n) __builtin_clz(n)
229 #if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clzll)
230 # define FMT_BUILTIN_CLZLL(n) __builtin_clzll(n)
237 #if defined(_MSC_VER) && !defined(FMT_BUILTIN_CLZLL)
242 # pragma intrinsic(_BitScanReverse)
245 _BitScanReverse(&r, x);
251 # pragma warning(suppress: 6102)
254 # define FMT_BUILTIN_CLZ(n) fmt::internal::clz(n)
257 # pragma intrinsic(_BitScanReverse64)
263 _BitScanReverse64(&r, x);
266 if (_BitScanReverse(&r, static_cast<uint32_t>(x >> 32)))
267 return 63 - (r + 32);
270 _BitScanReverse(&r, static_cast<uint32_t>(x));
277 # pragma warning(suppress: 6102)
280 # define FMT_BUILTIN_CLZLL(n) fmt::internal::clzll(n)
289 operator int()
const {
return 0; }
304 template <
typename T>
315 class numeric_limits<
fmt::internal::DummyInt> :
316 public std::numeric_limits<int> {
319 template <
typename T>
325 sizeof(
isinf(x)) ==
sizeof(
int))) {
326 return isinf(x) != 0;
328 return !
_finite(static_cast<double>(x));
332 template <
typename T>
336 sizeof(
isnan(x)) ==
sizeof(
int))) {
337 return isnan(x) != 0;
339 return _isnan(static_cast<double>(x)) != 0;
347 if (x < 0)
return true;
348 if (!isnotanumber(x))
return false;
349 int dec = 0,
sign = 0;
351 _ecvt_s(buffer,
sizeof(buffer), x, 0, &dec, &
sign);
364 #if FMT_USE_RVALUE_REFERENCES
368 template <
typename Char>
374 template <
typename Char>
377 template <
typename Char,
typename T>
404 template <
typename Char>
429 : data_(s.c_str()), size_(s.size()) {}
437 return std::basic_string<Char>(data_, size_);
444 std::size_t
size()
const {
return size_; }
448 std::size_t size = size_ < other.
size_ ? size_ : other.
size_;
449 int result = std::char_traits<Char>::compare(data_, other.
data_, size);
451 result = size_ == other.
size_ ? 0 : (size_ < other.
size_ ? -1 : 1);
503 template <
typename Char>
532 :
std::runtime_error(message.c_str()) {}
538 template <
typename T>
541 #define FMT_SPECIALIZE_MAKE_UNSIGNED(T, U) \
543 struct MakeUnsigned<T> { typedef U Type; }
553 template <
typename Int>
565 template <
typename T>
566 inline stdext::checked_array_iterator<T*>
make_ptr(T *ptr, std::size_t size) {
567 return stdext::checked_array_iterator<T*>(ptr, size);
570 template <
typename T>
571 inline T *
make_ptr(T *ptr, std::size_t) {
return ptr; }
580 template <
typename T>
590 Buffer(T *ptr = 0, std::size_t capacity = 0)
591 : ptr_(ptr), size_(0), capacity_(capacity) {}
599 virtual void grow(std::size_t size) = 0;
605 std::size_t
size()
const {
return size_; }
614 if (new_size > capacity_)
625 if (capacity > capacity_)
632 if (size_ == capacity_)
634 ptr_[size_++] =
value;
638 template <
typename U>
639 void append(
const U *begin,
const U *end);
642 const T &
operator[](std::size_t index)
const {
return ptr_[index]; }
645 template <
typename T>
646 template <
typename U>
649 if (new_size > capacity_)
651 std::uninitialized_copy(begin, end,
660 template <
typename T, std::
size_t SIZE,
typename Allocator = std::allocator<T> >
667 if (this->ptr_ != data_) Allocator::deallocate(this->ptr_, this->capacity_);
671 void grow(std::size_t size);
675 : Allocator(alloc),
Buffer<T>(data_, SIZE) {}
678 #if FMT_USE_RVALUE_REFERENCES
682 Allocator &this_alloc = *
this, &other_alloc = other;
683 this_alloc = std::move(other_alloc);
684 this->size_ = other.
size_;
688 std::uninitialized_copy(other.
data_, other.
data_ + this->size_,
691 this->ptr_ = other.
ptr_;
704 assert(
this != &other);
715 template <
typename T, std::
size_t SIZE,
typename Allocator>
717 std::size_t new_capacity = this->capacity_ + this->capacity_ / 2;
718 if (size > new_capacity)
720 T *new_ptr = this->allocate(new_capacity);
722 std::uninitialized_copy(this->ptr_, this->ptr_ + this->size_,
724 std::size_t old_capacity = this->capacity_;
725 T *old_ptr = this->ptr_;
726 this->capacity_ = new_capacity;
727 this->ptr_ = new_ptr;
731 if (old_ptr != data_)
732 Allocator::deallocate(old_ptr, old_capacity);
736 template <
typename Char>
742 FMT_API void grow(std::size_t size);
745 template <
typename Char>
749 typedef stdext::checked_array_iterator<Char*>
CharPtr;
756 template <
typename Char>
769 template <
typename T>
770 FMT_API static int format_float(
char *buffer, std::size_t size,
771 const char *
format,
unsigned width,
int precision, T
value);
780 template <
typename T>
781 FMT_API static int format_float(
wchar_t *buffer, std::size_t size,
782 const wchar_t *
format,
unsigned width,
int precision, T
value);
786 template <
bool IsSigned>
788 template <
typename T>
794 template <
typename T>
800 template <
typename T>
806 template <
bool FitsIn32Bits>
812 template <
typename T>
824 template <
typename T =
void>
828 static const char DIGITS[];
833 #ifdef FMT_BUILTIN_CLZLL
839 int t = (64 - FMT_BUILTIN_CLZLL(n | 1)) * 1233 >> 12;
840 return to_unsigned(t) - (n < Data::POWERS_OF_10_64[t]) + 1;
850 if (n < 10)
return count;
851 if (n < 100)
return count + 1;
852 if (n < 1000)
return count + 2;
853 if (n < 10000)
return count + 3;
860 #ifdef FMT_BUILTIN_CLZ
863 int t = (32 - FMT_BUILTIN_CLZ(n | 1)) * 1233 >> 12;
864 return to_unsigned(t) - (n < Data::POWERS_OF_10_32[t]) + 1;
869 template <
typename UInt,
typename Char>
871 buffer += num_digits;
872 while (value >= 100) {
876 unsigned index =
static_cast<unsigned>((value % 100) * 2);
878 *--buffer = Data::DIGITS[index + 1];
879 *--buffer = Data::DIGITS[index];
882 *--buffer =
static_cast<char>(
'0' +
value);
885 unsigned index =
static_cast<unsigned>(value * 2);
886 *--buffer = Data::DIGITS[index + 1];
887 *--buffer = Data::DIGITS[index];
891 # define FMT_USE_WINDOWS_H 0
892 #elif !defined(FMT_USE_WINDOWS_H)
893 # define FMT_USE_WINDOWS_H 1
898 #if FMT_USE_WINDOWS_H
906 FMT_API explicit UTF8ToUTF16(StringRef s);
908 size_t size()
const {
return buffer_.
size() - 1; }
909 const wchar_t *c_str()
const {
return &buffer_[0]; }
910 std::wstring str()
const {
return std::wstring(&buffer_[0], size()); }
921 FMT_API explicit UTF16ToUTF8(WStringRef s);
923 size_t size()
const {
return buffer_.
size() - 1; }
924 const char *c_str()
const {
return &buffer_[0]; }
925 std::string str()
const {
return std::string(&buffer_[0], size()); }
942 template <
typename Char>
948 typedef void (*FormatFunc)(
949 void *formatter,
const void *
arg,
void *format_str_ptr);
974 INT, UINT, LONG_LONG,
ULONG_LONG, BOOL, CHAR, LAST_INTEGER_TYPE = CHAR,
987 template <
typename Char>
990 template <
typename T =
void>
995 template <
typename T,
typename Char>
1001 template <
typename T>
1015 template <
typename T>
1021 void operator<<(Null<>);
1026 template<
typename T,
bool ENABLE_CONVERSION>
1031 template<
typename T>
1039 template<
typename T,
bool ENABLE_CONVERSION>
1044 template<
typename T>
1052 template<
typename T>
1054 enum { enable_conversion =
sizeof(
convert(get<T>())) ==
sizeof(Yes) };
1058 #define FMT_DISABLE_CONVERSION_TO_INT(Type) \
1060 struct ConvertToInt<Type> { enum { value = 0 }; }
1067 template<
bool B,
class T =
void>
1073 template<
bool B,
class T,
class F>
1076 template<
class T,
class F>
1087 template <
typename Formatter>
1098 template <
typename T>
1100 template <
typename T>
1107 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
1116 string.value = str.
data();
1117 string.size = str.
size();
1121 wstring.value = str.
data();
1122 wstring.size = str.
size();
1126 template <
typename T>
1128 void *formatter,
const void *
arg,
void *format_str_ptr) {
1129 format(*static_cast<Formatter*>(formatter),
1130 *static_cast<const Char**>(format_str_ptr),
1131 *static_cast<const T*>(arg));
1137 #define FMT_MAKE_VALUE_(Type, field, TYPE, rhs) \
1138 MakeValue(Type value) { field = rhs; } \
1139 static uint64_t type(Type) { return Arg::TYPE; }
1141 #define FMT_MAKE_VALUE(Type, field, TYPE) \
1142 FMT_MAKE_VALUE_(Type, field, TYPE, value)
1153 if (
check(
sizeof(
long) ==
sizeof(
int)))
1154 int_value =
static_cast<int>(
value);
1156 long_long_value =
value;
1159 return sizeof(long) ==
sizeof(
int) ? Arg::INT : Arg::LONG_LONG;
1163 if (
check(
sizeof(
unsigned long) ==
sizeof(
unsigned)))
1164 uint_value =
static_cast<unsigned>(
value);
1166 ulong_long_value =
value;
1169 return sizeof(
unsigned long) ==
sizeof(
unsigned) ?
1170 Arg::UINT : Arg::ULONG_LONG;
1182 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
1189 #define FMT_MAKE_STR_VALUE(Type, TYPE) \
1190 MakeValue(Type value) { set_string(value); } \
1191 static uint64_t type(Type) { return Arg::TYPE; }
1201 #define FMT_MAKE_WSTR_VALUE(Type, TYPE) \
1202 MakeValue(typename WCharHelper<Type, Char>::Supported value) { \
1203 set_string(value); \
1205 static uint64_t type(Type) { return Arg::TYPE; }
1215 template <typename T>
1219 custom.value = &
value;
1220 custom.format = &format_custom_arg<T>;
1223 template <
typename T>
1229 template <
typename T>
1236 template <
typename Char_>
1239 template <
typename Char_>
1243 template <
typename Formatter>
1250 template <
typename T>
1257 template <
typename Char>
1261 template <
typename T>
1266 #define FMT_DISPATCH(call) static_cast<Impl*>(this)->call
1288 template <
typename Impl,
typename Result>
1316 template <
typename T>
1327 template <
typename T>
1357 case Arg::LONG_LONG:
1359 case Arg::ULONG_LONG:
1367 case Arg::LONG_DOUBLE:
1388 template <
typename Char>
1391 template <
typename Char>
1412 unsigned shift = index * 4;
1415 (types_ & (mask << shift)) >> shift);
1418 template <
typename Char>
1423 enum { MAX_PACKED_ARGS = 16 };
1428 : types_(types), values_(values) {}
1430 : types_(types), args_(args) {}
1436 bool use_values = type(MAX_PACKED_ARGS - 1) == Arg::NONE;
1437 if (index < MAX_PACKED_ARGS) {
1440 if (arg_type != Arg::NONE)
1441 val = use_values ? values_[index] : args_[index];
1442 arg.
type = arg_type;
1448 arg.
type = Arg::NONE;
1451 for (
unsigned i = MAX_PACKED_ARGS; i <= index; ++i) {
1452 if (args_[i].type == Arg::NONE)
1455 return args_[index];
1473 template <
char TYPE>
1478 bool flag(
unsigned)
const {
return false; }
1490 WidthSpec(
unsigned width,
wchar_t fill) : width_(width), fill_(fill) {}
1492 unsigned width()
const {
return width_; }
1493 wchar_t fill()
const {
return fill_; }
1501 :
WidthSpec(width, fill), align_(align) {}
1509 template <
char TYPE>
1513 bool flag(
unsigned)
const {
return false; }
1524 unsigned width = 0,
char type = 0,
wchar_t fill =
' ')
1525 :
AlignSpec(width, fill), flags_(0), precision_(-1), type_(type) {}
1527 bool flag(
unsigned f)
const {
return (flags_ & f) != 0; }
1529 char type()
const {
return type_; }
1533 template <
typename T,
typename SpecT = TypeSpec<0>,
typename Char =
char>
1540 : SpecT(spec), value_(val) {}
1546 template <
typename Char>
1552 template <
typename FillChar>
1558 const Char *
str()
const {
return str_; }
1564 IntFormatSpec<int, TypeSpec<'b'> >
bin(
int value);
1569 IntFormatSpec<int, TypeSpec<'o'> >
oct(
int value);
1575 IntFormatSpec<int, TypeSpec<'x'> >
hex(
int value);
1581 IntFormatSpec<int, TypeSpec<'X'> >
hexu(
int value);
1597 template <
char TYPE_CODE,
typename Char>
1598 IntFormatSpec<int, AlignTypeSpec<TYPE_CODE>, Char>
pad(
1599 int value,
unsigned width, Char fill =
' ');
1601 #define FMT_DEFINE_INT_FORMATTERS(TYPE) \
1602 inline IntFormatSpec<TYPE, TypeSpec<'b'> > bin(TYPE value) { \
1603 return IntFormatSpec<TYPE, TypeSpec<'b'> >(value, TypeSpec<'b'>()); \
1606 inline IntFormatSpec<TYPE, TypeSpec<'o'> > oct(TYPE value) { \
1607 return IntFormatSpec<TYPE, TypeSpec<'o'> >(value, TypeSpec<'o'>()); \
1610 inline IntFormatSpec<TYPE, TypeSpec<'x'> > hex(TYPE value) { \
1611 return IntFormatSpec<TYPE, TypeSpec<'x'> >(value, TypeSpec<'x'>()); \
1614 inline IntFormatSpec<TYPE, TypeSpec<'X'> > hexu(TYPE value) { \
1615 return IntFormatSpec<TYPE, TypeSpec<'X'> >(value, TypeSpec<'X'>()); \
1618 template <char TYPE_CODE> \
1619 inline IntFormatSpec<TYPE, AlignTypeSpec<TYPE_CODE> > pad( \
1620 IntFormatSpec<TYPE, TypeSpec<TYPE_CODE> > f, unsigned width) { \
1621 return IntFormatSpec<TYPE, AlignTypeSpec<TYPE_CODE> >( \
1622 f.value(), AlignTypeSpec<TYPE_CODE>(width, ' ')); \
1629 template <char TYPE_CODE, typename Char> \
1630 inline IntFormatSpec<TYPE, AlignTypeSpec<TYPE_CODE>, Char> pad( \
1631 IntFormatSpec<TYPE, TypeSpec<TYPE_CODE>, Char> f, \
1632 unsigned width, Char fill) { \
1633 return IntFormatSpec<TYPE, AlignTypeSpec<TYPE_CODE>, Char>( \
1634 f.value(), AlignTypeSpec<TYPE_CODE>(width, fill)); \
1637 inline IntFormatSpec<TYPE, AlignTypeSpec<0> > pad( \
1638 TYPE value, unsigned width) { \
1639 return IntFormatSpec<TYPE, AlignTypeSpec<0> >( \
1640 value, AlignTypeSpec<0>(width, ' ')); \
1643 template <typename Char> \
1644 inline IntFormatSpec<TYPE, AlignTypeSpec<0>, Char> pad( \
1645 TYPE value, unsigned width, Char fill) { \
1646 return IntFormatSpec<TYPE, AlignTypeSpec<0>, Char>( \
1647 value, AlignTypeSpec<0>(width, fill)); \
1669 template <typename Char>
1671 const Char *str,
unsigned width, Char fill = ' ') {
1676 const wchar_t *str,
unsigned width,
char fill =
' ') {
1682 template <
typename Char>
1686 typedef typename MapType::value_type
Pair;
1695 for (
typename MapType::const_iterator it = map_.begin(), end = map_.end();
1697 if (it->first == name)
1704 template <
typename Impl,
typename Char>
1715 writer_.
write_int(reinterpret_cast<uintptr_t>(p), spec_);
1723 const char *str_value = value ?
"true" :
"false";
1735 : writer_(w), spec_(s) {}
1737 template <
typename T>
1740 template <
typename T>
1745 return visit_any_int(value);
1759 CharPtr out = CharPtr();
1760 const unsigned CHAR_WIDTH = 1;
1761 if (spec_.
width_ > CHAR_WIDTH) {
1764 std::uninitialized_fill_n(out, spec_.
width_ - CHAR_WIDTH, fill);
1765 out += spec_.
width_ - CHAR_WIDTH;
1770 std::uninitialized_fill_n(out + CHAR_WIDTH,
1771 spec_.
width_ - CHAR_WIDTH, fill);
1780 if (spec_.
type_ ==
'p')
1781 return write_pointer(value);
1798 write_pointer(value);
1803 template <
typename Char>
1813 formatter_(f), format_(fmt) {}
1826 FMT_API Arg do_get_arg(
unsigned arg_index,
const char *&error);
1833 next_arg_index_ = 0;
1838 if (next_arg_index_ >= 0)
1840 error =
"cannot switch from manual to automatic argument indexing";
1847 return check_no_auto_index(error) ? do_get_arg(arg_index, error) :
Arg();
1851 if (next_arg_index_ > 0) {
1852 error =
"cannot switch from automatic to manual argument indexing";
1855 next_arg_index_ = -1;
1859 template <
typename Char>
1867 template <
typename Char>
1870 void parse_flags(
FormatSpec &spec,
const Char *&s);
1874 Arg get_arg(
const Char *s,
1878 unsigned parse_header(
const Char *&s,
FormatSpec &spec);
1888 template <
typename CharType>
1889 class BasicFormatter :
private internal::FormatterBase {
1900 using internal::FormatterBase::get_arg;
1935 # define FMT_GEN(n, f) FMT_GEN##n(f)
1936 # define FMT_GEN1(f) f(0)
1937 # define FMT_GEN2(f) FMT_GEN1(f), f(1)
1938 # define FMT_GEN3(f) FMT_GEN2(f), f(2)
1939 # define FMT_GEN4(f) FMT_GEN3(f), f(3)
1940 # define FMT_GEN5(f) FMT_GEN4(f), f(4)
1941 # define FMT_GEN6(f) FMT_GEN5(f), f(5)
1942 # define FMT_GEN7(f) FMT_GEN6(f), f(6)
1943 # define FMT_GEN8(f) FMT_GEN7(f), f(7)
1944 # define FMT_GEN9(f) FMT_GEN8(f), f(8)
1945 # define FMT_GEN10(f) FMT_GEN9(f), f(9)
1946 # define FMT_GEN11(f) FMT_GEN10(f), f(10)
1947 # define FMT_GEN12(f) FMT_GEN11(f), f(11)
1948 # define FMT_GEN13(f) FMT_GEN12(f), f(12)
1949 # define FMT_GEN14(f) FMT_GEN13(f), f(13)
1950 # define FMT_GEN15(f) FMT_GEN14(f), f(14)
1955 template <
typename T>
1960 template <
unsigned N,
bool= (N < ArgList::MAX_PACKED_ARGS)>
1963 template <
unsigned N>
1967 template <
typename Formatter,
typename T>
1977 template <
unsigned N>
1981 template <
typename Formatter,
typename T>
1985 #if FMT_USE_VARIADIC_TEMPLATES
1986 template <
typename Arg,
typename... Args>
1998 template <
typename T>
2002 # define FMT_ARG_TYPE_DEFAULT(n) ArgType t##n = ArgType()
2005 return t0.type | (t1.type << 4) | (t2.type << 8) | (t3.type << 12) |
2006 (t4.type << 16) | (t5.type << 20) | (t6.type << 24) | (t7.type << 28) |
2007 (t8.type << 32) | (t9.type << 36) | (t10.type << 40) | (t11.type << 44) |
2008 (t12.type << 48) | (t13.type << 52) | (t14.type << 56);
2012 template <
class Char>
2015 typedef typename std::basic_streambuf<Char>::int_type
int_type;
2023 this->setp(start_, start_ + buffer_.
capacity());
2027 if (!traits_type::eq_int_type(ch, traits_type::eof())) {
2028 size_t size = this->size();
2032 start_ = &buffer_[0];
2033 start_[size] = traits_type::to_char_type(ch);
2034 this->setp(start_+ size + 1, start_ + size * 2);
2045 # define FMT_MAKE_TEMPLATE_ARG(n) typename T##n
2046 # define FMT_MAKE_ARG_TYPE(n) T##n
2047 # define FMT_MAKE_ARG(n) const T##n &v##n
2048 # define FMT_ASSIGN_char(n) \
2049 arr[n] = fmt::internal::MakeValue< fmt::BasicFormatter<char> >(v##n)
2050 # define FMT_ASSIGN_wchar_t(n) \
2051 arr[n] = fmt::internal::MakeValue< fmt::BasicFormatter<wchar_t> >(v##n)
2053 #if FMT_USE_VARIADIC_TEMPLATES
2055 # define FMT_VARIADIC_VOID(func, arg_type) \
2056 template <typename... Args> \
2057 void func(arg_type arg0, const Args & ... args) { \
2058 typedef fmt::internal::ArgArray<sizeof...(Args)> ArgArray; \
2059 typename ArgArray::Type array{ \
2060 ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \
2061 func(arg0, fmt::ArgList(fmt::internal::make_type(args...), array)); \
2065 # define FMT_VARIADIC_CTOR(ctor, func, arg0_type, arg1_type) \
2066 template <typename... Args> \
2067 ctor(arg0_type arg0, arg1_type arg1, const Args & ... args) { \
2068 typedef fmt::internal::ArgArray<sizeof...(Args)> ArgArray; \
2069 typename ArgArray::Type array{ \
2070 ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \
2071 func(arg0, arg1, fmt::ArgList(fmt::internal::make_type(args...), array)); \
2076 # define FMT_MAKE_REF(n) \
2077 fmt::internal::MakeValue< fmt::BasicFormatter<Char> >(v##n)
2078 # define FMT_MAKE_REF2(n) v##n
2082 # define FMT_WRAP1(func, arg_type, n) \
2083 template <FMT_GEN(n, FMT_MAKE_TEMPLATE_ARG)> \
2084 inline void func(arg_type arg1, FMT_GEN(n, FMT_MAKE_ARG)) { \
2085 const fmt::internal::ArgArray<n>::Type array = {FMT_GEN(n, FMT_MAKE_REF)}; \
2086 func(arg1, fmt::ArgList( \
2087 fmt::internal::make_type(FMT_GEN(n, FMT_MAKE_REF2)), array)); \
2091 # define FMT_VARIADIC_VOID(func, arg_type) \
2092 inline void func(arg_type arg) { func(arg, fmt::ArgList()); } \
2093 FMT_WRAP1(func, arg_type, 1) FMT_WRAP1(func, arg_type, 2) \
2094 FMT_WRAP1(func, arg_type, 3) FMT_WRAP1(func, arg_type, 4) \
2095 FMT_WRAP1(func, arg_type, 5) FMT_WRAP1(func, arg_type, 6) \
2096 FMT_WRAP1(func, arg_type, 7) FMT_WRAP1(func, arg_type, 8) \
2097 FMT_WRAP1(func, arg_type, 9) FMT_WRAP1(func, arg_type, 10)
2099 # define FMT_CTOR(ctor, func, arg0_type, arg1_type, n) \
2100 template <FMT_GEN(n, FMT_MAKE_TEMPLATE_ARG)> \
2101 ctor(arg0_type arg0, arg1_type arg1, FMT_GEN(n, FMT_MAKE_ARG)) { \
2102 const fmt::internal::ArgArray<n>::Type array = {FMT_GEN(n, FMT_MAKE_REF)}; \
2103 func(arg0, arg1, fmt::ArgList( \
2104 fmt::internal::make_type(FMT_GEN(n, FMT_MAKE_REF2)), array)); \
2108 # define FMT_VARIADIC_CTOR(ctor, func, arg0_type, arg1_type) \
2109 FMT_CTOR(ctor, func, arg0_type, arg1_type, 1) \
2110 FMT_CTOR(ctor, func, arg0_type, arg1_type, 2) \
2111 FMT_CTOR(ctor, func, arg0_type, arg1_type, 3) \
2112 FMT_CTOR(ctor, func, arg0_type, arg1_type, 4) \
2113 FMT_CTOR(ctor, func, arg0_type, arg1_type, 5) \
2114 FMT_CTOR(ctor, func, arg0_type, arg1_type, 6) \
2115 FMT_CTOR(ctor, func, arg0_type, arg1_type, 7) \
2116 FMT_CTOR(ctor, func, arg0_type, arg1_type, 8) \
2117 FMT_CTOR(ctor, func, arg0_type, arg1_type, 9) \
2118 FMT_CTOR(ctor, func, arg0_type, arg1_type, 10)
2123 #define FMT_FOR_EACH1(f, x0) f(x0, 0)
2124 #define FMT_FOR_EACH2(f, x0, x1) \
2125 FMT_FOR_EACH1(f, x0), f(x1, 1)
2126 #define FMT_FOR_EACH3(f, x0, x1, x2) \
2127 FMT_FOR_EACH2(f, x0 ,x1), f(x2, 2)
2128 #define FMT_FOR_EACH4(f, x0, x1, x2, x3) \
2129 FMT_FOR_EACH3(f, x0, x1, x2), f(x3, 3)
2130 #define FMT_FOR_EACH5(f, x0, x1, x2, x3, x4) \
2131 FMT_FOR_EACH4(f, x0, x1, x2, x3), f(x4, 4)
2132 #define FMT_FOR_EACH6(f, x0, x1, x2, x3, x4, x5) \
2133 FMT_FOR_EACH5(f, x0, x1, x2, x3, x4), f(x5, 5)
2134 #define FMT_FOR_EACH7(f, x0, x1, x2, x3, x4, x5, x6) \
2135 FMT_FOR_EACH6(f, x0, x1, x2, x3, x4, x5), f(x6, 6)
2136 #define FMT_FOR_EACH8(f, x0, x1, x2, x3, x4, x5, x6, x7) \
2137 FMT_FOR_EACH7(f, x0, x1, x2, x3, x4, x5, x6), f(x7, 7)
2138 #define FMT_FOR_EACH9(f, x0, x1, x2, x3, x4, x5, x6, x7, x8) \
2139 FMT_FOR_EACH8(f, x0, x1, x2, x3, x4, x5, x6, x7), f(x8, 8)
2140 #define FMT_FOR_EACH10(f, x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) \
2141 FMT_FOR_EACH9(f, x0, x1, x2, x3, x4, x5, x6, x7, x8), f(x9, 9)
2149 void init(
int err_code, CStringRef format_str,
ArgList args);
2185 init(error_code, message,
ArgList());
2189 int error_code()
const {
return error_code_; }
2210 template <
typename Char>
2222 static Char *
get(CharPtr p) {
return p.base(); }
2224 static Char *
get(Char *p) {
return p; }
2229 static CharPtr fill_padding(CharPtr buffer,
2230 unsigned total_size, std::size_t content_size,
wchar_t fill);
2235 std::size_t size = buffer_.
size();
2236 buffer_.
resize(size + n);
2241 template <
typename UInt>
2244 Char *ptr =
get(grow_buffer(prefix_size + num_digits));
2250 template <
typename Int>
2253 MainType abs_value =
static_cast<MainType
>(
value);
2255 abs_value = 0 - abs_value;
2256 *write_unsigned_decimal(abs_value, 1) =
'-';
2258 write_unsigned_decimal(abs_value, 0);
2264 const EmptySpec &,
const char *prefix,
unsigned prefix_size) {
2265 unsigned size = prefix_size + num_digits;
2266 CharPtr p = grow_buffer(size);
2267 std::uninitialized_copy(prefix, prefix + prefix_size, p);
2268 return p + size - 1;
2271 template <
typename Spec>
2272 CharPtr prepare_int_buffer(
unsigned num_digits,
2273 const Spec &spec,
const char *prefix,
unsigned prefix_size);
2276 template <
typename T,
typename Spec>
2277 void write_int(T
value, Spec spec);
2280 template <
typename T>
2284 template <
typename StrChar>
2285 CharPtr write_str(
const StrChar *s, std::size_t size,
const AlignSpec &spec);
2287 template <
typename StrChar>
2295 void operator<<(typename internal::WCharHelper<wchar_t, Char>::Unsupported);
2302 *format_ptr++ =
'L';
2305 template<
typename T>
2308 template <
typename Impl,
typename Char_>
2336 const Char *
data()
const FMT_NOEXCEPT {
return &buffer_[0]; }
2343 std::size_t size = buffer_.
size();
2345 buffer_[size] =
'\0';
2354 std::basic_string<Char>
str()
const {
2355 return std::basic_string<Char>(&buffer_[0], buffer_.size());
2389 write_decimal(value);
2393 return *this << IntFormatSpec<unsigned>(
value);
2396 write_decimal(value);
2400 return *this << IntFormatSpec<unsigned long>(
value);
2403 write_decimal(value);
2413 return *this << IntFormatSpec<ULongLong>(
value);
2452 const Char *str =
value.data();
2459 const char *str = value.data();
2460 buffer_.
append(str, str + value.size());
2464 template <
typename T,
typename Spec,
typename FillChar>
2467 write_int(spec.value(), spec);
2471 template <
typename StrChar>
2473 const StrChar *s = spec.
str();
2481 template <
typename Char>
2482 template <
typename StrChar>
2484 const StrChar *s, std::size_t size,
const AlignSpec &spec) {
2486 if (spec.
width() > size) {
2487 out = grow_buffer(spec.
width());
2490 std::uninitialized_fill_n(out, spec.
width() - size, fill);
2491 out += spec.
width() - size;
2493 out = fill_padding(out, spec.
width(), size, fill);
2495 std::uninitialized_fill_n(out + size, spec.
width() - size, fill);
2498 out = grow_buffer(size);
2500 std::uninitialized_copy(s, s + size, out);
2504 template <
typename Char>
2505 template <
typename StrChar>
2512 const StrChar *str_value = s.
value;
2513 std::size_t str_size = s.
size;
2514 if (str_size == 0) {
2520 std::size_t precision =
static_cast<std::size_t
>(spec.
precision_);
2521 if (spec.
precision_ >= 0 && precision < str_size)
2522 str_size = precision;
2523 write_str(str_value, str_size, spec);
2526 template <
typename Char>
2529 CharPtr buffer,
unsigned total_size,
2530 std::size_t content_size,
wchar_t fill) {
2531 std::size_t padding = total_size - content_size;
2532 std::size_t left_padding = padding / 2;
2534 std::uninitialized_fill_n(buffer, left_padding, fill_char);
2535 buffer += left_padding;
2537 std::uninitialized_fill_n(buffer + content_size,
2538 padding - left_padding, fill_char);
2542 template <
typename Char>
2543 template <
typename Spec>
2546 unsigned num_digits,
const Spec &spec,
2547 const char *prefix,
unsigned prefix_size) {
2548 unsigned width = spec.width();
2551 if (spec.precision() >
static_cast<int>(num_digits)) {
2554 if (prefix_size > 0 && prefix[prefix_size - 1] ==
'0')
2556 unsigned number_size =
2559 if (number_size >= width)
2560 return prepare_int_buffer(num_digits, subspec, prefix, prefix_size);
2562 unsigned fill_size = width - number_size;
2564 CharPtr p = grow_buffer(fill_size);
2565 std::uninitialized_fill(p, p + fill_size, fill);
2567 CharPtr result = prepare_int_buffer(
2568 num_digits, subspec, prefix, prefix_size);
2570 CharPtr p = grow_buffer(fill_size);
2571 std::uninitialized_fill(p, p + fill_size, fill);
2575 unsigned size = prefix_size + num_digits;
2576 if (width <= size) {
2577 CharPtr p = grow_buffer(size);
2578 std::uninitialized_copy(prefix, prefix + prefix_size, p);
2579 return p + size - 1;
2581 CharPtr p = grow_buffer(width);
2584 std::uninitialized_copy(prefix, prefix + prefix_size, p);
2586 std::uninitialized_fill(p, end, fill);
2588 p = fill_padding(p, width, size, fill);
2589 std::uninitialized_copy(prefix, prefix + prefix_size, p);
2593 if (prefix_size != 0) {
2594 p = std::uninitialized_copy(prefix, prefix + prefix_size, p);
2595 size -= prefix_size;
2598 std::uninitialized_copy(prefix, prefix + prefix_size, end - size);
2600 std::uninitialized_fill(p, end - size, fill);
2606 template <
typename Char>
2607 template <
typename T,
typename Spec>
2609 unsigned prefix_size = 0;
2611 UnsignedType abs_value =
static_cast<UnsignedType
>(
value);
2612 char prefix[4] =
"";
2616 abs_value = 0 - abs_value;
2618 prefix[0] = spec.flag(
PLUS_FLAG) ?
'+' :
' ';
2621 switch (spec.type()) {
2624 CharPtr p = prepare_int_buffer(
2625 num_digits, spec, prefix, prefix_size) + 1 - num_digits;
2629 case 'x':
case 'X': {
2630 UnsignedType n = abs_value;
2632 prefix[prefix_size++] =
'0';
2633 prefix[prefix_size++] = spec.type();
2635 unsigned num_digits = 0;
2638 }
while ((n >>= 4) != 0);
2639 Char *p =
get(prepare_int_buffer(
2640 num_digits, spec, prefix, prefix_size));
2642 const char *digits = spec.type() ==
'x' ?
2643 "0123456789abcdef" :
"0123456789ABCDEF";
2645 *p-- = digits[n & 0xf];
2646 }
while ((n >>= 4) != 0);
2649 case 'b':
case 'B': {
2650 UnsignedType n = abs_value;
2652 prefix[prefix_size++] =
'0';
2653 prefix[prefix_size++] = spec.type();
2655 unsigned num_digits = 0;
2658 }
while ((n >>= 1) != 0);
2659 Char *p =
get(prepare_int_buffer(num_digits, spec, prefix, prefix_size));
2662 *p-- =
static_cast<Char
>(
'0' + (n & 1));
2663 }
while ((n >>= 1) != 0);
2667 UnsignedType n = abs_value;
2669 prefix[prefix_size++] =
'0';
2670 unsigned num_digits = 0;
2673 }
while ((n >>= 3) != 0);
2674 Char *p =
get(prepare_int_buffer(num_digits, spec, prefix, prefix_size));
2677 *p-- =
static_cast<Char
>(
'0' + (n & 7));
2678 }
while ((n >>= 3) != 0);
2683 spec.type(), spec.flag(
CHAR_FLAG) ?
"char" :
"integer");
2688 template <
typename Char>
2689 template <
typename T>
2692 char type = spec.
type();
2698 case 'e':
case 'f':
case 'g':
case 'a':
2706 case 'E':
case 'G':
case 'A':
2717 if (internal::FPUtil::isnegative(static_cast<double>(value))) {
2724 if (internal::FPUtil::isnotanumber(value)) {
2727 std::size_t nan_size = 4;
2728 const char *
nan = upper ?
" NAN" :
" nan";
2733 CharPtr out = write_str(nan, nan_size, spec);
2739 if (internal::FPUtil::isinfinity(value)) {
2742 std::size_t inf_size = 4;
2743 const char *
inf = upper ?
" INF" :
" inf";
2748 CharPtr out = write_str(inf, inf_size, spec);
2754 std::size_t offset = buffer_.
size();
2755 unsigned width = spec.
width();
2757 buffer_.
reserve(buffer_.
size() + (width > 1u ? width : 1u));
2764 enum { MAX_FORMAT_SIZE = 10};
2765 Char
format[MAX_FORMAT_SIZE];
2766 Char *format_ptr =
format;
2767 *format_ptr++ =
'%';
2768 unsigned width_for_sprintf = width;
2770 *format_ptr++ =
'#';
2772 width_for_sprintf = 0;
2775 *format_ptr++ =
'-';
2777 *format_ptr++ =
'*';
2780 *format_ptr++ =
'.';
2781 *format_ptr++ =
'*';
2784 append_float_length(format_ptr, value);
2785 *format_ptr++ = type;
2793 std::size_t buffer_size = buffer_.
capacity() - offset;
2798 if (buffer_size == 0) {
2800 buffer_size = buffer_.
capacity() - offset;
2803 start = &buffer_[offset];
2805 start, buffer_size, format, width_for_sprintf, spec.
precision(),
value);
2808 if (offset + n < buffer_.
capacity())
2810 buffer_.
reserve(offset + n + 1);
2820 *(start - 1) = sign;
2823 *(start - 1) = fill;
2828 width = spec.
width();
2829 CharPtr p = grow_buffer(width);
2830 std::memmove(
get(p) + (width - n) / 2,
get(p), n *
sizeof(Char));
2831 fill_padding(p, spec.
width(), n, fill);
2835 while (*start ==
' ')
2838 *(start - 1) = sign;
2877 template <
typename Char,
typename Allocator = std::allocator<Char> >
2886 #if FMT_USE_RVALUE_REFERENCES
2894 :
BasicWriter<Char>(buffer_), buffer_(
std::move(other.buffer_)) {
2902 BasicMemoryWriter &
operator=(BasicMemoryWriter &&other) {
2903 buffer_ = std::move(other.buffer_);
2932 template <
typename Char>
2945 :
BasicWriter<Char>(buffer_), buffer_(array, size) {}
2953 template <std::
size_t SIZE>
2955 :
BasicWriter<Char>(buffer_), buffer_(array, SIZE) {}
2962 template <
typename Char,
typename T>
2967 std::basic_ostream<Char>
output(&format_buf);
2972 format_str = f.
format(format_str, MakeArg(str));
2980 #if FMT_USE_WINDOWS_H
2983 class WindowsError :
public SystemError {
2985 FMT_API void init(
int error_code, CStringRef format_str, ArgList args);
3016 WindowsError(
int error_code, CStringRef message) {
3017 init(error_code, message, ArgList());
3024 FMT_API void report_windows_error(
int error_code,
3050 w.
write(format_str, args);
3056 w.
write(format_str, args);
3069 FMT_API void print(std::FILE *f, CStringRef format_str, ArgList args);
3080 FMT_API void print(CStringRef format_str, ArgList args);
3082 template <
typename Char>
3129 return fprintf(stdout, format, args);
3139 enum {BUFFER_SIZE = std::numeric_limits<ULongLong>::digits10 + 3};
3140 mutable char buffer_[BUFFER_SIZE];
3145 char *buffer_end = buffer_ + BUFFER_SIZE - 1;
3146 while (value >= 100) {
3150 unsigned index =
static_cast<unsigned>((value % 100) * 2);
3152 *--buffer_end = internal::Data::DIGITS[index + 1];
3153 *--buffer_end = internal::Data::DIGITS[index];
3156 *--buffer_end =
static_cast<char>(
'0' +
value);
3159 unsigned index =
static_cast<unsigned>(value * 2);
3160 *--buffer_end = internal::Data::DIGITS[index + 1];
3161 *--buffer_end = internal::Data::DIGITS[index];
3166 ULongLong abs_value =
static_cast<ULongLong
>(
value);
3167 bool negative = value < 0;
3169 abs_value = 0 - abs_value;
3192 const char *
data()
const {
return str_; }
3199 buffer_[BUFFER_SIZE - 1] =
'\0';
3208 std::string
str()
const {
return std::string(str_, size()); }
3214 template <
typename T>
3217 MainType abs_value =
static_cast<MainType
>(
value);
3220 abs_value = 0 - abs_value;
3222 if (abs_value < 100) {
3223 if (abs_value < 10) {
3224 *buffer++ =
static_cast<char>(
'0' + abs_value);
3227 unsigned index =
static_cast<unsigned>(abs_value * 2);
3228 *buffer++ = internal::Data::DIGITS[index];
3229 *buffer++ = internal::Data::DIGITS[index + 1];
3234 buffer += num_digits;
3247 template <
typename T>
3252 template <
typename T>
3259 template <
typename Char>
3261 template <typename Char>
3270 # pragma GCC system_header
3274 #define FMT_EXPAND(args) args
3278 #define FMT_NARG(...) FMT_NARG_(__VA_ARGS__, FMT_RSEQ_N())
3279 #define FMT_NARG_(...) FMT_EXPAND(FMT_ARG_N(__VA_ARGS__))
3280 #define FMT_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
3281 #define FMT_RSEQ_N() 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
3283 #define FMT_CONCAT(a, b) a##b
3284 #define FMT_FOR_EACH_(N, f, ...) \
3285 FMT_EXPAND(FMT_CONCAT(FMT_FOR_EACH, N)(f, __VA_ARGS__))
3286 #define FMT_FOR_EACH(f, ...) \
3287 FMT_EXPAND(FMT_FOR_EACH_(FMT_NARG(__VA_ARGS__), f, __VA_ARGS__))
3289 #define FMT_ADD_ARG_NAME(type, index) type arg##index
3290 #define FMT_GET_ARG_NAME(type, index) arg##index
3292 #if FMT_USE_VARIADIC_TEMPLATES
3293 # define FMT_VARIADIC_(Char, ReturnType, func, call, ...) \
3294 template <typename... Args> \
3295 ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), \
3296 const Args & ... args) { \
3297 typedef fmt::internal::ArgArray<sizeof...(Args)> ArgArray; \
3298 typename ArgArray::Type array{ \
3299 ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \
3300 call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), \
3301 fmt::ArgList(fmt::internal::make_type(args...), array)); \
3306 # define FMT_WRAP(Char, ReturnType, func, call, n, ...) \
3307 template <FMT_GEN(n, FMT_MAKE_TEMPLATE_ARG)> \
3308 inline ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), \
3309 FMT_GEN(n, FMT_MAKE_ARG)) { \
3310 fmt::internal::ArgArray<n>::Type arr; \
3311 FMT_GEN(n, FMT_ASSIGN_##Char); \
3312 call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), fmt::ArgList( \
3313 fmt::internal::make_type(FMT_GEN(n, FMT_MAKE_REF2)), arr)); \
3316 # define FMT_VARIADIC_(Char, ReturnType, func, call, ...) \
3317 inline ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__)) { \
3318 call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), fmt::ArgList()); \
3320 FMT_WRAP(Char, ReturnType, func, call, 1, __VA_ARGS__) \
3321 FMT_WRAP(Char, ReturnType, func, call, 2, __VA_ARGS__) \
3322 FMT_WRAP(Char, ReturnType, func, call, 3, __VA_ARGS__) \
3323 FMT_WRAP(Char, ReturnType, func, call, 4, __VA_ARGS__) \
3324 FMT_WRAP(Char, ReturnType, func, call, 5, __VA_ARGS__) \
3325 FMT_WRAP(Char, ReturnType, func, call, 6, __VA_ARGS__) \
3326 FMT_WRAP(Char, ReturnType, func, call, 7, __VA_ARGS__) \
3327 FMT_WRAP(Char, ReturnType, func, call, 8, __VA_ARGS__) \
3328 FMT_WRAP(Char, ReturnType, func, call, 9, __VA_ARGS__) \
3329 FMT_WRAP(Char, ReturnType, func, call, 10, __VA_ARGS__) \
3330 FMT_WRAP(Char, ReturnType, func, call, 11, __VA_ARGS__) \
3331 FMT_WRAP(Char, ReturnType, func, call, 12, __VA_ARGS__) \
3332 FMT_WRAP(Char, ReturnType, func, call, 13, __VA_ARGS__) \
3333 FMT_WRAP(Char, ReturnType, func, call, 14, __VA_ARGS__) \
3334 FMT_WRAP(Char, ReturnType, func, call, 15, __VA_ARGS__)
3335 #endif // FMT_USE_VARIADIC_TEMPLATES
3364 #define FMT_VARIADIC(ReturnType, func, ...) \
3365 FMT_VARIADIC_(char, ReturnType, func, return func, __VA_ARGS__)
3367 #define FMT_VARIADIC_W(ReturnType, func, ...) \
3368 FMT_VARIADIC_(wchar_t, ReturnType, func, return func, __VA_ARGS__)
3370 #define FMT_CAPTURE_ARG_(id, index) ::fmt::arg(#id, id)
3372 #define FMT_CAPTURE_ARG_W_(id, index) ::fmt::arg(L###id, id)
3388 #define FMT_CAPTURE(...) FMT_FOR_EACH(FMT_CAPTURE_ARG_, __VA_ARGS__)
3390 #define FMT_CAPTURE_W(...) FMT_FOR_EACH(FMT_CAPTURE_ARG_W_, __VA_ARGS__)
3404 #if FMT_USE_IOSTREAMS
3414 FMT_API void print(std::ostream &os, CStringRef format_str, ArgList args);
3426 FMT_API int fprintf(std::ostream &os, CStringRef format_str, ArgList args);
3431 template <
typename Char>
3433 return (
'a' <= c && c <=
'z') || (
'A' <= c && c <=
'Z') ||
'_' == c;
3438 template <
typename Char>
3440 assert(
'0' <= *s && *s <=
'9');
3443 unsigned new_value = value * 10 + (*s++ -
'0');
3445 if (new_value < value) {
3450 }
while (
'0' <= *s && *s <=
'9');
3453 if (value > max_int)
3459 if (arg.
type > Arg::LAST_NUMERIC_TYPE) {
3460 std::string message =
3461 fmt::format(
"format specifier '{}' requires numeric argument", spec);
3466 template <
typename Char>
3468 char sign =
static_cast<char>(*s);
3470 if (arg.
type == Arg::UINT || arg.
type == Arg::ULONG_LONG) {
3472 "format specifier '{}' requires signed argument", sign)));
3478 template <
typename Char>
3481 if (check_no_auto_index(error)) {
3486 error =
"argument not found";
3491 template <
typename Char>
3493 const char *error = 0;
3498 *s !=
'}' && *s !=
':' ?
"invalid format string" : error));
3503 template <
typename Char>
3506 const Char *start = s;
3511 const char *error = 0;
3518 template <
typename Char>
3522 const Char *s = format_str;
3525 if (arg.
type == Arg::CUSTOM) {
3532 const Char *p = s + 1;
3551 if (c ==
'}')
break;
3595 if (
'0' <= *s && *s <=
'9') {
3597 }
else if (*s ==
'{') {
3600 parse_arg_name(s) : parse_arg_index(s);
3603 ULongLong
value = 0;
3604 switch (width_arg.
type) {
3613 case Arg::LONG_LONG:
3618 case Arg::ULONG_LONG:
3633 if (
'0' <= *s && *s <=
'9') {
3635 }
else if (*s ==
'{') {
3638 parse_arg_name(s) : parse_arg_index(s);
3641 ULongLong
value = 0;
3642 switch (precision_arg.
type) {
3651 case Arg::LONG_LONG:
3656 case Arg::ULONG_LONG:
3668 if (arg.
type <= Arg::LAST_INTEGER_TYPE || arg.
type == Arg::POINTER) {
3670 fmt::format(
"precision not allowed in {} format specifier",
3671 arg.
type == Arg::POINTER ?
"pointer" :
"integer")));
3676 if (*s !=
'}' && *s)
3677 spec.
type_ =
static_cast<char>(*s++);
3688 template <
typename Char>
3690 const Char *s = format_str.
c_str();
3691 const Char *start = s;
3694 if (c !=
'{' && c !=
'}')
continue;
3696 write(writer_, start, s);
3702 write(writer_, start, s - 1);
3704 parse_arg_name(s) : parse_arg_index(s);
3705 start = s =
format(s, arg);
3707 write(writer_, start, s);
3711 #if FMT_USE_USER_DEFINED_LITERALS
3715 template <
typename Char>
3719 template <
typename... Args>
3720 auto operator()(Args && ... args)
const
3721 -> decltype(
format(str,
std::forward<Args>(args)...)) {
3722 return format(str, std::forward<Args>(args)...);
3726 template <
typename Char>
3730 template <
typename T>
3732 return {str, std::forward<T>(
value)};
3738 inline namespace literals {
3750 inline internal::UdlFormat<char>
3751 operator"" _format(
const char *s, std::size_t) {
return {s}; }
3752 inline internal::UdlFormat<wchar_t>
3753 operator"" _format(
const wchar_t *s, std::size_t) {
return {s}; }
3765 inline internal::UdlArg<char>
3766 operator"" _a(
const char *s, std::size_t) {
return {s}; }
3767 inline internal::UdlArg<wchar_t>
3768 operator"" _a(
const wchar_t *s, std::size_t) {
return {s}; }
3772 #endif // FMT_USE_USER_DEFINED_LITERALS
3775 #if FMT_GCC_VERSION >= 406
3776 # pragma GCC diagnostic pop
3779 #if defined(__clang__) && !defined(__INTEL_COMPILER)
3780 # pragma clang diagnostic pop
3783 #ifdef FMT_HEADER_ONLY
3784 # include "format.cc"
3787 #endif // FMT_FORMAT_H_
BasicCStringRef(const Char *s)
Definition: format.h:510
void format(BasicFormatter< Char > &f, const Char *&format_str, const T &value)
Definition: format.h:2963
double double_value
Definition: format.h:961
AlignTypeSpec(unsigned width, wchar_t fill)
Definition: format.h:1511
uint64_t Type
Definition: format.h:810
StrFormatSpec< wchar_t > pad(const wchar_t *str, unsigned width, char fill= ' ')
Definition: format.h:1675
Definition: AppenderConsole.h:28
BasicWriter & operator<<(typename internal::WCharHelper< wchar_t, Char >::Supported value)
Definition: format.h:2440
MakeValue(typename WCharHelper< wchar_t, Char >::Supported value)
Definition: format.h:1183
int printf(CStringRef format, ArgList args)
Definition: format.h:3128
FMT_API void print(std::ostream &os, CStringRef format_str, ArgList args)
std::size_t size() const
Definition: format.h:2330
BasicStringRef(const Char *s)
Definition: format.h:420
FMT_API void print_colored(Color c, CStringRef format, ArgList args)
const T & operator[](std::size_t index) const
Definition: format.h:642
ArgType(const T &arg)
Definition: format.h:1999
bool is_negative(T value)
Definition: format.h:801
BasicWriter & operator<<(unsigned long value)
Definition: format.h:2399
Alignment align_
Definition: format.h:1498
const Char * data() const
Definition: format.h:441
Definition: format.h:1460
static void format_custom_arg(void *formatter, const void *arg, void *format_str_ptr)
Definition: format.h:1127
std::size_t size_
Definition: format.h:587
T data_[SIZE]
Definition: format.h:663
static bool is_negative(T value)
Definition: format.h:789
void resize(std::size_t new_size)
Definition: format.h:613
CharPtr grow_buffer(std::size_t n)
Definition: format.h:2234
Alignment align() const
Definition: format.h:1475
friend bool operator!=(BasicStringRef lhs, BasicStringRef rhs)
Definition: format.h:458
const void * value
Definition: format.h:952
FMT_API int fprintf(std::ostream &os, CStringRef format_str, ArgList args)
int precision() const
Definition: format.h:1505
friend bool operator<=(BasicStringRef lhs, BasicStringRef rhs)
Definition: format.h:464
char Yes[1]
Definition: format.h:1007
Definition: AppenderConsole.h:30
wchar_t fill_
Definition: format.h:1488
IntFormatSpec< int, TypeSpec<'x'> > hex(int value)
Result visit_wstring(Arg::StringValue< wchar_t >)
Definition: format.h:1338
T Type
Definition: format.h:539
IntFormatSpec< int, TypeSpec<'o'> > oct(int value)
WidthSpec(unsigned width, wchar_t fill)
Definition: format.h:1490
T * make_ptr(T *ptr, std::size_t)
Definition: format.h:571
friend bool operator<(BasicStringRef lhs, BasicStringRef rhs)
Definition: format.h:461
const Char * c_str() const
Definition: format.h:2342
internal::FixedBuffer< Char > buffer_
Definition: format.h:2935
BasicWriter(Buffer< Char > &b)
Definition: format.h:2317
char Char
Definition: format.h:2154
static wchar_t convert(char value)
Definition: format.h:777
Definition: AppenderConsole.h:27
int data[2]
Definition: format.h:288
FMT_API void format_system_error(fmt::Writer &out, int error_code, fmt::StringRef message) FMT_NOEXCEPT
#define isnan
Definition: BoundingIntervalHierarchy.cpp:24
T type
Definition: format.h:1071
std::size_t capacity() const
Definition: format.h:608
unsigned width_
Definition: format.h:1485
BasicArrayWriter(Char *array, std::size_t size)
Definition: format.h:2944
const Char * c_str() const
Definition: format.h:520
FMT_GCC_EXTENSION typedef unsigned long long ULongLong
Definition: format.h:362
Result visit_long_long(LongLong value)
Definition: format.h:1301
Definition: format.h:1053
Definition: format.h:2933
Alignment align() const
Definition: format.h:1503
Definition: format.h:1460
DummyInt isinf(...)
Definition: format.h:297
Definition: AppenderConsole.h:32
#define false
Definition: CascPort.h:18
static uint64_t type(long)
Definition: format.h:1158
Definition: format.h:1961
MakeValue(const NamedArg< Char_ > &value)
Definition: format.h:1237
void write_double(T value, const FormatSpec &spec)
Definition: format.h:2690
void write(BasicCStringRef< Char > format, ArgList args)
Definition: format.h:2383
Result visit_cstring(const char *)
Definition: format.h:1332
bool flag(unsigned) const
Definition: format.h:1478
const void * pointer
Definition: format.h:963
NamedArg(BasicStringRef< Char > argname, const T &value)
Definition: format.h:1262
static wchar_t convert(wchar_t value)
Definition: format.h:778
BasicStringRef< Char > name
Definition: format.h:1259
unsigned parse_nonnegative_int(const Char *&s)
Definition: format.h:3439
ArgType()
Definition: format.h:1996
BasicStringRef(const Char *s, std::size_t size)
Definition: format.h:412
uint32_t Type
Definition: format.h:807
StringValue< signed char > sstring
Definition: format.h:965
CustomValue custom
Definition: format.h:968
BasicWriter & operator<<(LongLong value)
Definition: format.h:2402
void write_decimal(Int value)
Definition: format.h:2251
BasicCStringRef(const std::basic_string< Char > &s)
Definition: format.h:517
F type
Definition: format.h:1077
Result visit_string(Arg::StringValue< char >)
Definition: format.h:1335
Result visit_ulong_long(ULongLong value)
Definition: format.h:1307
T & operator[](std::size_t index)
Definition: format.h:641
std::size_t size
Definition: format.h:945
friend bool operator>(BasicStringRef lhs, BasicStringRef rhs)
Definition: format.h:467
void set_string(StringRef str)
Definition: format.h:1115
T max(const T &x, const T &y)
Definition: g3dmath.h:320
static uint64_t type(unsigned long)
Definition: format.h:1168
virtual ~BasicWriter()
Definition: format.h:2325
Definition: format.h:1018
void append(const U *begin, const U *end)
Definition: format.h:647
Result visit_uint(unsigned value)
Definition: format.h:1304
Definition: format.h:1460
static uint64_t type(const T &)
Definition: format.h:1230
Result visit_char(int value)
Definition: format.h:1313
FixedBuffer(Char *array, std::size_t size)
Definition: format.h:739
virtual ~Buffer()
Definition: format.h:602
#define true
Definition: CascPort.h:17
wchar_t fill() const
Definition: format.h:1493
std::basic_string< Char > to_string() const
Definition: format.h:436
BasicStringRef< wchar_t > WStringRef
Definition: format.h:476
void arg(WStringRef, const internal::NamedArg< Char > &) FMT_DELETED_OR_UNDEFINED
unsigned width() const
Definition: format.h:1476
Definition: format.h:1510
Definition: format.h:1068
Definition: format.h:1040
static uint64_t type(wchar_t)
Definition: format.h:1186
Definition: format.h:2878
void clear() FMT_NOEXCEPT
Definition: format.h:629
BasicStringRef< char > StringRef
Definition: format.h:475
unsigned int uint32_t
Definition: stdint.h:80
Result visit(const Arg &arg)
Definition: format.h:1348
Alignment
Definition: format.h:1459
Definition: format.h:1392
BasicMemoryWriter< char > MemoryWriter
Definition: format.h:2909
Definition: AppenderConsole.h:34
double inf()
Definition: g3dmath.cpp:40
BasicWriter & operator<<(long value)
Definition: format.h:2395
uint64_t types_
Definition: format.h:1400
RuntimeError()
Definition: format.h:1385
void clear() FMT_NOEXCEPT
Definition: format.h:2478
Null< T > Unsupported
Definition: format.h:1004
char Char
Definition: bzlib_private.h:41
DummyInt isnan(...)
Definition: format.h:299
Null< T > Supported
Definition: format.h:997
Type
Definition: format.h:971
Definition: format.h:1081
MakeValue(unsigned long value)
Definition: format.h:1162
IntFormatSpec< int, TypeSpec<'X'> > hexu(int value)
Definition: format.h:1396
SystemError()
Definition: format.h:2156
BasicCStringRef< char > CStringRef
Definition: format.h:523
MapType map_
Definition: format.h:1688
Result visit_double(double value)
Definition: format.h:1321
unsigned uint_value
Definition: format.h:958
unsigned __int64 uint64_t
Definition: stdint.h:90
BasicWriter & operator<<(long double value)
Definition: format.h:2427
friend bool operator==(BasicStringRef lhs, BasicStringRef rhs)
Definition: format.h:455
Definition: format.h:1465
static bool isinfinity(T x)
Definition: format.h:320
BasicWriter< char > Writer
Definition: format.h:369
internal::CharTraits< Char >::CharPtr CharPtr
Definition: format.h:2218
std::size_t size() const
Definition: format.h:605
Result visit_custom(Arg::CustomValue)
Definition: format.h:1344
Definition: AppenderConsole.h:26
Definition: format.h:1027
Definition: format.h:1465
int int_value
Definition: format.h:957
MakeUnsigned< Int >::Type to_unsigned(Int value)
Definition: format.h:554
CharPtr write_str(const StrChar *s, std::size_t size, const AlignSpec &spec)
Definition: format.h:2483
ArgList()
Definition: format.h:1425
friend bool operator>=(BasicStringRef lhs, BasicStringRef rhs)
Definition: format.h:470
Vector2int16 & operator=(const Any &a)
SystemError(int error_code, CStringRef message)
Definition: format.h:2184
StringValue< char > string
Definition: format.h:964
void append_float_length(Char *&format_ptr, long double)
Definition: format.h:2301
DummyInt signbit(...)
Definition: format.h:295
void check_sign(const Char *&s, const Arg &arg)
Definition: format.h:3467
Buffer(T *ptr=0, std::size_t capacity=0)
Definition: format.h:590
BasicCStringRef< wchar_t > WCStringRef
Definition: format.h:524
internal::Arg operator[](unsigned index) const
Definition: format.h:1433
const Char * value
Definition: format.h:944
static bool isnotanumber(T x)
Definition: format.h:333
int compare(BasicStringRef other) const
Definition: format.h:447
ArgList(ULongLong types, const internal::Arg *args)
Definition: format.h:1429
No & operator<<(std::ostream &, int)
FMT_API void report_unknown_type(char code, const char *type)
std::size_t size() const
Definition: format.h:444
std::basic_string< Char > str() const
Definition: format.h:2354
~MemoryBuffer()
Definition: format.h:676
const internal::Arg * args_
Definition: format.h:1408
std::string __cdecl format(const char *fmt...) G3D_CHECK_PRINTF_ARGS
Result visit_any_double(T)
Definition: format.h:1328
Definition: format.h:1470
DummyInt _isnan(...)
Definition: format.h:300
Char * CharPtr
Definition: format.h:751
Definition: format.h:1289
BasicWriter< wchar_t > WWriter
Definition: format.h:372
MakeValue(const T &value, typename EnableIf< ConvertToInt< T >::value, int >::type=0)
Definition: format.h:1224
BasicWriter & operator<<(ULongLong value)
Definition: format.h:2412
Formatter::Char Char
Definition: format.h:1090
void push_back(const T &value)
Definition: format.h:631
char No[2]
Definition: format.h:1008
T Unsupported
Definition: format.h:998
BasicArrayWriter(Char(&array)[SIZE])
Definition: format.h:2954
BasicArrayWriter< char > ArrayWriter
Definition: format.h:2958
BasicMemoryWriter(const Allocator &alloc=Allocator())
Definition: format.h:2883
float length(float v)
Definition: vectorMath.h:208
MakeArg()
Definition: format.h:1246
Allocator get_allocator() const
Definition: format.h:712
T type
Definition: format.h:1074
Definition: format.h:1497
const Char * data_
Definition: format.h:506
void write_int(T value, Spec spec)
Definition: format.h:2608
Definition: inftrees.h:24
BasicWriter & operator<<(char value)
Definition: format.h:2435
Definition: format.h:1460
Definition: AppenderConsole.h:31
Color
Definition: format.h:3029
uint64_t type
Definition: format.h:1994
Definition: document.h:390
char type() const
Definition: format.h:1479
Definition: format.h:1474
static char convert(char value)
Definition: format.h:766
Result visit_long_double(long double value)
Definition: format.h:1324
BasicWriter & operator<<(double value)
Definition: format.h:2416
void append_float_length(Char *&, T)
Definition: format.h:2306
T * ptr_
Definition: format.h:586
void require_numeric_argument(const Arg &arg, char spec)
Definition: format.h:3458
void set_string(WStringRef str)
Definition: format.h:1120
StringValue< wchar_t > wstring
Definition: format.h:967
unsigned count_digits(uint64_t n)
Definition: format.h:844
MemoryBuffer(const Allocator &alloc=Allocator())
Definition: format.h:674
int precision() const
Definition: format.h:1477
Result visit_int(int value)
Definition: format.h:1298
std::vector< std::pair< fmt::BasicStringRef< Char >, internal::Arg > > MapType
Definition: format.h:1685
Result visit_any_int(T)
Definition: format.h:1317
Char * write_unsigned_decimal(UInt value, unsigned prefix_size=0)
Definition: format.h:2242
BasicStringRef(const std::basic_string< Char > &s)
Definition: format.h:428
char fill() const
Definition: format.h:1480
Definition: format.h:1465
IntFormatSpec< int, TypeSpec<'b'> > bin(int value)
Definition: format.h:1993
BasicWriter & operator<<(unsigned value)
Definition: format.h:2392
Definition: format.h:1074
MakeArg(const T &value)
Definition: format.h:1251
Definition: AppenderConsole.h:40
const Char * data() const FMT_NOEXCEPT
Definition: format.h:2336
void reserve(std::size_t capacity)
Definition: format.h:624
BasicData Data
Definition: format.h:831
internal::MemoryBuffer< Char, internal::INLINE_BUFFER_SIZE, Allocator > buffer_
Definition: format.h:2880
std::size_t capacity_
Definition: format.h:588
T Supported
Definition: format.h:1003
Result visit_unhandled_arg()
Definition: format.h:1293
static Arg make(const T &value)
Definition: format.h:1982
ULongLong ulong_long_value
Definition: format.h:960
bool flag(unsigned) const
Definition: format.h:1513
BasicMemoryWriter< wchar_t > WMemoryWriter
Definition: format.h:2910
std::wstring sprintf(WCStringRef format, ArgList args)
Definition: format.h:3102
Definition: format.h:1466
const FieldDescriptor value
Definition: descriptor.h:1522
Definition: format.h:1484
const internal::Arg * find(const fmt::BasicStringRef< Char > &name) const
Definition: format.h:1693
FormatFunc format
Definition: format.h:953
static uint64_t type(const NamedArg< Char_ > &)
Definition: format.h:1240
Type type
Definition: format.h:984
Definition: format.h:2147
Definition: format.h:1244
MakeValue()
Definition: format.h:1135
static CharPtr fill_padding(CharPtr buffer, unsigned total_size, std::size_t content_size, wchar_t fill)
Definition: format.h:2528
#define const
Definition: zconf.h:217
G3D::int16 x
Definition: Vector2int16.h:37
AlignSpec(unsigned width, wchar_t fill, Alignment align=ALIGN_DEFAULT)
Definition: format.h:1500
unsigned width() const
Definition: format.h:1492
void report_unhandled_arg()
Definition: format.h:1291
uint64_t make_type(FMT_GEN15(FMT_ARG_TYPE_DEFAULT))
Definition: format.h:2004
static bool isnegative(double x)
Definition: format.h:343
LongLong long_long_value
Definition: format.h:959
DummyInt _finite(...)
Definition: format.h:298
T check(T value)
Definition: format.h:305
Definition: format.h:1460
static bool is_negative(T)
Definition: format.h:795
long double long_double_value
Definition: format.h:962
Type
Type of JSON value.
Definition: rapidjson.h:642
Buffer< Char > & buffer_
Definition: format.h:2214
char type() const
Definition: format.h:1514
StringValue< unsigned char > ustring
Definition: format.h:966
double sign(double fValue)
Definition: g3dmath.h:669
const internal::Value * values_
Definition: format.h:1407
std::numeric_limits< fmt::internal::DummyInt > FPUtil
Definition: format.h:291
FMT_API void report_system_error(int error_code, StringRef message) FMT_NOEXCEPT
Result visit_pointer(const void *)
Definition: format.h:1341
static Value make(const T &value)
Definition: format.h:1968
void format_decimal(char *&buffer, T value)
Definition: format.h:3215
static Char cast(int value)
Definition: format.h:753
ArgList(ULongLong types, const internal::Value *values)
Definition: format.h:1427
Definition: format.h:1088
double nan()
Definition: g3dmath.cpp:77
Definition: format.h:1465
MapType::value_type Pair
Definition: format.h:1686
int error_code_
Definition: format.h:2152
internal::Arg::Type type(unsigned index) const
Definition: format.h:1411
GenericMemoryBuffer MemoryBuffer
Definition: memorybuffer.h:60
BasicArrayWriter< wchar_t > WArrayWriter
Definition: format.h:2959
BasicWriter & operator<<(typename internal::WCharHelper< StringRef, Char >::Supported value)
Definition: format.h:2457
FMT_GCC_EXTENSION typedef long long LongLong
Definition: format.h:361
DummyInt _ecvt_s(...)
Definition: format.h:296
void deallocate()
Definition: format.h:666
const Char * data_
Definition: format.h:407
octet_iterator append(uint32_t cp, octet_iterator result)
The library API - functions intended to be called by the users.
Definition: checked.h:73
bool is_name_start(Char c)
Definition: format.h:3432
CharPtr prepare_int_buffer(unsigned num_digits, const EmptySpec &, const char *prefix, unsigned prefix_size)
Definition: format.h:2263
Result visit_bool(bool value)
Definition: format.h:1310
int64_t intmax_t
Definition: stdint.h:123
Definition: format.h:1383
std::size_t size_
Definition: format.h:408