16template <
typename Char,
typename InputIt>
35 using value_type =
typename std::iterator_traits<OutputIt>::value_type;
47template <
typename OutputIt,
48 typename Enable =
typename std::is_void<
49 typename std::iterator_traits<OutputIt>::value_type>
::type>
52template <
typename OutputIt>
66 if (this->count_++ < this->limit_) ++this->out_;
77 return this->count_ < this->limit_ ? *this->out_ : blackhole_;
81template <
typename OutputIt>
91 if (this->count_++ < this->limit_) *this->out_++ = val;
119#if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction)
120# define FMT_COMPILE(s) \
121 FMT_STRING_IMPL(s, fmt::detail::compiled_string, explicit)
123# define FMT_COMPILE(s) FMT_STRING(s)
126#if FMT_USE_NONTYPE_TEMPLATE_ARGS
127template <
typename Char,
size_t N,
128 fmt::detail_exported::fixed_string<Char, N> Str>
129struct udl_compiled_string : compiled_string {
132 return {Str.
data, N - 1};
137template <
typename T,
typename... Tail>
142#if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction)
143template <
typename... Args>
struct type_list {};
146template <
int N,
typename T,
typename... Args>
147constexpr const auto&
get([[maybe_unused]]
const T&
first,
148 [[maybe_unused]]
const Args&... rest) {
149 static_assert(N < 1 +
sizeof...(Args),
"index is out of bounds");
150 if constexpr (N == 0)
156template <
typename Char,
typename... Args>
158 type_list<Args...>) {
162template <
int N,
typename>
struct get_type_impl;
164template <
int N,
typename... Args>
struct get_type_impl<N, type_list<Args...>> {
169template <
int N,
typename T>
172template <
typename T>
struct is_compiled_format : std::false_type {};
174template <
typename Char>
struct text {
178 template <
typename OutputIt,
typename... Args>
179 constexpr OutputIt
format(OutputIt out,
const Args&...)
const {
180 return write<Char>(out,
data);
184template <
typename Char>
185struct is_compiled_format<text<Char>> : std::true_type {};
187template <
typename Char>
190 return {{&s[pos],
size}};
193template <
typename Char>
struct code_unit {
197 template <
typename OutputIt,
typename... Args>
198 constexpr OutputIt
format(OutputIt out,
const Args&...)
const {
199 return write<Char>(out,
value);
204template <
typename T,
int N,
typename... Args>
205constexpr const T& get_arg_checked(
const Args&... args) {
206 const auto&
arg = detail::get<N>(args...);
214template <
typename Char>
215struct is_compiled_format<code_unit<Char>> : std::true_type {};
218template <
typename Char,
typename T,
int N>
struct field {
221 template <
typename OutputIt,
typename... Args>
222 constexpr OutputIt
format(OutputIt out,
const Args&... args)
const {
223 return write<Char>(out, get_arg_checked<T, N>(args...));
227template <
typename Char,
typename T,
int N>
228struct is_compiled_format<field<Char, T, N>> : std::true_type {};
231template <
typename Char>
struct runtime_named_field {
235 template <
typename OutputIt,
typename T>
236 constexpr static bool try_format_argument(
241 if (arg_name ==
arg.name) {
242 out = write<Char>(out,
arg.value);
249 template <
typename OutputIt,
typename... Args>
250 constexpr OutputIt
format(OutputIt out,
const Args&... args)
const {
251 bool found = (try_format_argument(out, name, args) || ...);
259template <
typename Char>
260struct is_compiled_format<runtime_named_field<Char>> : std::true_type {};
263template <
typename Char,
typename T,
int N>
struct spec_field {
267 template <
typename OutputIt,
typename... Args>
269 const Args&... args)
const {
271 fmt::make_format_args<basic_format_context<OutputIt, Char>>(args...);
273 return fmt.format(get_arg_checked<T, N>(args...), ctx);
277template <
typename Char,
typename T,
int N>
278struct is_compiled_format<spec_field<Char, T, N>> : std::true_type {};
280template <
typename L,
typename R>
struct concat {
285 template <
typename OutputIt,
typename... Args>
286 constexpr OutputIt
format(OutputIt out,
const Args&... args)
const {
287 out = lhs.format(out, args...);
288 return rhs.format(out, args...);
292template <
typename L,
typename R>
293struct is_compiled_format<concat<
L,
R>> : std::true_type {};
295template <
typename L,
typename R>
296constexpr concat<L, R> make_concat(
L lhs,
R rhs) {
300struct unknown_format {};
302template <
typename Char>
305 if (str[pos] ==
'{' || str[pos] ==
'}')
break;
310template <
typename Args,
size_t POS,
int ID,
typename S>
311constexpr auto compile_format_string(
S format_str);
313template <
typename Args,
size_t POS,
int ID,
typename T,
typename S>
314constexpr auto parse_tail(T
head,
S format_str) {
317 constexpr auto tail = compile_format_string<Args, POS, ID>(format_str);
328template <
typename T,
typename Char>
struct parse_specs_result {
334constexpr int manual_indexing_id = -1;
336template <
typename T,
typename Char>
338 size_t pos,
int next_arg_id) {
343 auto end = f.parse(ctx);
345 next_arg_id == 0 ? manual_indexing_id : ctx.next_arg_id()};
348template <
typename Char>
struct arg_id_handler {
352 FMT_ASSERT(
false,
"handler cannot be used with automatic indexing");
364 constexpr void on_error(
const char* message) {
369template <
typename Char>
struct parse_arg_id_result {
371 const Char* arg_id_end;
374template <
int ID,
typename Char>
378 return parse_arg_id_result<Char>{handler.arg_id, arg_id_end};
381template <
typename T,
typename Enable =
void>
struct field_type {
390template <
typename T,
typename Args,
size_t END_POS,
int ARG_INDEX,
int NEXT_ID,
392constexpr auto parse_replacement_field_then_tail(
S format_str) {
396 if constexpr (
c ==
'}') {
397 return parse_tail<Args, END_POS + 1, NEXT_ID>(
400 }
else if constexpr (
c !=
':') {
404 str, END_POS + 1, NEXT_ID == manual_indexing_id ? 0 : NEXT_ID);
405 if constexpr (
result.end >= str.size() || str[
result.end] !=
'}') {
409 return parse_tail<Args,
result.end + 1,
result.next_arg_id>(
419template <
typename Args,
size_t POS,
int ID,
typename S>
420constexpr auto compile_format_string(
S format_str) {
423 if constexpr (str[POS] ==
'{') {
424 if constexpr (POS + 1 == str.size())
426 if constexpr (str[POS + 1] ==
'{') {
427 return parse_tail<Args, POS + 2, ID>(make_text(str, POS, 1), format_str);
428 }
else if constexpr (str[POS + 1] ==
'}' || str[POS + 1] ==
':') {
429 static_assert(ID != manual_indexing_id,
430 "cannot switch from manual to automatic argument indexing");
431 constexpr auto next_id =
432 ID != manual_indexing_id ? ID + 1 : manual_indexing_id;
433 return parse_replacement_field_then_tail<get_type<ID, Args>, Args,
434 POS + 1, ID, next_id>(
437 constexpr auto arg_id_result =
438 parse_arg_id<ID>(str.data() + POS + 1, str.data() + str.size());
439 constexpr auto arg_id_end_pos = arg_id_result.arg_id_end - str.data();
441 arg_id_end_pos != str.size() ? str[arg_id_end_pos] :
char_type();
442 static_assert(
c ==
'}' ||
c ==
':',
"missing '}' in format string");
445 ID == manual_indexing_id || ID == 0,
446 "cannot switch from automatic to manual argument indexing");
447 constexpr auto arg_index = arg_id_result.arg_id.val.index;
448 return parse_replacement_field_then_tail<get_type<arg_index, Args>,
449 Args, arg_id_end_pos,
450 arg_index, manual_indexing_id>(
453 constexpr auto arg_index =
456 constexpr auto next_id =
457 ID != manual_indexing_id ? ID + 1 : manual_indexing_id;
458 return parse_replacement_field_then_tail<
459 decltype(get_type<arg_index, Args>::value), Args, arg_id_end_pos,
460 arg_index, next_id>(format_str);
462 if constexpr (
c ==
'}') {
463 return parse_tail<Args, arg_id_end_pos + 1, ID>(
464 runtime_named_field<char_type>{arg_id_result.arg_id.val.name},
466 }
else if constexpr (
c ==
':') {
467 return unknown_format();
472 }
else if constexpr (str[POS] ==
'}') {
473 if constexpr (POS + 1 == str.size())
475 return parse_tail<Args, POS + 2, ID>(make_text(str, POS, 1), format_str);
477 constexpr auto end = parse_text(str, POS + 1);
478 if constexpr (
end - POS > 1) {
479 return parse_tail<Args, end, ID>(make_text(str, POS,
end - POS),
482 return parse_tail<Args, end, ID>(code_unit<char_type>{str[POS]},
488template <
typename... Args,
typename S,
490constexpr auto compile(
S format_str) {
492 if constexpr (str.size() == 0) {
493 return detail::make_text(str, 0, 0);
496 detail::compile_format_string<detail::type_list<Args...>, 0, 0>(
506#if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction)
508template <
typename CompiledFormat,
typename... Args,
509 typename Char =
typename CompiledFormat::char_type,
510 FMT_ENABLE_IF(detail::is_compiled_format<CompiledFormat>::value)>
512 const Args&... args) {
513 auto s = std::basic_string<Char>();
514 cf.format(std::back_inserter(s), args...);
518template <
typename OutputIt,
typename CompiledFormat,
typename... Args,
519 FMT_ENABLE_IF(detail::is_compiled_format<CompiledFormat>::value)>
521 const Args&... args) {
522 return cf.format(out, args...);
525template <
typename S,
typename... Args,
529 if constexpr (std::is_same<typename S::char_type, char>::value) {
531 if constexpr (str.size() == 2 && str[0] ==
'{' && str[1] ==
'}') {
533 if constexpr (detail::is_named_arg<
541 constexpr auto compiled = detail::compile<Args...>(
S());
543 detail::unknown_format>()) {
546 std::forward<Args>(args)...);
548 return fmt::format(compiled, std::forward<Args>(args)...);
552template <
typename OutputIt,
typename S,
typename... Args,
555 constexpr auto compiled = detail::compile<Args...>(
S());
557 detail::unknown_format>()) {
560 std::forward<Args>(args)...);
562 return fmt::format_to(out, compiled, std::forward<Args>(args)...);
567template <
typename OutputIt,
typename S,
typename... Args,
570 const S& format_str, Args&&... args) {
572 format_str, std::forward<Args>(args)...);
573 return {it.base(), it.count()};
576template <
typename S,
typename... Args,
579 const Args&... args) {
580 return fmt::format_to(detail::counting_iterator(), format_str, args...)
584template <
typename S,
typename... Args,
586void print(std::FILE* f,
const S& format_str,
const Args&... args) {
592template <
typename S,
typename... Args,
594void print(
const S& format_str,
const Args&... args) {
595 print(stdout, format_str, args...);
598#if FMT_USE_NONTYPE_TEMPLATE_ARGS
600template <detail_exported::fixed_
string Str>
constexpr auto operator""_cf() {
602 return detail::udl_compiled_string<
char_t,
sizeof(Str.data) /
sizeof(
char_t),
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
Definition: ArrayCwiseUnaryOps.h:66
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE FixedSegmentReturnType< internal::get_fixed_value< NType >::value >::Type tail(NType n)
Definition: BlockMethods.h:1257
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE FixedSegmentReturnType< internal::get_fixed_value< NType >::value >::Type head(NType n)
Definition: BlockMethods.h:1208
internal::enable_if< internal::valid_indexed_view_overload< RowIndices, ColIndices >::value &&internal::traits< typenameEIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::ReturnAsIndexedView, typenameEIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
Definition: IndexedViewMethods.h:73
\rst A dynamically growing memory buffer for trivially copyable/constructible types with the first SI...
Definition: format.h:819
An implementation of std::basic_string_view for pre-C++17.
Definition: core.h:430
constexpr auto size() const noexcept -> size_t
Returns the string size.
Definition: core.h:475
constexpr auto data() const noexcept -> const Char *
Returns a pointer to the string data.
Definition: core.h:472
FMT_CONSTEXPR void remove_prefix(size_t n) noexcept
Definition: core.h:484
\rst A contiguous memory buffer with an optional growing ability.
Definition: core.h:862
FMT_CONSTEXPR auto data() noexcept -> T *
Returns a pointer to the buffer data.
Definition: core.h:908
constexpr auto size() const noexcept -> size_t
Returns the size of this buffer.
Definition: core.h:902
Definition: format.h:2138
Definition: compile.h:101
truncating_iterator operator++(int)
Definition: compile.h:70
truncating_iterator(OutputIt out, size_t limit)
Definition: compile.h:62
typename truncating_iterator_base< OutputIt >::value_type value_type
Definition: compile.h:58
truncating_iterator & operator++()
Definition: compile.h:65
value_type & operator*() const
Definition: compile.h:76
truncating_iterator()=default
truncating_iterator & operator++(int)
Definition: compile.h:96
truncating_iterator & operator=(T val)
Definition: compile.h:90
truncating_iterator & operator*()
Definition: compile.h:97
truncating_iterator()=default
truncating_iterator(OutputIt out, size_t limit)
Definition: compile.h:87
truncating_iterator & operator++()
Definition: compile.h:95
truncating_iterator_base()
Definition: compile.h:28
FMT_UNCHECKED_ITERATOR(truncating_iterator_base)
size_t count_
Definition: compile.h:26
size_t count() const
Definition: compile.h:42
truncating_iterator_base(OutputIt out, size_t limit)
Definition: compile.h:30
OutputIt base() const
Definition: compile.h:41
size_t limit_
Definition: compile.h:25
OutputIt out_
Definition: compile.h:24
void pointer
Definition: compile.h:37
std::ptrdiff_t difference_type
Definition: compile.h:36
void reference
Definition: compile.h:38
std::output_iterator_tag iterator_category
Definition: compile.h:34
typename std::iterator_traits< OutputIt >::value_type value_type
Definition: compile.h:35
void print(std::FILE *f, const S &format_str, const Args &... args)
Definition: compile.h:586
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:569
FMT_CONSTEXPR20 size_t formatted_size(const S &format_str, const Args &... args)
Definition: compile.h:578
typename std::enable_if< B, T >::type enable_if_t
Definition: core.h:298
#define FMT_ASSERT(condition, message)
Definition: core.h:369
typename detail::char_t_impl< S >::type char_t
String's character type.
Definition: core.h:644
#define FMT_MODULE_EXPORT_BEGIN
Definition: core.h:224
#define FMT_CONSTEXPR
Definition: core.h:106
type
Definition: core.h:575
#define FMT_BEGIN_NAMESPACE
Definition: core.h:214
#define FMT_ENABLE_IF(...)
Definition: core.h:335
#define FMT_INLINE
Definition: core.h:199
FMT_CONSTEXPR auto to_unsigned(Int value) -> typename std::make_unsigned< Int >::type
Definition: core.h:407
FMT_CONSTEXPR FMT_INLINE auto parse_arg_id(const Char *begin, const Char *end, IDHandler &&handler) -> const Char *
Definition: core.h:2434
#define FMT_CONSTEXPR20
Definition: core.h:114
typename std::remove_cv< remove_reference_t< T > >::type remove_cvref_t
Definition: core.h:307
constexpr int invalid_arg_index
Definition: core.h:2909
#define FMT_END_NAMESPACE
Definition: core.h:217
#define FMT_MODULE_EXPORT_END
Definition: core.h:225
FMT_CONSTEXPR auto get_arg_index_by_name(basic_string_view< Char > name) -> int
Definition: core.h:2925
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
static EIGEN_DEPRECATED const end_t end
Definition: IndexedViewHelper.h:181
FMT_CONSTEXPR counting_iterator copy_str(InputIt begin, InputIt end, counting_iterator it)
Definition: compile.h:17
FMT_FUNC void print(std::FILE *f, string_view text)
Definition: format-inl.h:1499
const T & first(const T &value, const Tail &...)
Definition: compile.h:138
result
Definition: format.h:2556
GHC_FS_API directory_iterator begin(directory_iterator iter) noexcept
Definition: filesystem.hpp:5746
Definition: StdDeque.h:50
static constexpr const unit_t< compound_unit< energy::joules, inverse< temperature::kelvin >, inverse< substance::moles > > > R(8.3144598)
Gas constant.
static constexpr const velocity::meters_per_second_t c(299792458.0)
Speed of light in vacuum.
std::string to_string(const T &t)
Definition: base.h:93
cubed< length::millimeter > L
Definition: volume.h:49
constexpr const char * name(const T &)
Definition: format.h:1544
Definition: compile.h:104
#define S(label, offset, message)
Definition: Errors.h:118
constexpr T & get(wpi::array< T, N > &arr) noexcept
Definition: array.h:66
auto format(wformat_string< T... > fmt, T &&... args) -> std::wstring
Definition: xchar.h:87
auto format_to(OutputIt out, const S &fmt, Args &&... args) -> OutputIt
Definition: xchar.h:136