11#if defined(FMT_IMPORT_STD) && !defined(FMT_MODULE)
22# include <type_traits>
26#define FMT_VERSION 110002
29#if defined(__clang__) && !defined(__ibmxl__)
30# define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
32# define FMT_CLANG_VERSION 0
34#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
35# define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
37# define FMT_GCC_VERSION 0
40# define FMT_ICC_VERSION __ICL
41#elif defined(__INTEL_COMPILER)
42# define FMT_ICC_VERSION __INTEL_COMPILER
44# define FMT_ICC_VERSION 0
47# define FMT_MSC_VERSION _MSC_VER
49# define FMT_MSC_VERSION 0
53#ifdef _GLIBCXX_RELEASE
54# define FMT_GLIBCXX_RELEASE _GLIBCXX_RELEASE
56# define FMT_GLIBCXX_RELEASE 0
59# define FMT_LIBCPP_VERSION _LIBCPP_VERSION
61# define FMT_LIBCPP_VERSION 0
65# define FMT_CPLUSPLUS _MSVC_LANG
67# define FMT_CPLUSPLUS __cplusplus
72# define FMT_HAS_FEATURE(x) __has_feature(x)
74# define FMT_HAS_FEATURE(x) 0
77# define FMT_HAS_INCLUDE(x) __has_include(x)
79# define FMT_HAS_INCLUDE(x) 0
81#ifdef __has_cpp_attribute
82# define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
84# define FMT_HAS_CPP_ATTRIBUTE(x) 0
87#define FMT_HAS_CPP14_ATTRIBUTE(attribute) \
88 (FMT_CPLUSPLUS >= 201402L && FMT_HAS_CPP_ATTRIBUTE(attribute))
90#define FMT_HAS_CPP17_ATTRIBUTE(attribute) \
91 (FMT_CPLUSPLUS >= 201703L && FMT_HAS_CPP_ATTRIBUTE(attribute))
94#ifdef FMT_USE_CONSTEXPR
96#elif FMT_GCC_VERSION >= 600 && FMT_CPLUSPLUS >= 201402L
99# define FMT_USE_CONSTEXPR 1
101# define FMT_USE_CONSTEXPR 0
102#elif FMT_HAS_FEATURE(cxx_relaxed_constexpr) || FMT_MSC_VERSION >= 1912
103# define FMT_USE_CONSTEXPR 1
105# define FMT_USE_CONSTEXPR 0
108# define FMT_CONSTEXPR constexpr
110# define FMT_CONSTEXPR
114#if !defined(__cpp_lib_is_constant_evaluated)
115# define FMT_USE_CONSTEVAL 0
116#elif FMT_CPLUSPLUS < 201709L
117# define FMT_USE_CONSTEVAL 0
118#elif FMT_GLIBCXX_RELEASE && FMT_GLIBCXX_RELEASE < 10
119# define FMT_USE_CONSTEVAL 0
120#elif FMT_LIBCPP_VERSION && FMT_LIBCPP_VERSION < 10000
121# define FMT_USE_CONSTEVAL 0
122#elif defined(__apple_build_version__) && __apple_build_version__ < 14000029L
123# define FMT_USE_CONSTEVAL 0
124#elif FMT_MSC_VERSION && FMT_MSC_VERSION < 1929
125# define FMT_USE_CONSTEVAL 0
126#elif defined(__cpp_consteval)
127# define FMT_USE_CONSTEVAL 1
128#elif FMT_GCC_VERSION >= 1002 || FMT_CLANG_VERSION >= 1101
129# define FMT_USE_CONSTEVAL 1
131# define FMT_USE_CONSTEVAL 0
134# define FMT_CONSTEVAL consteval
135# define FMT_CONSTEXPR20 constexpr
137# define FMT_CONSTEVAL
138# define FMT_CONSTEXPR20
141#if defined(FMT_USE_NONTYPE_TEMPLATE_ARGS)
143#elif defined(__NVCOMPILER)
144# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
145#elif FMT_GCC_VERSION >= 903 && FMT_CPLUSPLUS >= 201709L
146# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
147#elif defined(__cpp_nontype_template_args) && \
148 __cpp_nontype_template_args >= 201911L
149# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
150#elif FMT_CLANG_VERSION >= 1200 && FMT_CPLUSPLUS >= 202002L
151# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
153# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
156#ifdef FMT_USE_CONCEPTS
158#elif defined(__cpp_concepts)
159# define FMT_USE_CONCEPTS 1
161# define FMT_USE_CONCEPTS 0
167#elif defined(__GNUC__) && !defined(__EXCEPTIONS)
168# define FMT_EXCEPTIONS 0
169#elif FMT_MSC_VERSION && !_HAS_EXCEPTIONS
170# define FMT_EXCEPTIONS 0
172# define FMT_EXCEPTIONS 1
176# define FMT_CATCH(x) catch (x)
178# define FMT_TRY if (true)
179# define FMT_CATCH(x) if (false)
182#if FMT_HAS_CPP17_ATTRIBUTE(fallthrough)
183# define FMT_FALLTHROUGH [[fallthrough]]
184#elif defined(__clang__)
185# define FMT_FALLTHROUGH [[clang::fallthrough]]
186#elif FMT_GCC_VERSION >= 700 && \
187 (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 520)
188# define FMT_FALLTHROUGH [[gnu::fallthrough]]
190# define FMT_FALLTHROUGH
194#if FMT_HAS_CPP_ATTRIBUTE(noreturn) && !FMT_MSC_VERSION && !defined(__NVCC__)
195# define FMT_NORETURN [[noreturn]]
201# if FMT_HAS_CPP17_ATTRIBUTE(nodiscard)
202# define FMT_NODISCARD [[nodiscard]]
204# define FMT_NODISCARD
210#elif FMT_HAS_CPP14_ATTRIBUTE(deprecated)
211# define FMT_DEPRECATED [[deprecated]]
213# define FMT_DEPRECATED
218#elif FMT_GCC_VERSION || FMT_CLANG_VERSION
219# define FMT_ALWAYS_INLINE inline __attribute__((always_inline))
221# define FMT_ALWAYS_INLINE inline
225# define FMT_INLINE FMT_ALWAYS_INLINE
227# define FMT_INLINE inline
230#if FMT_GCC_VERSION || FMT_CLANG_VERSION
231# define FMT_VISIBILITY(value) __attribute__((visibility(value)))
233# define FMT_VISIBILITY(value)
236#ifndef FMT_GCC_PRAGMA
239# if FMT_GCC_VERSION >= 504 && !defined(__NVCOMPILER)
240# define FMT_GCC_PRAGMA(arg) _Pragma(arg)
242# define FMT_GCC_PRAGMA(arg)
247#if FMT_GCC_VERSION && FMT_GCC_VERSION < 500
248# define FMT_DECLTYPE_THIS this->
250# define FMT_DECLTYPE_THIS
254# define FMT_MSC_WARNING(...) __pragma(warning(__VA_ARGS__))
255# define FMT_UNCHECKED_ITERATOR(It) \
256 using _Unchecked_type = It
258# define FMT_MSC_WARNING(...)
259# define FMT_UNCHECKED_ITERATOR(It) using unchecked_type = It
262#ifndef FMT_BEGIN_NAMESPACE
263# define FMT_BEGIN_NAMESPACE \
265 inline namespace v11 {
266# define FMT_END_NAMESPACE \
273# define FMT_BEGIN_EXPORT
274# define FMT_END_EXPORT
277#if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
278# if defined(FMT_LIB_EXPORT)
279# define FMT_API __declspec(dllexport)
280# elif defined(FMT_SHARED)
281# define FMT_API __declspec(dllimport)
283#elif defined(FMT_LIB_EXPORT) || defined(FMT_SHARED)
284# define FMT_API FMT_VISIBILITY("default")
291# define FMT_UNICODE 1
297# if defined(__GXX_RTTI) || FMT_HAS_FEATURE(cxx_rtti) || defined(_CPPRTTI) || \
298 defined(__INTEL_RTTI__) || defined(__RTTI)
299# define FMT_USE_RTTI 1
301# define FMT_USE_RTTI 0
305#define FMT_FWD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)
308FMT_GCC_PRAGMA(
"GCC push_options")
309#if !defined(__OPTIMIZE__) && !defined(__CUDACC__)
310FMT_GCC_PRAGMA(
"GCC optimize(\"Og\")")
316template <
bool B,
typename T =
void>
317using enable_if_t =
typename std::enable_if<B, T>::type;
318template <
bool B,
typename T,
typename F>
319using conditional_t =
typename std::conditional<B, T, F>::type;
320template <
bool B>
using bool_constant = std::integral_constant<bool, B>;
322using remove_reference_t =
typename std::remove_reference<T>::type;
324using remove_const_t =
typename std::remove_const<T>::type;
326using remove_cvref_t =
typename std::remove_cv<remove_reference_t<T>>::type;
330template <
typename T>
using type_identity_t =
typename type_identity<T>::type;
332using make_unsigned_t =
typename std::make_unsigned<T>::type;
334using underlying_t =
typename std::underlying_type<T>::type;
336#if FMT_GCC_VERSION && FMT_GCC_VERSION < 500
338template <
typename...>
struct void_t_impl {
341template <
typename... T>
using void_t =
typename void_t_impl<T...>::type;
343template <
typename...>
using void_t = void;
347 constexpr monostate() {}
354# define FMT_ENABLE_IF(...)
356# define FMT_ENABLE_IF(...) fmt::enable_if_t<(__VA_ARGS__), int> = 0
362template <
typename T, FMT_ENABLE_IF(std::is_same<T, std::
byte>::value)>
363inline auto format_as(T b) ->
unsigned char {
364 return static_cast<unsigned char>(b);
372template <
typename... T> FMT_CONSTEXPR
void ignore_unused(
const T&...) {}
374constexpr auto is_constant_evaluated(
bool default_value =
false) noexcept
379#if FMT_CPLUSPLUS >= 202002L && FMT_GLIBCXX_RELEASE >= 12 && \
380 (FMT_CLANG_VERSION >= 1400 && FMT_CLANG_VERSION < 1500)
381 ignore_unused(default_value);
382 return __builtin_is_constant_evaluated();
383#elif defined(__cpp_lib_is_constant_evaluated)
384 ignore_unused(default_value);
385 return std::is_constant_evaluated();
387 return default_value;
392template <
typename T>
constexpr auto const_check(T value) -> T {
return value; }
394FMT_NORETURN FMT_API
void assert_fail(
const char* file,
int line,
395 const char* message);
397#if defined(FMT_ASSERT)
401# define FMT_ASSERT(condition, message) \
402 fmt::detail::ignore_unused((condition), (message))
404# define FMT_ASSERT(condition, message) \
407 : fmt::detail::assert_fail(__FILE__, __LINE__, (message)))
412#elif defined(__SIZEOF_INT128__) && !defined(__NVCC__) && \
413 !(FMT_CLANG_VERSION && FMT_MSC_VERSION)
414# define FMT_USE_INT128 1
415using int128_opt = __int128_t;
416using uint128_opt = __uint128_t;
417template <
typename T>
inline auto convert_for_visit(T value) -> T {
421# define FMT_USE_INT128 0
424enum class int128_opt {};
425enum class uint128_opt {};
427template <
typename T>
auto convert_for_visit(T) ->
monostate {
return {}; }
431template <
typename Int>
432FMT_CONSTEXPR
auto to_unsigned(Int value) -> make_unsigned_t<Int> {
433 FMT_ASSERT(std::is_unsigned<Int>::value || value >= 0,
"negative value");
434 return static_cast<make_unsigned_t<Int>
>(value);
439template <
typename T,
typename Enable =
void>
443 typename T::value_type(), 0))>>
444 : std::is_convertible<decltype(std::declval<T>().data()),
445 const typename T::value_type*> {};
448constexpr auto is_utf8_enabled() ->
bool {
450 using uchar =
unsigned char;
451 return sizeof(
"\u00A7") == 3 && uchar(
"\u00A7"[0]) == 0xC2 &&
452 uchar(
"\u00A7"[1]) == 0xA7;
454constexpr auto use_utf8() ->
bool {
455 return !FMT_MSC_VERSION || is_utf8_enabled();
458static_assert(!FMT_UNICODE || use_utf8(),
459 "Unicode support requires compiling with /utf-8");
461template <
typename Char> FMT_CONSTEXPR
auto length(
const Char* s) ->
size_t {
467template <
typename Char>
468FMT_CONSTEXPR
auto compare(
const Char* s1,
const Char* s2, std::size_t n)
470 if (!is_constant_evaluated() &&
sizeof(Char) == 1)
return memcmp(s1, s2, n);
471 for (; n != 0; ++s1, ++s2, --n) {
472 if (*s1 < *s2)
return -1;
473 if (*s1 > *s2)
return 1;
481template <
typename Container>
482auto invoke_back_inserter()
483 ->
decltype(back_inserter(std::declval<Container&>()));
486template <
typename It,
typename Enable = std::true_type>
489template <
typename It>
491 It, bool_constant<std::is_same<
492 decltype(adl::invoke_back_inserter<typename It::container_type>()),
493 It>
::value>> : std::true_type {};
496template <
typename OutputIt>
497inline auto get_container(OutputIt it) ->
typename OutputIt::container_type& {
498 struct accessor : OutputIt {
499 accessor(OutputIt base) : OutputIt(base) {}
500 using OutputIt::container;
502 return *accessor(it).container;
517template <
typename Char>
class basic_string_view {
523 using value_type = Char;
524 using iterator =
const Char*;
526 constexpr basic_string_view() noexcept : data_(
nullptr), size_(0) {}
530 : data_(s), size_(count) {}
538 size_(detail::const_check(std::is_same<Char, char>::value &&
539 !detail::is_constant_evaluated(false))
540 ? strlen(reinterpret_cast<const char*>(s))
541 : detail::length(s)) {}
545 template <
typename S,
547 typename S::value_type, Char>::value)>
549 : data_(s.data()), size_(s.size()) {}
552 constexpr auto data() const noexcept -> const Char* {
return data_; }
555 constexpr auto size() const noexcept ->
size_t {
return size_; }
557 constexpr auto begin() const noexcept -> iterator {
return data_; }
558 constexpr auto end() const noexcept -> iterator {
return data_ + size_; }
560 constexpr auto operator[](
size_t pos)
const noexcept ->
const Char& {
564 FMT_CONSTEXPR
void remove_prefix(
size_t n)
noexcept {
569 FMT_CONSTEXPR
auto starts_with(basic_string_view<Char> sv)
const noexcept
571 return size_ >= sv.size_ && detail::compare(data_, sv.data_, sv.size_) == 0;
573 FMT_CONSTEXPR
auto starts_with(Char c)
const noexcept ->
bool {
574 return size_ >= 1 && *data_ == c;
576 FMT_CONSTEXPR
auto starts_with(
const Char* s)
const ->
bool {
577 return starts_with(basic_string_view<Char>(s));
581 FMT_CONSTEXPR
auto compare(basic_string_view other)
const ->
int {
582 size_t str_size = size_ < other.size_ ? size_ : other.size_;
583 int result = detail::compare(data_, other.data_, str_size);
585 result = size_ == other.size_ ? 0 : (size_ < other.size_ ? -1 : 1);
589 FMT_CONSTEXPR
friend auto operator==(basic_string_view lhs,
590 basic_string_view rhs) ->
bool {
591 return lhs.compare(rhs) == 0;
593 friend auto operator!=(basic_string_view lhs, basic_string_view rhs) ->
bool {
594 return lhs.compare(rhs) != 0;
596 friend auto operator<(basic_string_view lhs, basic_string_view rhs) ->
bool {
597 return lhs.compare(rhs) < 0;
599 friend auto operator<=(basic_string_view lhs, basic_string_view rhs) ->
bool {
600 return lhs.compare(rhs) <= 0;
602 friend auto operator>(basic_string_view lhs, basic_string_view rhs) ->
bool {
603 return lhs.compare(rhs) > 0;
605 friend auto operator>=(basic_string_view lhs, basic_string_view rhs) ->
bool {
606 return lhs.compare(rhs) >= 0;
615template <
typename T>
struct is_char : std::false_type {};
616template <>
struct is_char<char> : std::true_type {};
623template <
typename Char, FMT_ENABLE_IF(is_
char<Char>::value)>
627template <
typename T, FMT_ENABLE_IF(is_std_
string_like<T>::value)>
628constexpr auto to_string_view(
const T& s)
629 -> basic_string_view<typename T::value_type> {
632template <
typename Char>
633constexpr auto to_string_view(basic_string_view<Char> s)
634 -> basic_string_view<Char> {
638template <
typename T,
typename Enable =
void>
643 T, void_t<decltype(detail::to_string_view(std::declval<T>()))>>
647 static constexpr Char value[
sizeof...(C)] = {C...};
649 return {value,
sizeof...(C)};
652#if FMT_CPLUSPLUS < 201703L
653template <
typename Char, Char... C>
668 last_integer_type = char_type,
673 last_numeric_type = long_double_type,
681template <
typename T,
typename Char>
684#define FMT_TYPE_CONSTANT(Type, constant) \
685 template <typename Char> \
686 struct type_constant<Type, Char> \
687 : std::integral_constant<type, type::constant> {}
689FMT_TYPE_CONSTANT(
int, int_type);
690FMT_TYPE_CONSTANT(
unsigned, uint_type);
691FMT_TYPE_CONSTANT(
long long, long_long_type);
692FMT_TYPE_CONSTANT(
unsigned long long, ulong_long_type);
693FMT_TYPE_CONSTANT(int128_opt, int128_type);
694FMT_TYPE_CONSTANT(uint128_opt, uint128_type);
695FMT_TYPE_CONSTANT(
bool, bool_type);
696FMT_TYPE_CONSTANT(Char, char_type);
697FMT_TYPE_CONSTANT(
float, float_type);
698FMT_TYPE_CONSTANT(
double, double_type);
699FMT_TYPE_CONSTANT(
long double, long_double_type);
700FMT_TYPE_CONSTANT(
const Char*, cstring_type);
702FMT_TYPE_CONSTANT(
const void*, pointer_type);
704constexpr auto is_integral_type(type t) ->
bool {
705 return t > type::none_type && t <= type::last_integer_type;
707constexpr auto is_arithmetic_type(type t) ->
bool {
708 return t > type::none_type && t <= type::last_numeric_type;
711constexpr auto set(type rhs) ->
int {
return 1 <<
static_cast<int>(rhs); }
712constexpr auto in(type t,
int set) ->
bool {
713 return ((set >>
static_cast<int>(t)) & 1) != 0;
719 set(type::int_type) | set(type::long_long_type) | set(type::int128_type),
720 uint_set = set(type::uint_type) | set(type::ulong_long_type) |
721 set(type::uint128_type),
722 bool_set = set(type::bool_type),
723 char_set = set(type::char_type),
724 float_set = set(type::float_type) | set(type::double_type) |
725 set(type::long_double_type),
726 string_set = set(type::string_type),
727 cstring_set = set(type::cstring_type),
728 pointer_set = set(type::pointer_type)
735FMT_NORETURN FMT_API
void report_error(
const char* message);
737FMT_DEPRECATED FMT_NORETURN
inline void throw_format_error(
738 const char* message) {
739 report_error(message);
744 typename V =
decltype(detail::to_string_view(std::declval<S>()))>
745using char_t =
typename V::value_type;
753template <
typename Char>
class basic_format_parse_context {
758 FMT_CONSTEXPR
void do_check_arg_id(
int id);
761 using char_type = Char;
762 using iterator =
const Char*;
764 explicit constexpr basic_format_parse_context(
766 : format_str_(format_str), next_arg_id_(
next_arg_id) {}
770 constexpr auto begin() const noexcept -> iterator {
771 return format_str_.begin();
775 constexpr auto end() const noexcept -> iterator {
return format_str_.end(); }
779 format_str_.remove_prefix(detail::to_unsigned(it -
begin()));
785 if (next_arg_id_ < 0) {
786 report_error(
"cannot switch from manual to automatic argument indexing");
789 int id = next_arg_id_++;
797 if (next_arg_id_ > 0) {
798 report_error(
"cannot switch from automatic to manual argument indexing");
807 FMT_CONSTEXPR
void check_dynamic_spec(
int arg_id);
815template <
typename Char>
816class compile_parse_context :
public basic_format_parse_context<Char> {
820 using base = basic_format_parse_context<Char>;
823 explicit FMT_CONSTEXPR compile_parse_context(
826 : base(format_str, next_arg_id), num_args_(num_args), types_(types) {}
828 constexpr auto num_args()
const ->
int {
return num_args_; }
829 constexpr auto arg_type(
int id)
const -> type {
return types_[id]; }
831 FMT_CONSTEXPR
auto next_arg_id() ->
int {
833 if (
id >= num_args_) report_error(
"argument not found");
837 FMT_CONSTEXPR
void check_arg_id(
int id) {
839 if (
id >= num_args_) report_error(
"argument not found");
843 FMT_CONSTEXPR
void check_dynamic_spec(
int arg_id) {
844 detail::ignore_unused(arg_id);
845 if (arg_id < num_args_ && types_ && !is_integral_type(types_[arg_id]))
846 report_error(
"width/precision is not integer");
852template <
typename T>
class buffer {
858 using grow_fun = void (*)(buffer& buf,
size_t capacity);
863 FMT_MSC_WARNING(suppress : 26495)
864 FMT_CONSTEXPR20 buffer(grow_fun grow,
size_t sz) noexcept
865 : size_(sz), capacity_(sz), grow_(grow) {}
867 constexpr buffer(grow_fun grow, T* p =
nullptr,
size_t sz = 0,
868 size_t cap = 0) noexcept
869 : ptr_(p), size_(sz), capacity_(cap), grow_(grow) {}
871 FMT_CONSTEXPR20 ~buffer() =
default;
872 buffer(buffer&&) =
default;
875 FMT_CONSTEXPR
void set(T* buf_data,
size_t buf_capacity)
noexcept {
877 capacity_ = buf_capacity;
881 using value_type = T;
882 using const_reference =
const T&;
885 void operator=(
const buffer&) =
delete;
887 auto begin() noexcept -> T* {
return ptr_; }
888 auto end() noexcept -> T* {
return ptr_ + size_; }
890 auto begin() const noexcept -> const T* {
return ptr_; }
891 auto end() const noexcept -> const T* {
return ptr_ + size_; }
894 constexpr auto size() const noexcept ->
size_t {
return size_; }
897 constexpr auto capacity() const noexcept ->
size_t {
return capacity_; }
900 FMT_CONSTEXPR
auto data() noexcept -> T* {
return ptr_; }
901 FMT_CONSTEXPR
auto data() const noexcept -> const T* {
return ptr_; }
908 FMT_CONSTEXPR
void try_resize(
size_t count) {
910 size_ = count <= capacity_ ? count : capacity_;
917 FMT_CONSTEXPR
void try_reserve(
size_t new_capacity) {
918 if (new_capacity > capacity_) grow_(*
this, new_capacity);
921 FMT_CONSTEXPR
void push_back(
const T& value) {
922 try_reserve(size_ + 1);
923 ptr_[size_++] = value;
927 template <
typename U>
void append(
const U* begin,
const U* end) {
928 while (begin != end) {
929 auto count = to_unsigned(end - begin);
930 try_reserve(size_ + count);
931 auto free_cap = capacity_ - size_;
932 if (free_cap < count) count = free_cap;
934 T* out = ptr_ + size_;
935 for (
size_t i = 0; i < count; ++i) out[i] = begin[i];
941 template <
typename Idx> FMT_CONSTEXPR
auto operator[](Idx index) -> T& {
944 template <
typename Idx>
945 FMT_CONSTEXPR
auto operator[](Idx index)
const ->
const T& {
950struct buffer_traits {
951 explicit buffer_traits(
size_t) {}
952 auto count()
const ->
size_t {
return 0; }
953 auto limit(
size_t size) ->
size_t {
return size; }
956class fixed_buffer_traits {
962 explicit fixed_buffer_traits(
size_t limit) : limit_(limit) {}
963 auto count()
const ->
size_t {
return count_; }
964 auto limit(
size_t size) ->
size_t {
965 size_t n = limit_ > count_ ? limit_ - count_ : 0;
967 return size < n ? size : n;
972template <
typename OutputIt,
typename T,
typename Traits = buffer_traits>
973class iterator_buffer :
public Traits,
public buffer<T> {
976 enum { buffer_size = 256 };
977 T data_[buffer_size];
979 static FMT_CONSTEXPR
void grow(buffer<T>& buf,
size_t) {
980 if (buf.
size() == buffer_size)
static_cast<iterator_buffer&
>(buf).flush();
986 const T* begin = data_;
987 const T* end = begin + this->limit(
size);
988 while (begin != end) *out_++ = *begin++;
992 explicit iterator_buffer(OutputIt out,
size_t n = buffer_size)
993 : Traits(n), buffer<T>(grow, data_, 0, buffer_size), out_(out) {}
994 iterator_buffer(iterator_buffer&& other) noexcept
996 buffer<T>(grow, data_, 0, buffer_size),
1000 FMT_TRY { flush(); }
1004 auto out() -> OutputIt {
1008 auto count()
const ->
size_t {
return Traits::count() + this->
size(); }
1011template <
typename T>
1012class iterator_buffer<T*, T, fixed_buffer_traits> :
public fixed_buffer_traits,
1016 enum { buffer_size = 256 };
1017 T data_[buffer_size];
1019 static FMT_CONSTEXPR
void grow(buffer<T>& buf,
size_t) {
1021 static_cast<iterator_buffer&
>(buf).flush();
1025 size_t n = this->limit(this->
size());
1026 if (this->
data() == out_) {
1028 this->
set(data_, buffer_size);
1034 explicit iterator_buffer(T* out,
size_t n = buffer_size)
1035 : fixed_buffer_traits(n), buffer<T>(grow, out, 0, n), out_(out) {}
1036 iterator_buffer(iterator_buffer&& other) noexcept
1037 : fixed_buffer_traits(other),
1038 buffer<T>(
static_cast<iterator_buffer&&
>(other)),
1040 if (this->
data() != out_) {
1041 this->
set(data_, buffer_size);
1045 ~iterator_buffer() { flush(); }
1051 auto count()
const ->
size_t {
1052 return fixed_buffer_traits::count() + this->
size();
1056template <
typename T>
class iterator_buffer<T*, T> :
public buffer<T> {
1058 explicit iterator_buffer(T* out,
size_t = 0)
1059 : buffer<T>([](buffer<T>&,
size_t) {}, out, 0, ~size_t()) {}
1061 auto out() -> T* {
return &*this->end(); }
1065template <
typename OutputIt>
1066class iterator_buffer<
1070 typename OutputIt::container_type::value_type>>
1071 :
public buffer<typename OutputIt::container_type::value_type> {
1073 using container_type =
typename OutputIt::container_type;
1074 using value_type =
typename container_type::value_type;
1075 container_type& container_;
1077 static FMT_CONSTEXPR
void grow(buffer<value_type>& buf,
size_t capacity) {
1078 auto& self =
static_cast<iterator_buffer&
>(buf);
1080 self.set(&self.container_[0],
capacity);
1084 explicit iterator_buffer(container_type& c)
1085 : buffer<value_type>(grow, c.size()), container_(c) {}
1086 explicit iterator_buffer(OutputIt out,
size_t = 0)
1087 : iterator_buffer(get_container(out)) {}
1089 auto out() -> OutputIt {
return back_inserter(container_); }
1093template <
typename T =
char>
class counting_buffer :
public buffer<T> {
1095 enum { buffer_size = 256 };
1096 T data_[buffer_size];
1099 static FMT_CONSTEXPR
void grow(buffer<T>& buf,
size_t) {
1100 if (buf.
size() != buffer_size)
return;
1101 static_cast<counting_buffer&
>(buf).count_ += buf.
size();
1106 counting_buffer() : buffer<T>(grow, data_, 0, buffer_size) {}
1108 auto count() ->
size_t {
return count_ + this->
size(); }
1112template <
typename Char>
1113FMT_CONSTEXPR
void basic_format_parse_context<Char>::do_check_arg_id(
int id) {
1116 if (detail::is_constant_evaluated() &&
1117 (!FMT_GCC_VERSION || FMT_GCC_VERSION >= 1200)) {
1119 if (
id >=
static_cast<context*
>(
this)->num_args())
1120 report_error(
"argument not found");
1124template <
typename Char>
1125FMT_CONSTEXPR
void basic_format_parse_context<Char>::check_dynamic_spec(
1127 if (detail::is_constant_evaluated() &&
1128 (!FMT_GCC_VERSION || FMT_GCC_VERSION >= 1200)) {
1130 static_cast<context*
>(
this)->check_dynamic_spec(arg_id);
1140template <
typename T,
typename Char =
char,
typename Enable =
void>
1143 formatter() =
delete;
1148template <
typename T,
typename Context>
1149using has_formatter =
1150 std::is_constructible<typename Context::template formatter_type<T>>;
1154template <
typename T>
class basic_appender {
1159 return *app.buffer_;
1163 using iterator_category = int;
1164 using value_type = T;
1165 using difference_type = ptrdiff_t;
1167 using reference = T&;
1169 FMT_UNCHECKED_ITERATOR(basic_appender);
1173 auto operator=(T c) -> basic_appender& {
1174 buffer_->push_back(c);
1177 auto operator*() -> basic_appender& {
return *
this; }
1178 auto operator++() -> basic_appender& {
return *
this; }
1179 auto operator++(
int) -> basic_appender {
return *
this; }
1185template <
typename T>
1188template <
typename T,
typename Enable =
void>
1190template <
typename T>
1192 : std::false_type {};
1194template <
typename T =
int> FMT_CONSTEXPR
inline auto is_locking() ->
bool {
1197template <
typename T1,
typename T2,
typename... Tail>
1198FMT_CONSTEXPR
inline auto is_locking() ->
bool {
1199 return locking<T1>::value || is_locking<T2, Tail...>();
1203template <
typename T,
typename InputIt,
typename OutputIt,
1205auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
1206 get_container(out).append(begin, end);
1210template <
typename T,
typename InputIt,
typename OutputIt,
1212FMT_CONSTEXPR
auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
1213 while (begin != end) *out++ =
static_cast<T
>(*begin++);
1217template <
typename T,
typename V,
typename OutputIt>
1218FMT_CONSTEXPR
auto copy(basic_string_view<V> s, OutputIt out) -> OutputIt {
1219 return copy<T>(s.begin(), s.end(), out);
1222template <
typename Context,
typename T>
1223constexpr auto has_const_formatter_impl(T*)
1224 ->
decltype(
typename Context::template formatter_type<T>().format(
1225 std::declval<const T&>(), std::declval<Context&>()),
1229template <
typename Context>
1230constexpr auto has_const_formatter_impl(...) ->
bool {
1233template <
typename T,
typename Context>
1234constexpr auto has_const_formatter() ->
bool {
1235 return has_const_formatter_impl<Context>(
static_cast<T*
>(
nullptr));
1238template <
typename It,
typename Enable = std::true_type>
1240template <
typename It>
1244 std::is_base_of<buffer<typename It::container_type::value_type>,
1245 typename It::container_type>
::value>>
1246 : std::true_type {};
1249template <
typename T,
typename OutputIt,
1254template <
typename T,
typename OutputIt,
1255 FMT_ENABLE_IF(is_buffer_appender<OutputIt>::value)>
1256auto get_buffer(OutputIt out) -> buffer<T>& {
1257 return get_container(out);
1260template <
typename Buf,
typename OutputIt>
1261auto get_iterator(Buf& buf, OutputIt) ->
decltype(buf.out()) {
1264template <
typename T,
typename OutputIt>
1265auto get_iterator(
buffer<T>&, OutputIt out) -> OutputIt {
1271template <
typename Char,
typename T>
struct named_arg :
view {
1274 named_arg(
const Char* n,
const T& v) : name(n), value(v) {}
1285template <
typename T,
typename Char>
1288template <
bool B = false>
constexpr auto count() ->
size_t {
return B ? 1 : 0; }
1289template <
bool B1,
bool B2,
bool... Tail>
constexpr auto count() ->
size_t {
1290 return (B1 ? 1 : 0) + count<B2, Tail...>();
1293template <
typename... Args>
constexpr auto count_named_args() ->
size_t {
1294 return count<is_named_arg<Args>::value...>();
1297template <
typename... Args>
1298constexpr auto count_statically_named_args() ->
size_t {
1299 return count<is_statically_named_arg<Args>::value...>();
1317 using parse_context =
typename Context::parse_context_type;
1319 void (*format)(
void* arg, parse_context& parse_ctx, Context& ctx);
1323template <
typename Context>
class value {
1325 using char_type =
typename Context::char_type;
1330 unsigned uint_value;
1331 long long long_long_value;
1332 unsigned long long ulong_long_value;
1333 int128_opt int128_value;
1334 uint128_opt uint128_value;
1336 char_type char_value;
1338 double double_value;
1339 long double long_double_value;
1340 const void* pointer;
1346 constexpr FMT_ALWAYS_INLINE value() : no_value() {}
1347 constexpr FMT_ALWAYS_INLINE value(
int val) : int_value(val) {}
1348 constexpr FMT_ALWAYS_INLINE value(
unsigned val) : uint_value(val) {}
1349 constexpr FMT_ALWAYS_INLINE value(
long long val) : long_long_value(val) {}
1350 constexpr FMT_ALWAYS_INLINE value(
unsigned long long val)
1351 : ulong_long_value(val) {}
1352 FMT_ALWAYS_INLINE value(int128_opt val) : int128_value(val) {}
1353 FMT_ALWAYS_INLINE value(uint128_opt val) : uint128_value(val) {}
1354 constexpr FMT_ALWAYS_INLINE value(
float val) : float_value(val) {}
1355 constexpr FMT_ALWAYS_INLINE value(
double val) : double_value(val) {}
1356 FMT_ALWAYS_INLINE value(
long double val) : long_double_value(val) {}
1357 constexpr FMT_ALWAYS_INLINE value(
bool val) : bool_value(val) {}
1358 constexpr FMT_ALWAYS_INLINE value(char_type val) : char_value(val) {}
1359 FMT_CONSTEXPR FMT_ALWAYS_INLINE value(
const char_type* val) {
1361 if (is_constant_evaluated())
string.size = {};
1364 string.data = val.
data();
1365 string.size = val.
size();
1367 FMT_ALWAYS_INLINE value(
const void* val) : pointer(val) {}
1369 : named_args{args, size} {}
1371 template <
typename T> FMT_CONSTEXPR20 FMT_ALWAYS_INLINE value(T& val) {
1372 using value_type = remove_const_t<T>;
1374#if defined(__cpp_if_constexpr)
1375 if constexpr (std::is_same<
decltype(&val), T*>::value)
1376 custom.value =
const_cast<value_type*
>(&val);
1378 if (!is_constant_evaluated())
1379 custom.value =
const_cast<char*
>(&
reinterpret_cast<const char&
>(val));
1383 custom.format = format_custom_arg<
1384 value_type,
typename Context::template formatter_type<value_type>>;
1392 template <
typename T,
typename Formatter>
1393 static void format_custom_arg(
void* arg,
1394 typename Context::parse_context_type& parse_ctx,
1396 auto f = Formatter();
1397 parse_ctx.advance_to(f.parse(parse_ctx));
1398 using qualified_type =
1399 conditional_t<has_const_formatter<T, Context>(),
const T, T>;
1402 ctx.advance_to(cf.format(*
static_cast<qualified_type*
>(arg), ctx));
1408enum { long_short =
sizeof(long) ==
sizeof(
int) };
1409using long_type = conditional_t<long_short, int, long long>;
1410using ulong_type = conditional_t<long_short, unsigned, unsigned long long>;
1413 template <
typename U,
1414 FMT_ENABLE_IF(std::is_enum<U>::value || std::is_class<U>::value)>
1415 static auto map(U*) -> remove_cvref_t<decltype(format_as(std::declval<U>()))>;
1416 static auto map(...) -> void;
1418 using type =
decltype(map(
static_cast<T*
>(
nullptr)));
1420template <
typename T>
using format_as_t =
typename format_as_result<T>::type;
1422template <
typename T>
1424 : bool_constant<!std::is_same<format_as_t<T>, void>::value> {};
1426#define FMT_MAP_API FMT_CONSTEXPR FMT_ALWAYS_INLINE
1432 using char_type =
typename Context::char_type;
1434 FMT_MAP_API
auto map(
signed char val) ->
int {
return val; }
1435 FMT_MAP_API
auto map(
unsigned char val) ->
unsigned {
return val; }
1436 FMT_MAP_API
auto map(
short val) ->
int {
return val; }
1437 FMT_MAP_API
auto map(
unsigned short val) ->
unsigned {
return val; }
1438 FMT_MAP_API
auto map(
int val) ->
int {
return val; }
1439 FMT_MAP_API
auto map(
unsigned val) ->
unsigned {
return val; }
1440 FMT_MAP_API
auto map(
long val) -> long_type {
return val; }
1441 FMT_MAP_API
auto map(
unsigned long val) -> ulong_type {
return val; }
1442 FMT_MAP_API
auto map(
long long val) ->
long long {
return val; }
1443 FMT_MAP_API
auto map(
unsigned long long val) ->
unsigned long long {
1446 FMT_MAP_API
auto map(int128_opt val) -> int128_opt {
return val; }
1447 FMT_MAP_API
auto map(uint128_opt val) -> uint128_opt {
return val; }
1448 FMT_MAP_API
auto map(
bool val) ->
bool {
return val; }
1450 template <
typename T, FMT_ENABLE_IF(std::is_same<T,
char>::value ||
1451 std::is_same<T,
char_type>::value)>
1452 FMT_MAP_API
auto map(T val) -> char_type {
1455 template <
typename T, enable_if_t<(std::is_same<T,
wchar_t>::value ||
1457 std::is_same<T,
char8_t>::value ||
1459 std::is_same<T,
char16_t>::value ||
1460 std::is_same<T,
char32_t>::value) &&
1461 !std::is_same<T,
char_type>::value,
1467 FMT_MAP_API
auto map(
float val) ->
float {
return val; }
1468 FMT_MAP_API
auto map(
double val) ->
double {
return val; }
1469 FMT_MAP_API
auto map(
long double val) ->
long double {
return val; }
1471 FMT_MAP_API
auto map(char_type* val) ->
const char_type* {
return val; }
1472 FMT_MAP_API
auto map(
const char_type* val) ->
const char_type* {
return val; }
1473 template <
typename T,
typename Char =
char_t<T>,
1474 FMT_ENABLE_IF(std::is_same<Char,
char_type>::value &&
1475 !std::is_po
inter<T>::value)>
1477 return to_string_view(val);
1479 template <
typename T,
typename Char =
char_t<T>,
1480 FMT_ENABLE_IF(!std::is_same<Char,
char_type>::value &&
1481 !std::is_po
inter<T>::value)>
1486 FMT_MAP_API
auto map(
void* val) ->
const void* {
return val; }
1487 FMT_MAP_API
auto map(
const void* val) ->
const void* {
return val; }
1488 FMT_MAP_API
auto map(
volatile void* val) ->
const void* {
1489 return const_cast<const void*
>(val);
1491 FMT_MAP_API
auto map(
const volatile void* val) ->
const void* {
1492 return const_cast<const void*
>(val);
1494 FMT_MAP_API
auto map(std::nullptr_t val) ->
const void* {
return val; }
1501 std::is_pointer<T>::value || std::is_member_pointer<T>::value ||
1502 std::is_function<
typename std::remove_pointer<T>::type>
::value ||
1503 (std::is_array<T>::value &&
1504 !std::is_convertible<T, const char_type*>::value))>
1509 template <
typename T, std::size_t N,
1510 FMT_ENABLE_IF(!std::is_same<T, wchar_t>::value)>
1511 FMT_MAP_API
auto map(
const T (&values)[N]) ->
const T (&)[N] {
1516 template <
typename T,
typename U = format_as_t<T>,
1517 FMT_ENABLE_IF(std::is_arithmetic<U>::value)>
1518 FMT_MAP_API
auto map(
const T& val) ->
decltype(FMT_DECLTYPE_THIS map(U())) {
1519 return map(format_as(val));
1522 template <
typename T,
typename U = remove_const_t<T>>
1523 struct formattable : bool_constant<has_const_formatter<U, Context>() ||
1524 (has_formatter<U, Context>::value &&
1525 !std::is_const<T>::value)> {};
1527 template <
typename T, FMT_ENABLE_IF(formattable<T>::value)>
1528 FMT_MAP_API
auto do_map(T& val) -> T& {
1531 template <
typename T, FMT_ENABLE_IF(!formattable<T>::value)>
1537 template <
typename T,
typename U = remove_const_t<T>,
1539 (std::is_
class<U>::value || std::is_enum<U>::value ||
1540 std::is_union<U>::value || std::is_fundamental<U>::value) &&
1541 !has_to_
string_view<U>::value && !is_
char<U>::value &&
1542 !is_named_arg<U>::value && !std::is_
integral<U>::value &&
1543 !std::is_arithmetic<format_as_t<U>>::value)>
1544 FMT_MAP_API
auto map(T& val) ->
decltype(FMT_DECLTYPE_THIS do_map(val)) {
1548 template <
typename T, FMT_ENABLE_IF(is_named_arg<T>::value)>
1549 FMT_MAP_API
auto map(
const T& named_arg)
1550 ->
decltype(FMT_DECLTYPE_THIS map(named_arg.value)) {
1551 return map(named_arg.value);
1554 auto map(...) -> unformattable {
return {}; }
1558template <
typename T,
typename Context>
1559using mapped_type_constant =
1561 typename Context::char_type>;
1563enum { packed_arg_bits = 4 };
1565enum { max_packed_args = 62 / packed_arg_bits };
1566enum :
unsigned long long { is_unpacked_bit = 1ULL << 63 };
1567enum :
unsigned long long { has_named_args_bit = 1ULL << 62 };
1569template <
typename It,
typename T,
typename Enable =
void>
1574template <
typename It,
typename T>
1576 It, T, void_t<decltype(*std::declval<It&>()++ = std::declval<T>())>>
1577 : std::true_type {};
1582 const void* locale_;
1585 constexpr locale_ref() : locale_(
nullptr) {}
1586 template <
typename Locale>
explicit locale_ref(
const Locale& loc);
1588 explicit operator bool()
const noexcept {
return locale_ !=
nullptr; }
1590 template <
typename Locale>
auto get()
const -> Locale;
1593template <
typename>
constexpr auto encode_types() ->
unsigned long long {
1597template <
typename Context,
typename Arg,
typename... Args>
1598constexpr auto encode_types() ->
unsigned long long {
1599 return static_cast<unsigned>(mapped_type_constant<Arg, Context>::value) |
1600 (encode_types<Context, Args...>() << packed_arg_bits);
1603template <
typename Context,
typename... T,
size_t NUM_ARGS =
sizeof...(T)>
1604constexpr unsigned long long make_descriptor() {
1605 return NUM_ARGS <= max_packed_args ? encode_types<Context, T...>()
1606 : is_unpacked_bit | NUM_ARGS;
1610template <
typename T,
typename Char>
1611#if FMT_CLANG_VERSION && FMT_CLANG_VERSION <= 1500
1619template <
bool PACKED,
typename Context,
typename T, FMT_ENABLE_IF(PACKED)>
1621 using arg_type = remove_cvref_t<decltype(arg_mapper<Context>().map(val))>;
1625 formattable_char = !std::is_same<arg_type, unformattable_char>::value
1627 static_assert(formattable_char,
"Mixing character types is disallowed.");
1633 formattable_pointer = !std::is_same<arg_type, unformattable_pointer>::value
1635 static_assert(formattable_pointer,
1636 "Formatting of non-void pointers is disallowed.");
1638 enum { formattable = !std::is_same<arg_type, unformattable>::value };
1639#if defined(__cpp_if_constexpr)
1640 if constexpr (!formattable)
1645 "Cannot format an argument. To make type T formattable provide a "
1646 "formatter<T> specialization: https://fmt.dev/latest/api.html#udt");
1650template <
typename Context,
typename T>
1653 arg.type_ = mapped_type_constant<T, Context>::value;
1654 arg.value_ = make_arg<true, Context>(val);
1658template <
bool PACKED,
typename Context,
typename T, FMT_ENABLE_IF(!PACKED)>
1660 return make_arg<Context>(val);
1663template <
typename Context,
size_t NUM_ARGS>
1664using arg_t = conditional_t<NUM_ARGS <= max_packed_args, value<Context>,
1665 basic_format_arg<Context>>;
1667template <
typename Char,
typename T, FMT_ENABLE_IF(!is_named_arg<T>::value)>
1671template <
typename Char,
typename T, FMT_ENABLE_IF(is_named_arg<T>::value)>
1673 int& named_arg_index,
const T& arg) {
1674 named_args[named_arg_index++] = {arg.name, arg_index++};
1680template <
typename Context,
size_t NUM_ARGS,
size_t NUM_NAMED_ARGS,
1681 unsigned long long DESC>
1682struct format_arg_store {
1685 static constexpr size_t ARGS_ARR_SIZE = 1 + (NUM_ARGS != 0 ? NUM_ARGS : +1);
1687 arg_t<Context, NUM_ARGS> args[ARGS_ARR_SIZE];
1690 template <
typename... T>
1691 FMT_MAP_API format_arg_store(T&... values)
1692 : args{{named_args, NUM_NAMED_ARGS},
1693 make_arg<NUM_ARGS <= max_packed_args, Context>(values)...} {
1694 using dummy =
int[];
1695 int arg_index = 0, named_arg_index = 0;
1698 (init_named_arg(named_args, arg_index, named_arg_index, values), 0)...};
1701 format_arg_store(format_arg_store&& rhs) {
1702 args[0] = {named_args, NUM_NAMED_ARGS};
1703 for (
size_t i = 1; i < ARGS_ARR_SIZE; ++i) args[i] = rhs.args[i];
1704 for (
size_t i = 0; i < NUM_NAMED_ARGS; ++i)
1705 named_args[i] = rhs.named_args[i];
1708 format_arg_store(
const format_arg_store& rhs) =
delete;
1709 format_arg_store& operator=(
const format_arg_store& rhs) =
delete;
1710 format_arg_store& operator=(format_arg_store&& rhs) =
delete;
1715template <
typename Context,
size_t NUM_ARGS,
unsigned long long DESC>
1716struct format_arg_store<Context, NUM_ARGS, 0, DESC> {
1718 arg_t<Context, NUM_ARGS> args[NUM_ARGS != 0 ? NUM_ARGS : +1];
1726template <
typename Context>
class basic_format_arg {
1731 template <
typename ContextType,
typename T>
1732 friend FMT_CONSTEXPR
auto detail::make_arg(T& value)
1733 -> basic_format_arg<ContextType>;
1738 using char_type =
typename Context::char_type;
1740 template <
typename,
size_t,
size_t,
unsigned long long>
1744 : value_(args, size) {}
1751 void format(
typename Context::parse_context_type& parse_ctx,
1752 Context& ctx)
const {
1753 custom_.format(custom_.value, parse_ctx, ctx);
1760 constexpr basic_format_arg() : type_(detail::type::none_type) {}
1762 constexpr explicit operator bool() const noexcept {
1763 return type_ != detail::type::none_type;
1766 auto type() const -> detail::type {
return type_; }
1768 auto is_integral() const ->
bool {
return detail::is_integral_type(type_); }
1769 auto is_arithmetic() const ->
bool {
1770 return detail::is_arithmetic_type(type_);
1778 template <
typename Visitor>
1779 FMT_CONSTEXPR FMT_INLINE
auto visit(Visitor&& vis)
const ->
decltype(vis(0)) {
1781 case detail::type::none_type:
1783 case detail::type::int_type:
1784 return vis(value_.int_value);
1785 case detail::type::uint_type:
1786 return vis(value_.uint_value);
1787 case detail::type::long_long_type:
1788 return vis(value_.long_long_value);
1789 case detail::type::ulong_long_type:
1790 return vis(value_.ulong_long_value);
1791 case detail::type::int128_type:
1792 return vis(detail::convert_for_visit(value_.int128_value));
1793 case detail::type::uint128_type:
1794 return vis(detail::convert_for_visit(value_.uint128_value));
1795 case detail::type::bool_type:
1796 return vis(value_.bool_value);
1797 case detail::type::char_type:
1798 return vis(value_.char_value);
1799 case detail::type::float_type:
1800 return vis(value_.float_value);
1801 case detail::type::double_type:
1802 return vis(value_.double_value);
1803 case detail::type::long_double_type:
1804 return vis(value_.long_double_value);
1805 case detail::type::cstring_type:
1806 return vis(value_.string.data);
1807 case detail::type::string_type:
1809 return vis(sv(value_.string.data, value_.string.size));
1810 case detail::type::pointer_type:
1811 return vis(value_.pointer);
1812 case detail::type::custom_type:
1818 auto format_custom(
const char_type* parse_begin,
1819 typename Context::parse_context_type& parse_ctx,
1820 Context& ctx) ->
bool {
1821 if (type_ != detail::type::custom_type)
return false;
1822 parse_ctx.advance_to(parse_begin);
1823 value_.custom.format(value_.custom.value, parse_ctx, ctx);
1828template <
typename Visitor,
typename Context>
1829FMT_DEPRECATED FMT_CONSTEXPR
auto visit_format_arg(
1831 return arg.visit(
static_cast<Visitor&&
>(vis));
1842template <
typename Context>
class basic_format_args {
1844 using size_type = int;
1852 unsigned long long desc_;
1860 const format_arg* args_;
1863 constexpr auto is_packed()
const ->
bool {
1864 return (desc_ & detail::is_unpacked_bit) == 0;
1866 constexpr auto has_named_args()
const ->
bool {
1867 return (desc_ & detail::has_named_args_bit) != 0;
1870 FMT_CONSTEXPR
auto type(
int index)
const -> detail::type {
1871 int shift = index * detail::packed_arg_bits;
1872 unsigned int mask = (1 << detail::packed_arg_bits) - 1;
1873 return static_cast<detail::type
>((desc_ >> shift) & mask);
1877 constexpr basic_format_args() : desc_(0), args_(
nullptr) {}
1880 template <
size_t NUM_ARGS,
size_t NUM_NAMED_ARGS,
unsigned long long DESC,
1881 FMT_ENABLE_IF(NUM_ARGS <= detail::max_packed_args)>
1885 : desc_(DESC), values_(store.args + (NUM_NAMED_ARGS != 0 ? 1 : 0)) {}
1887 template <
size_t NUM_ARGS,
size_t NUM_NAMED_ARGS,
unsigned long long DESC,
1888 FMT_ENABLE_IF(NUM_ARGS > detail::max_packed_args)>
1892 : desc_(DESC), args_(store.args + (NUM_NAMED_ARGS != 0 ? 1 : 0)) {}
1896 : desc_(store.get_types()), args_(store.data()) {}
1900 : desc_(detail::is_unpacked_bit | detail::to_unsigned(count)),
1904 FMT_CONSTEXPR
auto get(
int id)
const -> format_arg {
1907 if (
id < max_size()) arg = args_[id];
1910 if (
static_cast<unsigned>(
id) >= detail::max_packed_args)
return arg;
1911 arg.type_ = type(
id);
1912 if (arg.type_ == detail::type::none_type)
return arg;
1913 arg.value_ = values_[id];
1917 template <
typename Char>
1919 int id = get_id(name);
1920 return id >= 0 ?
get(
id) : format_arg();
1923 template <
typename Char>
1924 FMT_CONSTEXPR
auto get_id(basic_string_view<Char> name)
const ->
int {
1925 if (!has_named_args())
return -1;
1926 const auto& named_args =
1927 (is_packed() ? values_[-1] : args_[-1].value_).named_args;
1928 for (
size_t i = 0; i < named_args.size; ++i) {
1929 if (named_args.data[i].name == name)
return named_args.data[i].id;
1934 auto max_size() const ->
int {
1935 unsigned long long max_packed = detail::max_packed_args;
1936 return static_cast<int>(is_packed() ? max_packed
1937 : desc_ & ~detail::is_unpacked_bit);
1952 using iterator = appender;
1961 : out_(out), args_(ctx_args), loc_(loc) {}
1964 void operator=(
const context&) =
delete;
1966 FMT_CONSTEXPR
auto arg(
int id)
const -> format_arg {
return args_.get(
id); }
1967 auto arg(string_view name) -> format_arg {
return args_.get(name); }
1968 FMT_CONSTEXPR
auto arg_id(string_view name) ->
int {
1969 return args_.get_id(name);
1971 auto args() const -> const basic_format_args<
context>& {
return args_; }
1974 FMT_CONSTEXPR
auto out() -> iterator {
return out_; }
1977 void advance_to(iterator) {}
1979 FMT_CONSTEXPR
auto locale() -> detail::locale_ref {
return loc_; }
1985template <
typename OutputIt,
typename Char>
1986using basic_format_context =
1987 conditional_t<std::is_same<OutputIt, appender>::value,
context,
1989using format_context =
context;
1991template <
typename Char>
1992using buffered_context = basic_format_context<basic_appender<Char>, Char>;
1994template <
typename T,
typename Char =
char>
1995using is_formattable = bool_constant<!std::is_base_of<
1997 .map(std::declval<T&>()))>::value>;
2000template <
typename T,
typename Char =
char>
2001concept formattable = is_formattable<remove_reference_t<T>, Char>::value;
2011template <
typename Context = format_context,
typename... T,
2012 size_t NUM_ARGS =
sizeof...(T),
2013 size_t NUM_NAMED_ARGS = detail::count_named_args<T...>(),
2014 unsigned long long DESC = detail::make_descriptor<Context, T...>(),
2015 FMT_ENABLE_IF(NUM_NAMED_ARGS == 0)>
2016constexpr FMT_ALWAYS_INLINE
auto make_format_args(T&... args)
2018 return {{detail::make_arg<NUM_ARGS <= detail::max_packed_args, Context>(
2023template <
typename Context = format_context,
typename... T,
2024 size_t NUM_NAMED_ARGS = detail::count_named_args<T...>(),
2025 unsigned long long DESC =
2026 detail::make_descriptor<Context, T...>() |
2027 static_cast<unsigned long long>(detail::has_named_args_bit),
2028 FMT_ENABLE_IF(NUM_NAMED_ARGS != 0)>
2029constexpr auto make_format_args(T&... args)
2044template <
typename Char,
typename T>
2060#if FMT_GCC_VERSION && FMT_GCC_VERSION < 903
2061# define FMT_ENUM_UNDERLYING_TYPE(type)
2063# define FMT_ENUM_UNDERLYING_TYPE(type) : type
2066enum type FMT_ENUM_UNDERLYING_TYPE(
unsigned char){none, left, right, center,
2069using align_t = align::type;
2071enum type FMT_ENUM_UNDERLYING_TYPE(
unsigned char){none, minus, plus, space};
2073using sign_t = sign::type;
2077template <
typename Char>
2078using unsigned_char =
typename conditional_t<std::is_integral<Char>::value,
2079 std::make_unsigned<Char>,
2085 enum { max_size = 4 };
2086 char data_[max_size] = {
' '};
2087 unsigned char size_ = 1;
2090 template <
typename Char>
2092 auto size = s.
size();
2093 size_ =
static_cast<unsigned char>(size);
2095 unsigned uchar =
static_cast<unsigned_char<Char>
>(s[0]);
2096 data_[0] =
static_cast<char>(uchar);
2097 data_[1] =
static_cast<char>(uchar >> 8);
2100 FMT_ASSERT(size <= max_size,
"invalid fill");
2101 for (
size_t i = 0; i < size; ++i) data_[i] = static_cast<char>(s[i]);
2104 FMT_CONSTEXPR
void operator=(
char c) {
2109 constexpr auto size()
const ->
size_t {
return size_; }
2111 template <
typename Char>
constexpr auto get()
const -> Char {
2112 using uchar =
unsigned char;
2113 return static_cast<Char
>(
static_cast<uchar
>(data_[0]) |
2114 (
static_cast<uchar
>(data_[1]) << 8));
2117 template <
typename Char, FMT_ENABLE_IF(std::is_same<Char,
char>::value)>
2118 constexpr auto data()
const ->
const Char* {
2121 template <
typename Char, FMT_ENABLE_IF(!std::is_same<Char,
char>::value)>
2122 constexpr auto data()
const ->
const Char* {
2128enum class presentation_type :
unsigned char {
2152struct format_specs {
2155 presentation_type type;
2163 constexpr format_specs()
2166 type(presentation_type::none),
2176enum class arg_id_kind { none, index, name };
2179template <
typename Char>
struct arg_ref {
2180 FMT_CONSTEXPR arg_ref() : kind(arg_id_kind::none), val() {}
2182 FMT_CONSTEXPR
explicit arg_ref(
int index)
2183 : kind(arg_id_kind::index), val(index) {}
2185 : kind(arg_id_kind::name), val(name) {}
2187 FMT_CONSTEXPR
auto operator=(
int idx) -> arg_ref& {
2188 kind = arg_id_kind::index;
2195 FMT_CONSTEXPR value(
int idx = 0) : index(idx) {}
2212template <
typename Char, FMT_ENABLE_IF(std::is_
integral<Char>::value)>
2213constexpr auto to_ascii(Char c) ->
char {
2214 return c <= 0xff ? static_cast<char>(c) :
'\0';
2218template <
typename Char>
2219FMT_CONSTEXPR
auto code_point_length(
const Char* begin) ->
int {
2220 if (const_check(
sizeof(Char) != 1))
return 1;
2221 auto c =
static_cast<unsigned char>(*begin);
2222 return static_cast<int>((0x3a55000000000000ull >> (2 * (c >> 3))) & 0x3) + 1;
2226template <
bool IS_CONSTEXPR,
typename T,
typename Ptr = const T*>
2227FMT_CONSTEXPR
auto find(Ptr first, Ptr last, T
value, Ptr& out) ->
bool {
2228 for (out = first; out != last; ++out) {
2229 if (*out ==
value)
return true;
2235inline auto find<false, char>(
const char* first,
const char* last,
char value,
2236 const char*& out) ->
bool {
2238 static_cast<const char*
>(memchr(first,
value, to_unsigned(last - first)));
2239 return out !=
nullptr;
2244template <
typename Char>
2245FMT_CONSTEXPR
auto parse_nonnegative_int(
const Char*& begin,
const Char* end,
2246 int error_value)
noexcept ->
int {
2247 FMT_ASSERT(begin != end &&
'0' <= *begin && *begin <=
'9',
"");
2248 unsigned value = 0, prev = 0;
2254 }
while (p != end &&
'0' <= *p && *p <=
'9');
2255 auto num_digits = p - begin;
2257 int digits10 =
static_cast<int>(
sizeof(int) * CHAR_BIT * 3 / 10);
2258 if (num_digits <= digits10)
return static_cast<int>(
value);
2260 unsigned max = INT_MAX;
2261 return num_digits == digits10 + 1 &&
2262 prev * 10ull + unsigned(p[-1] -
'0') <= max
2263 ?
static_cast<int>(
value)
2267FMT_CONSTEXPR
inline auto parse_align(
char c) -> align_t {
2272 return align::right;
2274 return align::center;
2279template <
typename Char>
constexpr auto is_name_start(Char c) ->
bool {
2280 return (
'a' <= c && c <=
'z') || (
'A' <= c && c <=
'Z') || c ==
'_';
2283template <
typename Char,
typename Handler>
2284FMT_CONSTEXPR
auto do_parse_arg_id(
const Char* begin,
const Char* end,
2285 Handler&& handler) ->
const Char* {
2287 if (c >=
'0' && c <=
'9') {
2290 index = parse_nonnegative_int(begin, end, INT_MAX);
2293 if (begin == end || (*begin !=
'}' && *begin !=
':'))
2294 report_error(
"invalid format string");
2296 handler.on_index(index);
2299 if (!is_name_start(c)) {
2300 report_error(
"invalid format string");
2306 }
while (it != end && (is_name_start(*it) || (
'0' <= *it && *it <=
'9')));
2307 handler.on_name({begin, to_unsigned(it - begin)});
2311template <
typename Char,
typename Handler>
2312FMT_CONSTEXPR
auto parse_arg_id(
const Char* begin,
const Char* end,
2313 Handler&& handler) ->
const Char* {
2314 FMT_ASSERT(begin != end,
"");
2316 if (c !=
'}' && c !=
':')
return do_parse_arg_id(begin, end, handler);
2325 FMT_CONSTEXPR
void on_auto() {
2326 int id = ctx.next_arg_id();
2328 ctx.check_dynamic_spec(
id);
2330 FMT_CONSTEXPR
void on_index(
int id) {
2332 ctx.check_arg_id(
id);
2333 ctx.check_dynamic_spec(
id);
2337 ctx.check_arg_id(
id);
2342template <
typename Char>
2343FMT_CONSTEXPR
auto parse_dynamic_spec(
const Char* begin,
const Char* end,
2347 FMT_ASSERT(begin != end,
"");
2348 if (
'0' <= *begin && *begin <=
'9') {
2349 int val = parse_nonnegative_int(begin, end, -1);
2353 report_error(
"number is too big");
2354 }
else if (*begin ==
'{') {
2356 auto handler = dynamic_spec_id_handler<Char>{ctx, ref};
2357 if (begin != end) begin = parse_arg_id(begin, end, handler);
2358 if (begin != end && *begin ==
'}')
return ++begin;
2359 report_error(
"invalid format string");
2364template <
typename Char>
2365FMT_CONSTEXPR
auto parse_precision(
const Char* begin,
const Char* end,
2367 basic_format_parse_context<Char>& ctx)
2370 if (begin == end || *begin ==
'}') {
2371 report_error(
"invalid precision");
2374 return parse_dynamic_spec(begin, end,
value, ref, ctx);
2377enum class state { start, align, sign, hash, zero, width, precision, locale };
2380template <
typename Char>
2381FMT_CONSTEXPR
auto parse_format_specs(
const Char* begin,
const Char* end,
2383 basic_format_parse_context<Char>& ctx,
2384 type arg_type) ->
const Char* {
2386 if (end - begin > 1) {
2387 auto next = to_ascii(begin[1]);
2388 c = parse_align(next) == align::none ? to_ascii(*begin) :
'\0';
2390 if (begin == end)
return begin;
2391 c = to_ascii(*begin);
2395 state current_state = state::start;
2396 FMT_CONSTEXPR
void operator()(state s,
bool valid =
true) {
2397 if (current_state >= s || !valid)
2398 report_error(
"invalid format specifier");
2403 using pres = presentation_type;
2404 constexpr auto integral_set = sint_set | uint_set | bool_set | char_set;
2410 FMT_CONSTEXPR
auto operator()(pres pres_type,
int set) ->
const Char* {
2411 if (!in(arg_type, set)) {
2412 if (arg_type == type::none_type)
return begin;
2413 report_error(
"invalid format specifier");
2415 specs.type = pres_type;
2418 } parse_presentation_type{begin, specs, arg_type};
2425 enter_state(state::align);
2426 specs.align = parse_align(c);
2432 if (arg_type == type::none_type)
return begin;
2433 enter_state(state::sign, in(arg_type, sint_set | float_set));
2436 specs.sign = sign::plus;
2439 specs.sign = sign::minus;
2442 specs.sign = sign::space;
2448 if (arg_type == type::none_type)
return begin;
2449 enter_state(state::hash, is_arithmetic_type(arg_type));
2454 enter_state(state::zero);
2455 if (!is_arithmetic_type(arg_type)) {
2456 if (arg_type == type::none_type)
return begin;
2457 report_error(
"format specifier requires numeric argument");
2459 if (specs.align == align::none) {
2461 specs.align = align::numeric;
2476 enter_state(state::width);
2477 begin = parse_dynamic_spec(begin, end, specs.width, specs.width_ref, ctx);
2480 if (arg_type == type::none_type)
return begin;
2481 enter_state(state::precision,
2482 in(arg_type, float_set | string_set | cstring_set));
2483 begin = parse_precision(begin, end, specs.precision, specs.precision_ref,
2487 if (arg_type == type::none_type)
return begin;
2488 enter_state(state::locale, is_arithmetic_type(arg_type));
2489 specs.localized =
true;
2493 return parse_presentation_type(pres::dec, integral_set);
2498 return parse_presentation_type(pres::hex, integral_set);
2500 return parse_presentation_type(pres::oct, integral_set);
2505 return parse_presentation_type(pres::bin, integral_set);
2510 return parse_presentation_type(pres::exp, float_set);
2515 return parse_presentation_type(pres::fixed, float_set);
2520 return parse_presentation_type(pres::general, float_set);
2525 return parse_presentation_type(pres::hexfloat, float_set);
2527 if (arg_type == type::bool_type) report_error(
"invalid format specifier");
2528 return parse_presentation_type(pres::chr, integral_set);
2530 return parse_presentation_type(pres::string,
2531 bool_set | string_set | cstring_set);
2533 return parse_presentation_type(pres::pointer, pointer_set | cstring_set);
2535 return parse_presentation_type(pres::debug,
2536 char_set | string_set | cstring_set);
2540 if (*begin ==
'}')
return begin;
2542 auto fill_end = begin + code_point_length(begin);
2543 if (end - fill_end <= 0) {
2544 report_error(
"invalid format specifier");
2547 if (*begin ==
'{') {
2548 report_error(
"invalid fill character '{'");
2551 auto align = parse_align(to_ascii(*fill_end));
2552 enter_state(state::align, align != align::none);
2554 basic_string_view<Char>(begin, to_unsigned(fill_end - begin));
2555 specs.align = align;
2556 begin = fill_end + 1;
2559 if (begin == end)
return begin;
2560 c = to_ascii(*begin);
2564template <
typename Char,
typename Handler>
2565FMT_CONSTEXPR
auto parse_replacement_field(
const Char* begin,
const Char* end,
2566 Handler&& handler) ->
const Char* {
2571 FMT_CONSTEXPR
void on_auto() { arg_id = handler.on_arg_id(); }
2572 FMT_CONSTEXPR
void on_index(
int id) { arg_id = handler.on_arg_id(
id); }
2573 FMT_CONSTEXPR
void on_name(basic_string_view<Char>
id) {
2574 arg_id = handler.on_arg_id(
id);
2579 if (begin == end)
return handler.on_error(
"invalid format string"), end;
2580 if (*begin ==
'}') {
2581 handler.on_replacement_field(handler.on_arg_id(), begin);
2582 }
else if (*begin ==
'{') {
2583 handler.on_text(begin, begin + 1);
2585 auto adapter = id_adapter{handler, 0};
2586 begin = parse_arg_id(begin, end, adapter);
2587 Char c = begin != end ? *begin : Char();
2589 handler.on_replacement_field(adapter.arg_id, begin);
2590 }
else if (c ==
':') {
2591 begin = handler.on_format_specs(adapter.arg_id, begin + 1, end);
2592 if (begin == end || *begin !=
'}')
2593 return handler.on_error(
"unknown format specifier"), end;
2595 return handler.on_error(
"missing '}' in format string"), end;
2601template <
bool IS_CONSTEXPR,
typename Char,
typename Handler>
2602FMT_CONSTEXPR
void parse_format_string(basic_string_view<Char> format_str,
2603 Handler&& handler) {
2604 auto begin = format_str.
data();
2605 auto end = begin + format_str.
size();
2606 if (end - begin < 32) {
2608 const Char* p = begin;
2612 handler.on_text(begin, p - 1);
2613 begin = p = parse_replacement_field(p - 1, end, handler);
2614 }
else if (c ==
'}') {
2615 if (p == end || *p !=
'}')
2616 return handler.on_error(
"unmatched '}' in format string");
2617 handler.on_text(begin, p);
2621 handler.on_text(begin, end);
2625 FMT_CONSTEXPR
void operator()(
const Char* from,
const Char* to) {
2626 if (from == to)
return;
2628 const Char* p =
nullptr;
2629 if (!find<IS_CONSTEXPR>(from, to, Char(
'}'), p))
2630 return handler_.on_text(from, to);
2632 if (p == to || *p !=
'}')
2633 return handler_.on_error(
"unmatched '}' in format string");
2634 handler_.on_text(from, p);
2639 } write = {handler};
2640 while (begin != end) {
2643 const Char* p = begin;
2644 if (*begin !=
'{' && !find<IS_CONSTEXPR>(begin + 1, end, Char(
'{'), p))
2645 return write(begin, end);
2647 begin = parse_replacement_field(p, end, handler);
2655 using type = remove_cvref_t<
decltype(T::value)>;
2658template <
typename T,
typename ParseContext>
2659FMT_VISIBILITY(
"hidden")
2660FMT_CONSTEXPR auto parse_format_specs(ParseContext& ctx)
2661 -> decltype(ctx.begin()) {
2662 using char_type =
typename ParseContext::char_type;
2663 using context = buffered_context<char_type>;
2664 using mapped_type = conditional_t<
2665 mapped_type_constant<T, context>::value != type::custom_type,
2667 typename strip_named_arg<T>::type>;
2668#if defined(__cpp_if_constexpr)
2669 if constexpr (std::is_default_constructible<
2673 type_is_unformattable_for<T, char_type> _;
2677 return formatter<mapped_type, char_type>().parse(ctx);
2682FMT_CONSTEXPR
inline auto check_char_specs(
const format_specs& specs) ->
bool {
2683 if (specs.type != presentation_type::none &&
2684 specs.type != presentation_type::chr &&
2685 specs.type != presentation_type::debug) {
2688 if (specs.align == align::numeric || specs.sign != sign::none || specs.alt)
2689 report_error(
"invalid format specifier for char");
2693#if FMT_USE_NONTYPE_TEMPLATE_ARGS
2694template <
int N,
typename T,
typename... Args,
typename Char>
2695constexpr auto get_arg_index_by_name(basic_string_view<Char> name) ->
int {
2697 if (name == T::name)
return N;
2699 if constexpr (
sizeof...(Args) > 0)
2700 return get_arg_index_by_name<N + 1, Args...>(name);
2706template <
typename... Args,
typename Char>
2707FMT_CONSTEXPR
auto get_arg_index_by_name(basic_string_view<Char> name) ->
int {
2708#if FMT_USE_NONTYPE_TEMPLATE_ARGS
2709 if constexpr (
sizeof...(Args) > 0)
2710 return get_arg_index_by_name<0, Args...>(name);
2716template <
typename Char,
typename... Args>
class format_string_checker {
2719 static constexpr int num_args =
sizeof...(Args);
2725 using parse_func =
const Char* (*)(parse_context_type&);
2727 type types_[num_args > 0 ?
static_cast<size_t>(num_args) : 1];
2728 parse_context_type context_;
2729 parse_func parse_funcs_[num_args > 0 ?
static_cast<size_t>(num_args) : 1];
2733 : types_{mapped_type_constant<Args, buffered_context<Char>>
::value...},
2734 context_(fmt, num_args, types_),
2735 parse_funcs_{&parse_format_specs<Args, parse_context_type>...} {}
2737 FMT_CONSTEXPR
void on_text(
const Char*,
const Char*) {}
2739 FMT_CONSTEXPR
auto on_arg_id() ->
int {
return context_.next_arg_id(); }
2740 FMT_CONSTEXPR
auto on_arg_id(
int id) ->
int {
2741 return context_.check_arg_id(
id), id;
2744#if FMT_USE_NONTYPE_TEMPLATE_ARGS
2745 auto index = get_arg_index_by_name<Args...>(id);
2746 if (index < 0) on_error(
"named argument is not found");
2750 on_error(
"compile-time checks for named arguments require C++20 support");
2755 FMT_CONSTEXPR
void on_replacement_field(
int id,
const Char* begin) {
2756 on_format_specs(
id, begin, begin);
2759 FMT_CONSTEXPR
auto on_format_specs(
int id,
const Char* begin,
const Char*)
2761 context_.advance_to(begin);
2763 return id >= 0 &&
id < num_args ? parse_funcs_[id](context_) : begin;
2766 FMT_NORETURN FMT_CONSTEXPR
void on_error(
const char* message) {
2767 report_error(message);
2774template <
typename S>
2775using is_compile_string = std::is_base_of<compile_string, S>;
2778template <
typename...,
typename S, FMT_ENABLE_IF(!is_compile_string<S>::value)>
2779FMT_ALWAYS_INLINE
void check_format_string(
const S&) {
2780#ifdef FMT_ENFORCE_COMPILE_STRING
2781 static_assert(is_compile_string<S>::value,
2782 "FMT_ENFORCE_COMPILE_STRING requires all format strings to use "
2786template <
typename... Args,
typename S,
2787 FMT_ENABLE_IF(is_compile_string<S>::value)>
2788void check_format_string(S format_str) {
2789 using char_t =
typename S::char_type;
2791 using checker = format_string_checker<char_t, remove_cvref_t<Args>...>;
2792 FMT_CONSTEXPR
bool error = (parse_format_string<true>(s, checker(s)),
true);
2793 ignore_unused(error);
2797inline void report_truncation(
bool truncated) {
2798 if (truncated) report_error(
"output is truncated");
2807 using type = format_args;
2810template <
typename Char>
2812 typename vformat_args<Char>::type args,
locale_ref loc = {});
2814FMT_API
void vprint_mojibake(FILE*, string_view, format_args,
bool =
false);
2816inline void vprint_mojibake(FILE*, string_view, format_args,
bool) {}
2824 using nonlocking = void;
2826 template <
typename ParseContext>
2827 FMT_CONSTEXPR
auto parse(ParseContext& ctx) ->
const Char* {
2828 if (ctx.begin() == ctx.end() || *ctx.begin() ==
'}')
return ctx.begin();
2829 auto end = parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, TYPE);
2830 if (const_check(TYPE == type::char_type)) check_char_specs(specs_);
2834 template <type U = TYPE,
2835 FMT_ENABLE_IF(U == type::string_type || U == type::cstring_type ||
2836 U == type::char_type)>
2837 FMT_CONSTEXPR
void set_debug_format(
bool set =
true) {
2838 specs_.type = set ? presentation_type::debug : presentation_type::none;
2841 template <
typename FormatContext>
2842 FMT_CONSTEXPR
auto format(
const T& val, FormatContext& ctx)
const
2843 ->
decltype(ctx.out());
2850template <
typename T,
typename Char>
2851struct formatter<T, Char,
2852 enable_if_t<detail::type_constant<T, Char>::value !=
2853 detail::type::custom_type>>
2862template <
typename Char,
typename... Args>
class basic_format_string {
2871 (detail::is_compile_string<S>::value &&
2873 FMT_CONSTEVAL FMT_ALWAYS_INLINE basic_format_string(
const S& s) : str_(s) {
2876 (std::is_base_of<detail::view, remove_reference_t<Args>>::value &&
2877 std::is_reference<Args>::value)...>() == 0,
2878 "passing views as lvalues is disallowed");
2879#if FMT_USE_CONSTEVAL
2880 if constexpr (detail::count_named_args<Args...>() ==
2881 detail::count_statically_named_args<Args...>()) {
2884 detail::parse_format_string<true>(str_, checker(s));
2887 detail::check_format_string<Args...>(s);
2896#if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
2898template <
typename...>
using format_string = string_view;
2899inline auto runtime(string_view s) -> string_view {
return s; }
2901template <
typename... Args>
2915template <
typename OutputIt,
2918auto vformat_to(OutputIt&& out, string_view fmt, format_args args)
2919 -> remove_cvref_t<OutputIt> {
2920 auto&& buf = detail::get_buffer<char>(out);
2921 detail::vformat_to(buf, fmt, args, {});
2922 return detail::get_iterator(buf, out);
2935template <
typename OutputIt,
typename... T,
2938FMT_INLINE
auto format_to(OutputIt&& out, format_string<T...> fmt, T&&... args)
2939 -> remove_cvref_t<OutputIt> {
2940 return vformat_to(FMT_FWD(out), fmt, fmt::make_format_args(args...));
2950template <
typename OutputIt,
typename... T,
2952auto vformat_to_n(OutputIt out,
size_t n, string_view fmt, format_args args)
2956 detail::vformat_to(buf, fmt, args, {});
2957 return {buf.out(), buf.count()};
2966template <
typename OutputIt,
typename... T,
2968FMT_INLINE
auto format_to_n(OutputIt out,
size_t n, format_string<T...> fmt,
2970 return vformat_to_n(out, n, fmt, fmt::make_format_args(args...));
2973template <
typename OutputIt,
typename Sentinel = OutputIt>
2980 FMT_CONSTEXPR
operator OutputIt&() & {
2984 FMT_CONSTEXPR
operator const OutputIt&()
const& {
2988 FMT_CONSTEXPR
operator OutputIt&&() && {
2990 return static_cast<OutputIt&&
>(
out);
2995auto vformat_to(
char (&out)[N], string_view fmt, format_args args)
2997 auto result = vformat_to_n(out, N, fmt, args);
2998 return {result.out, result.size > N};
3001template <
size_t N,
typename... T>
3002FMT_INLINE
auto format_to(
char (&out)[N], format_string<T...> fmt, T&&... args)
3004 auto result = fmt::format_to_n(out, N, fmt,
static_cast<T&&
>(args)...);
3005 return {result.out, result.size > N};
3009template <
typename... T>
3010FMT_NODISCARD FMT_INLINE
auto formatted_size(format_string<T...> fmt,
3011 T&&... args) ->
size_t {
3013 detail::vformat_to<char>(buf, fmt, fmt::make_format_args(args...), {});
3017FMT_API
void vprint(string_view fmt, format_args args);
3018FMT_API
void vprint(FILE* f, string_view fmt, format_args args);
3019FMT_API
void vprint_buffered(FILE* f, string_view fmt, format_args args);
3020FMT_API
void vprintln(FILE* f, string_view fmt, format_args args);
3030template <
typename... T>
3031FMT_INLINE
void print(format_string<T...> fmt, T&&... args) {
3032 const auto& vargs = fmt::make_format_args(args...);
3033 if (!detail::use_utf8())
return detail::vprint_mojibake(stdout, fmt, vargs);
3034 return detail::is_locking<T...>() ? vprint_buffered(stdout, fmt, vargs)
3035 : vprint(fmt, vargs);
3046template <
typename... T>
3047FMT_INLINE
void print(FILE* f, format_string<T...> fmt, T&&... args) {
3048 const auto& vargs = fmt::make_format_args(args...);
3049 if (!detail::use_utf8())
return detail::vprint_mojibake(f, fmt, vargs);
3050 return detail::is_locking<T...>() ? vprint_buffered(f, fmt, vargs)
3051 : vprint(f, fmt, vargs);
3056template <
typename... T>
3057FMT_INLINE
void println(FILE* f, format_string<T...> fmt, T&&... args) {
3058 const auto& vargs = fmt::make_format_args(args...);
3059 return detail::use_utf8() ? vprintln(f, fmt, vargs)
3060 : detail::vprint_mojibake(f, fmt, vargs, true);
3065template <
typename... T>
3066FMT_INLINE
void println(format_string<T...> fmt, T&&... args) {
3067 return fmt::println(stdout, fmt,
static_cast<T&&
>(args)...);
3071FMT_GCC_PRAGMA(
"GCC pop_options")
3074#ifdef FMT_HEADER_ONLY
FMT_CONSTEXPR auto next_arg_id() -> int
Definition base.h:784
constexpr auto end() const noexcept -> iterator
Returns an iterator past the end of the format string range being parsed.
Definition base.h:775
FMT_CONSTEXPR void check_arg_id(int id)
Definition base.h:796
FMT_CONSTEXPR void advance_to(iterator it)
Advances the begin iterator to it.
Definition base.h:778
constexpr auto begin() const noexcept -> iterator
Definition base.h:770
constexpr auto size() const noexcept -> size_t
Returns the string size.
Definition base.h:555
FMT_CONSTEXPR basic_string_view(const S &s) noexcept
Definition base.h:548
constexpr auto data() const noexcept -> const Char *
Returns a pointer to the string data.
Definition base.h:552
constexpr basic_string_view(const Char *s, size_t count) noexcept
Constructs a string reference object from a C string and a size.
Definition base.h:529
FMT_CONSTEXPR20 basic_string_view(const Char *s)
Constructs a string reference object from a C string.
Definition base.h:536
char char_type
The character type for the output.
Definition base.h:1950
FMT_CONSTEXPR context(iterator out, basic_format_args< context > ctx_args, detail::locale_ref loc={})
Definition base.h:1959
FMT_CONSTEXPR void set(T *buf_data, size_t buf_capacity) noexcept
Sets the buffer data and capacity.
Definition base.h:875
void clear()
Clears this buffer.
Definition base.h:904
constexpr auto size() const noexcept -> size_t
Returns the size of this buffer.
Definition base.h:894
void append(const U *begin, const U *end)
Appends data to the end of the buffer.
Definition base.h:927
constexpr auto capacity() const noexcept -> size_t
Returns the capacity of this buffer.
Definition base.h:897
FMT_CONSTEXPR auto data() noexcept -> T *
Returns a pointer to the buffer data (not null-terminated).
Definition base.h:900
Specifies if T is a character type. Can be specialized by users.
Definition base.h:615