17 template <
typename Char,
typename InputIt>
20 return it + (end - begin);
23 template <
typename OutputIt>
43 using value_type =
typename std::iterator_traits<OutputIt>::value_type;
61 template <
typename OutputIt,
62 typename Enable =
typename std::is_void<
63 typename std::iterator_traits<OutputIt>::value_type>
::type>
66 template <
typename OutputIt>
84 if (this->count_++ < this->limit_)
98 return this->count_ < this->limit_ ? *this->out_ : blackhole_;
102 template <
typename OutputIt>
114 template <
typename T>
117 if (this->count_++ < this->limit_)
141 template <
typename S>
159#if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction)
160#define FMT_COMPILE(s) \
161 FMT_STRING_IMPL(s, fmt::detail::compiled_string, explicit)
163#define FMT_COMPILE(s) FMT_STRING(s)
166#if FMT_USE_NONTYPE_TEMPLATE_ARGS
167 template <
typename Char,
size_t N, fmt::detail_exported::fixed_
string<Char, N> Str>
168 struct udl_compiled_string : compiled_string
173 return {Str.
data, N - 1};
178 template <
typename T,
typename... Tail>
184#if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction)
185 template <
typename... Args>
191 template <
int N,
typename T,
typename... Args>
192 constexpr const auto&
get([[maybe_unused]]
const T&
first,
193 [[maybe_unused]]
const Args&... rest)
195 static_assert(N < 1 +
sizeof...(Args),
"index is out of bounds");
196 if constexpr (N == 0)
199 return detail::get<N - 1>(rest...);
202 template <
typename Char,
typename... Args>
209 template <
int N,
typename>
210 struct get_type_impl;
212 template <
int N,
typename... Args>
213 struct get_type_impl<N, type_list<Args...>>
219 template <
int N,
typename T>
220 using get_type =
typename get_type_impl<N, T>::type;
222 template <
typename T>
223 struct is_compiled_format : std::false_type
227 template <
typename Char>
233 template <
typename OutputIt,
typename... Args>
234 constexpr OutputIt
format(OutputIt
out,
const Args&...)
const
240 template <
typename Char>
241 struct is_compiled_format<text<Char>> : std::true_type
245 template <
typename Char>
248 return {{&
s[pos], size}};
251 template <
typename Char>
257 template <
typename OutputIt,
typename... Args>
258 constexpr OutputIt
format(OutputIt
out,
const Args&...)
const
265 template <
typename T,
int N,
typename... Args>
266 constexpr const T& get_arg_checked(
const Args&... args)
268 const auto&
arg = detail::get<N>(args...);
279 template <
typename Char>
280 struct is_compiled_format<code_unit<Char>> : std::true_type
285 template <
typename Char,
typename T,
int N>
290 template <
typename OutputIt,
typename... Args>
291 constexpr OutputIt
format(OutputIt
out,
const Args&... args)
const
293 return write<Char>(
out, get_arg_checked<T, N>(args...));
297 template <
typename Char,
typename T,
int N>
298 struct is_compiled_format<field<Char, T, N>> : std::true_type
303 template <
typename Char>
304 struct runtime_named_field
309 template <
typename OutputIt,
typename T>
310 constexpr static bool try_format_argument(
318 if (arg_name ==
arg.name)
327 template <
typename OutputIt,
typename... Args>
328 constexpr OutputIt
format(OutputIt
out,
const Args&... args)
const
330 bool found = (try_format_argument(
out,
name, args) || ...);
339 template <
typename Char>
340 struct is_compiled_format<runtime_named_field<Char>> : std::true_type
345 template <
typename Char,
typename T,
int N>
351 template <
typename OutputIt,
typename... Args>
353 const Args&... args)
const
356 fmt::make_format_args<basic_format_context<OutputIt, Char>>(args...);
358 return fmt.format(get_arg_checked<T, N>(args...), ctx);
362 template <
typename Char,
typename T,
int N>
363 struct is_compiled_format<spec_field<Char, T, N>> : std::true_type
367 template <
typename L,
typename R>
374 template <
typename OutputIt,
typename... Args>
375 constexpr OutputIt
format(OutputIt
out,
const Args&... args)
const
377 out = lhs.format(
out, args...);
378 return rhs.format(
out, args...);
382 template <
typename L,
typename R>
383 struct is_compiled_format<concat<L, R>> : std::true_type
387 template <
typename L,
typename R>
388 constexpr concat<L, R> make_concat(L lhs, R rhs)
393 struct unknown_format
397 template <
typename Char>
400 for (
size_t size = str.
size(); pos != size; ++pos)
402 if (str[pos] ==
'{' || str[pos] ==
'}')
408 template <
typename Args,
size_t POS,
int ID,
typename S>
409 constexpr auto compile_format_string(S format_str);
411 template <
typename Args,
size_t POS,
int ID,
typename T,
typename S>
412 constexpr auto parse_tail(T
head, S format_str)
417 constexpr auto tail = compile_format_string<Args, POS, ID>(format_str);
422 return make_concat(
head, tail);
430 template <
typename T,
typename Char>
431 struct parse_specs_result
438 constexpr int manual_indexing_id = -1;
440 template <
typename T,
typename Char>
449 auto end = f.parse(ctx);
450 return {f, pos + fmt::detail::to_unsigned(end - str.
data()),
451 next_arg_id == 0 ? manual_indexing_id : ctx.
next_arg_id()};
454 template <
typename Char>
455 struct arg_id_handler
459 constexpr int operator()()
461 FMT_ASSERT(
false,
"handler cannot be used with automatic indexing");
464 constexpr int operator()(
int id)
475 constexpr void on_error(
const char* message)
481 template <
typename Char>
482 struct parse_arg_id_result
485 const Char* arg_id_end;
488 template <
int ID,
typename Char>
489 constexpr auto parse_arg_id(
const Char* begin,
const Char* end)
493 return parse_arg_id_result<Char>{handler.arg_id, arg_id_end};
496 template <
typename T,
typename Enable =
void>
502 template <
typename T>
508 template <
typename T,
typename Args,
size_t END_POS,
int ARG_INDEX,
int NEXT_ID,
typename S>
509 constexpr auto parse_replacement_field_then_tail(S format_str)
514 if constexpr (c ==
'}')
516 return parse_tail<Args, END_POS + 1, NEXT_ID>(
517 field<
char_type,
typename field_type<T>::type, ARG_INDEX>(),
520 else if constexpr (c !=
':')
526 constexpr auto result = parse_specs<typename field_type<T>::type>(
527 str, END_POS + 1, NEXT_ID == manual_indexing_id ? 0 : NEXT_ID);
528 if constexpr (
result.end >= str.size() || str[
result.end] !=
'}')
535 return parse_tail<Args,
result.end + 1,
result.next_arg_id>(
536 spec_field<char_type, typename field_type<T>::type, ARG_INDEX>{
545 template <
typename Args,
size_t POS,
int ID,
typename S>
546 constexpr auto compile_format_string(S format_str)
550 if constexpr (str[POS] ==
'{')
552 if constexpr (POS + 1 == str.size())
554 if constexpr (str[POS + 1] ==
'{')
556 return parse_tail<Args, POS + 2, ID>(make_text(str, POS, 1), format_str);
558 else if constexpr (str[POS + 1] ==
'}' || str[POS + 1] ==
':')
560 static_assert(ID != manual_indexing_id,
561 "cannot switch from manual to automatic argument indexing");
562 constexpr auto next_id =
563 ID != manual_indexing_id ? ID + 1 : manual_indexing_id;
564 return parse_replacement_field_then_tail<get_type<ID, Args>, Args,
565 POS + 1, ID, next_id>(
570 constexpr auto arg_id_result =
571 parse_arg_id<ID>(str.data() + POS + 1, str.data() + str.size());
572 constexpr auto arg_id_end_pos = arg_id_result.arg_id_end - str.data();
574 arg_id_end_pos != str.size() ? str[arg_id_end_pos] :
char_type();
575 static_assert(c ==
'}' || c ==
':',
"missing '}' in format string");
579 ID == manual_indexing_id || ID == 0,
580 "cannot switch from automatic to manual argument indexing");
581 constexpr auto arg_index = arg_id_result.arg_id.val.index;
582 return parse_replacement_field_then_tail<get_type<arg_index, Args>,
583 Args, arg_id_end_pos,
584 arg_index, manual_indexing_id>(
589 constexpr auto arg_index =
593 constexpr auto next_id =
594 ID != manual_indexing_id ? ID + 1 : manual_indexing_id;
595 return parse_replacement_field_then_tail<
596 decltype(get_type<arg_index, Args>::value), Args, arg_id_end_pos,
597 arg_index, next_id>(format_str);
601 if constexpr (c ==
'}')
603 return parse_tail<Args, arg_id_end_pos + 1, ID>(
604 runtime_named_field<char_type>{arg_id_result.arg_id.val.name},
607 else if constexpr (c ==
':')
609 return unknown_format();
615 else if constexpr (str[POS] ==
'}')
617 if constexpr (POS + 1 == str.size())
619 return parse_tail<Args, POS + 2, ID>(make_text(str, POS, 1), format_str);
623 constexpr auto end = parse_text(str, POS + 1);
624 if constexpr (
end - POS > 1)
626 return parse_tail<Args, end, ID>(make_text(str, POS, end - POS),
631 return parse_tail<Args, end, ID>(code_unit<char_type>{str[POS]},
638 constexpr auto compile(S format_str)
641 if constexpr (str.size() == 0)
643 return detail::make_text(str, 0, 0);
648 detail::compile_format_string<detail::type_list<Args...>, 0, 0>(
658#if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction)
660template <
typename CompiledFormat,
typename... Args,
typename Char =
typename CompiledFormat::char_type,
FMT_ENABLE_IF(detail::is_compiled_format<CompiledFormat>::value)>
664 auto s = std::basic_string<Char>();
665 cf.format(std::back_inserter(
s), args...);
669template <
typename OutputIt,
typename CompiledFormat,
typename... Args,
FMT_ENABLE_IF(detail::is_compiled_format<CompiledFormat>::value)>
672 return cf.format(
out, args...);
679 if constexpr (std::is_same<typename S::char_type, char>::value)
682 if constexpr (str.size() == 2 && str[0] ==
'{' && str[1] ==
'}')
685 if constexpr (detail::is_named_arg<
688 return fmt::to_string(
first.value);
692 return fmt::to_string(first);
696 constexpr auto compiled = detail::compile<Args...>(S());
698 detail::unknown_format>())
702 std::forward<Args>(args)...);
706 return fmt::format(compiled, std::forward<Args>(args)...);
713 constexpr auto compiled = detail::compile<Args...>(S());
715 detail::unknown_format>())
717 return fmt::format_to(
719 std::forward<Args>(args)...);
723 return fmt::format_to(
out, compiled, std::forward<Args>(args)...);
732 format_str, std::forward<Args>(args)...);
733 return {it.base(), it.count()};
740 return fmt::format_to(detail::counting_iterator(), format_str, args...)
745void print(std::FILE* f,
const S& format_str,
const Args&... args)
748 fmt::format_to(std::back_inserter(
buffer), format_str, args...);
753void print(
const S& format_str,
const Args&... args)
755 print(stdout, format_str, args...);
758#if FMT_USE_NONTYPE_TEMPLATE_ARGS
761 template <detail_exported::fixed_
string Str>
762 constexpr auto operator""_cf()
765 return detail::udl_compiled_string<
char_t,
sizeof(Str.data) /
sizeof(
char_t),
void print(std::FILE *f, const S &format_str, const Args &... args)
Definition compile.h:745
FMT_MODULE_EXPORT_BEGIN format_to_n_result< OutputIt > format_to_n(OutputIt out, size_t n, const S &format_str, Args &&... args)
Definition compile.h:729
FMT_CONSTEXPR20 size_t formatted_size(const S &format_str, const Args &... args)
Definition compile.h:737
constexpr auto size() const noexcept -> size_t
Definition core.h:541
constexpr auto data() const noexcept -> const Char *
Definition core.h:535
FMT_CONSTEXPR void remove_prefix(size_t n) noexcept
Definition core.h:560
FMT_CONSTEXPR auto data() noexcept -> T *
Definition core.h:1102
constexpr auto size() const noexcept -> size_t
Definition core.h:1090
FMT_CONSTEXPR auto next_arg_id() -> int
Definition core.h:885
truncating_iterator operator++(int)
Definition compile.h:89
truncating_iterator(OutputIt out, size_t limit)
Definition compile.h:77
truncating_iterator_base< OutputIt >::value_type blackhole_
Definition compile.h:70
typename truncating_iterator_base< OutputIt >::value_type value_type
Definition compile.h:73
truncating_iterator & operator++()
Definition compile.h:82
value_type & operator*() const
Definition compile.h:96
truncating_iterator()=default
truncating_iterator & operator++(int)
Definition compile.h:126
truncating_iterator & operator=(T val)
Definition compile.h:115
truncating_iterator & operator*()
Definition compile.h:130
truncating_iterator()=default
truncating_iterator(OutputIt out, size_t limit)
Definition compile.h:109
truncating_iterator & operator++()
Definition compile.h:122
truncating_iterator_base()
Definition compile.h:31
FMT_UNCHECKED_ITERATOR(truncating_iterator_base)
size_t count_
Definition compile.h:29
size_t count() const
Definition compile.h:53
truncating_iterator_base(OutputIt out, size_t limit)
Definition compile.h:36
OutputIt base() const
Definition compile.h:49
size_t limit_
Definition compile.h:28
OutputIt out_
Definition compile.h:27
void pointer
Definition compile.h:45
std::ptrdiff_t difference_type
Definition compile.h:44
void reference
Definition compile.h:46
std::output_iterator_tag iterator_category
Definition compile.h:42
typename std::iterator_traits< OutputIt >::value_type value_type
Definition compile.h:43
auto format_to(OutputIt out, const text_style &ts, const S &format_str, Args &&... args) -> typename std::enable_if< enable, OutputIt >::type
Definition color.h:677
std::basic_string< Char > format(const text_style &ts, const S &format_str, const Args &... args)
Definition color.h:646
typename std::enable_if< B, T >::type enable_if_t
Definition core.h:302
#define FMT_ASSERT(condition, message)
Definition core.h:403
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Definition core.h:2506
typename detail::char_t_impl< S >::type char_t
Definition core.h:759
#define FMT_MODULE_EXPORT_BEGIN
Definition core.h:226
#define FMT_CONSTEXPR
Definition core.h:106
type
Definition core.h:681
#define FMT_BEGIN_NAMESPACE
Definition core.h:214
#define FMT_ENABLE_IF(...)
Definition core.h:364
#define FMT_INLINE
Definition core.h:199
FMT_CONSTEXPR FMT_INLINE auto parse_arg_id(const Char *begin, const Char *end, IDHandler &&handler) -> const Char *
Definition core.h:3165
#define FMT_CONSTEXPR20
Definition core.h:114
typename std::remove_cv< remove_reference_t< T > >::type remove_cvref_t
Definition core.h:312
constexpr int invalid_arg_index
Definition core.h:3748
#define FMT_END_NAMESPACE
Definition core.h:219
#define FMT_MODULE_EXPORT_END
Definition core.h:227
FMT_CONSTEXPR auto get_arg_index_by_name(basic_string_view< Char > name) -> int
Definition core.h:3767
#define out
Definition encodings.cpp:5
FMT_CONSTEXPR counting_iterator copy_str(InputIt begin, InputIt end, counting_iterator it)
Definition compile.h:18
FMT_FUNC void print(std::FILE *f, string_view text)
Definition format-inl.h:1620
const T & first(const T &value, const Tail &...)
Definition compile.h:179
result
Definition format.h:3059
Definition bin_to_hex.h:111
bool end(const css_token_vector &tokens, int index)
Definition gradient.cpp:78
SPDLOG_INLINE std::shared_ptr< logger > get(const std::string &name)
Definition spdlog-inl.h:21
s
Definition tag_strings.h:47
head
Definition tag_strings.h:5